PDA

View Full Version : Planetary Defense! Now with source code! (v0.02)



mpark
09-04-2007, 03:55 PM
In March of 1984, ANALOG Computing magazine published a game by Tom Hudson called Planetary Defense for the Atari 8-bit. (Does anyone out there remember this?) This is my take on Planetary Defense.

Here’s a teaser video www.youtube.com/watch?v=zMrPOU6-UKI (http://www.youtube.com/watch?v=zMrPOU6-UKI)

You are in charge of protecting your planet from alien attackers. Your only defense is an orbiting satellite armed with two weapons: a charged-particle gun and a missile launcher. To aim, move the targeting crosshairs with the mouse. The left mouse button fires the charged-particle gun, the right button fires missiles.
Charged-particle projectiles travel until they hit something. There is an unlimited supply of them and up to six may be in flight at a time.
Missiles explode when they reach their target (unless they hit something before then). There are 20 missiles per level and up to four can be in flight at a time.
Satellites are destroyed on contact with incoming bombs or flying saucers. You get an additional satellite every 10,000 points.
The game ends when your planet’s core (the glowing dot in the center) is destroyed.

Requirements: Hydra, NTSC TV, two-button mouse.

Installation instructions:
1. Download the attached .eeprom file.
2. Start the Propeller IDE.
3. Type Ctrl-O and open the .eeprom file you downloaded.
4. In the Object Info window, click Load RAM.
5. Defend your planet!

EDIT (attached source archive):

Here's the source. Use at own risk blah blah no warranty blah blah.

Note that I am not including NS_sound_drv_052_11khz_16bit.spin, so non-Hydra people won't be able to build the program (not with sound anyway). Non-Hydra folks, PM me if you want a build with custom clock speed, video pins, etc. and I'll see what I can do. (I assume it's all right to distribute binaries built with NS_sound_drv* -- please correct me if I'm wrong.)

A few random notes on the program:

Cog usage:
1 Spin interpreter
1 rasterizer
3 renderers
1 collision detection
1 mouse
1 sound
---
8 total

The screen is a 256 x 192 bitmap, 2 bits/pixel. The four colors are used as follows:
00 - background (black)
01 - score
10 - planet
11 - explosions

The rasterizer randomizes the explosion color every vblank and changes the planet color every scan line to create the color bands. (The rasterizer also does a whole lot of other stuff in a background task.)
Everything else on screen is a sprite. Sprites take up quite a bit of memory, being high-color (8 bits/pixel) and having a precomputed mask. I traded space for rendering complexity so that my three rendering cogs could give me the performance I wanted.

I was at a loss how to do sound until I looked through Dodgy Kong/HDMF Lite. That showed me the way. (Of course what I came up with is nowhere near HDMF, Lite or otherwise.)

EDIT

Replaced version 0.01 with v0.02 -- corrected teeny tiny boo-boo. Details in thread.

EDIT

Changed video link to YouTube.

Post Edited (mpark) : 4/4/2010 5:16:32 PM GMT

CardboardGuru
09-04-2007, 04:52 PM
Excellent game! A sort of rotational Space Invaders, or an inside out Gyrus combined with Missile command. Good Job!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com (http://propeller.wikispaces.com)

Baggers
09-04-2007, 07:14 PM
Any chance of posting a 12Mhz pll*8 binary version?

Cheers

epmoyer
09-04-2007, 09:22 PM
Man, I'm headed out the door for work! Can't wait to give it a try tonight!

Paul Baker
09-05-2007, 01:44 AM
Project added to master Project list.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

mpark
09-05-2007, 02:09 AM
Thank you, Paul.

Baggers --·what runs at 96MHz?

CardboardGuru -- Thanks! I always thought of the original PD as a neat variation on Missile Command and in fact added more MC-ish touches to my version.

epmoyer
09-05-2007, 09:51 AM
mpark,

Really great job! This is an excellent game in so many ways; very well suited to the platform, very well implemented, nice and stable, great use of sound, very good use of color, and best of all - super fun to play. I never played the original, but your version sure is a blast.

One of the things I miss about the 80's is that back then game designers were constantly seeking out new mechanics. So much of what gets made today is just the same old game with increasingly glitzy graphics. How many times can we play the same platform jumper? Yawn. This game smacks of innovation in all its 8 bit goodness (okay, arguably 32 bit goodness ;) I love it when simple mechanisms lead to interesting emergent behaviors. The dynamics of shot timing, leading the target, waiting for line of sight, prioritizing targets, and working around the evolving shape of the planet all combine to make a spectacularly fun experience out of a small handful of objects.

Thanks for porting this gem, and for doing such a fine job of it! You've made the world a better place.

MinimumWage
09-05-2007, 12:30 PM
Wow, this runs and looks great and is *tons* of fun to play. Any chance of posting source code? I know I would learn a lot from being able to look over it...

Mike

mpark
09-05-2007, 01:04 PM
epmoyer -- Thank you! Although I'm not much of a gamer, I think I know what you mean about the 80s and 8-bit goodness. Thank goodness for people like Tom Hudson, an Atari deity back in the day.


MinimumWage -- Thanks, but I don't know how much you'd learn from the source. It's pretty messed up. However, posting it was my original intention (if there was sufficient interest). Maybe I'll wait for bug reports first.



Michael

Coley
09-05-2007, 02:51 PM
EP Moyer said...
One of the things I miss about the 80's is that back then game designers were constantly seeking out new mechanics. So much of what gets made today is just the same old game with increasingly glitzy graphics. How many times can we play the same platform jumper? Yawn.


Exactly! That's why the Hydra will appeal to a lot of folks. My children have all those 'glitzy' games and they hold their attention for a few minutes at most.
I remember when getting a game you would play it till you finished it!

All the old 8 Bit game best sellers sold the most by being fun and playable not flashhy graphics.


@mpark

Please release a 96MHz version, to answer your question, a new platform the 'Hybrid' runs at that speed.

See this post for more details http://forums.parallax.com/showthread.php?p=659491


Best regards,


Coley

Forrest
09-05-2007, 03:51 PM
I've played the original on my Atari - please post the source so I can play it on my Propeller system (similar to the demo board).

Baggers
09-05-2007, 04:22 PM
mpark: Sorry, it's 10Mhz + 8*pll, thanks :) it's another project that runs at 96Mhz

Coley: It's the other project that runs at 96Mhz, Hybrid is still 80Mhz :) my typo originally soz. 12 should have been 10. too busy with second project.

CardboardGuru
09-05-2007, 05:37 PM
Everyone likes a bit of constructive criticism right? It's quite hard with this game, as it's incredibly polished for a first release. I can't find any bugs at all!

Just one odd thing. I played it first using my WinTV card for display. Even at full screen the bullets were almost invisible. To the extent I didn't even notice they were there the fist time I played it! Trying it out on a real TV, the bullets are very clear and bright. I'd just put it down to the WinTV card, except that the bullets in Eric's Space War game are very bright on the WinTV card. Although the Space War bullets go slower, so that might contribute.

Game play wise, I didn't pick up on the missiles at first. But the missile display and count at the level end is enough to hint that there are some to be found. But when I did, I didn't find them to be a much stronger weapon than a volley of bullets. I can see that they work like Missile Command missiles, but they just didn't seem so useful here. Perhaps there could to be some small enemies that are harder to shoot with bullets that the missiles would be better for.

Perhaps the small enemies could bring a bit of Defender type action in? Moving rapidly they could steal something from the planet, and then make their escape? And something bad happens if all of the somethings are taken? You can shoot the enemies to retrieve the somethings which then fall under gravity back to the planet.

It'd be nice to have some details of how you put the game together. What graphics driver did you use? What res? How many colours? How did you produce the sound?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com (http://propeller.wikispaces.com)

mpark
09-06-2007, 06:55 AM
Forrest -- Yay, another Atari guy! I'm going to post the source (see below).

Baggers -- The Hydra is 10MHz * 8, so maybe it'll work as is. Did you try it?

Coley -- The Hybrid is your baby, isn't it? Shouldn't you know its clock speed? http://forums.parallax.com/images/smilies/shocked.gif

CardboardGuru -- Constructive criticism is always welcome and I thank you for it.

I don't know what to tell you about the "invisible" bullets.

The MC-style missiles are my addition (I figured I should do something with the right mouse button) and smaller enemies were definitely in the plan, but I ran out of time and memory (I'm down to 1 free long). Instead, I·tried to design a few levels where you'd want to use the missiles to spray-and-pray a defensive cover of explosions, but more power to you if you can stick to the classic PD weapon and ignore missiles (and rack up the extra points).

Anyhoo, I'll post the source tonight in the hopes that

Forrest can get it working on his demo board and relive the days of Atari glory Baggers/Coley can get it working on the Hybrid CardboardGuru can find a bullet color that will show up on WinTV MinimumWage will find it informative.

mpark
09-06-2007, 10:38 AM
I have attached a source archive to the first post.

Baggers
09-06-2007, 02:52 PM
mPark, thanks for releasing the source, and yes, the Hydra is 10Mhz, the hybrid is 5Mhz, I have so many things goin on in my head at the mo, and so many clock versions of the prop.

My wife's nan died last friday, and my mum had a major stroke on Sunday, so please forgive my lack of attention to detail :) as you can imagine, my head is all over the place at the mo.

Again, thanks for posting the source, I'll have a play later, when I get chance.

Baggers,

Coley
09-06-2007, 05:24 PM
mpark said...
Coley -- The Hybrid is your baby, isn't it? Shouldn't you know its clock speed? http://forums.parallax.com/images/smilies/shocked.gif


lol, yes I should!

We have many things on the go at the moment and one product associated with the hybrid runs at 96MHz, sorry for the confusion.

Thanks for releasing the source, I am looking forwards to trying this one, so it's a big thank you from me.

Best regards,

Coley

potatohead
09-06-2007, 06:34 PM
Another Atarian here. (CoCo too)

Thanks for this! It plays well and is a lot of fun. Brings back lots of happy memories waiting for new issues COMPUTE!, ANALOG, Antic, Creative Computing, etc... to hit the shelves each month. What a fun time.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Wiki: Share the coolness! (http://propeller.wikispaces.com/)

Baggers
09-06-2007, 11:48 PM
Hi mpark,
Got it working, just changed the clock speeds, and modified the original mouse.spin ( added getparameters and removed bounding functions, to make it fit in memory :) ) and changed mouse pins to pin 14,15.

Works great, and it's very addictive.

Well done, very nice port.

Jim.

MinimumWage
09-07-2007, 12:10 PM
Thanks for posting the source mpark! Maybe I'll learn something from reading through it - if I can pull myself away from playing it... =)

mpark
09-07-2007, 01:02 PM
I found a small bug. In PlanetaryDefense_rasterizer, I had a typo in my calculation of the PLL freq:


freq long trunc(colorBurstFrq / 80_000_000.0 * 4_294_967_896.0)


That "8" should be a "2".
However, I also discovered that even with the correct number, the Spin compiler was computing a value that was just a little bit off. So I've replaced that whole line with this:


freq long 192175359 ' colorBurstFrq / 80_000_000.0 * 2^20


I discovered all this while trying to track down some interference in another program using the same video driver. I haven't noticed the interference in Planetary Defense (probably because the screen is mostly black) so it's probably not worth re-downloading, but I've replaced the binary and source in the first post with new versions (0.02).

mpark
09-07-2007, 01:59 PM
Potatohead -- Ah yes, the good old days. Maybe I'll find another game to port in my stacks of old magazines. (I knew they'd come in handy eventually, I knew it!)

Baggers -- My sympathies for your troubles, but I'm glad to hear you got it working.

MinimumWage -- Good luck!

Hey, just out of curiosity, are you non-Hydra people compiling it without sound, or do you have the sound driver somehow? PM me if you prefer. I don't want to bust anyone, I'm just curious.

Baggers
09-07-2007, 05:15 PM
Hi mpark,

Thanks for the sympathies. ;)

And yeah, was just a few simple changes to get it working :)

As for without sound, I have the Hydra book, for the overcharged price of £65 roughly $130 :( we brits always get ripped off, also I think it's one of the first revisions, as the software that came with it, wasn't complete, I'm missing at least one ( that I know of, the latest sound drivers. NS_Hydra_Sound_12, or something like that, I had to use a lower version, can't remember off hand which app it was for though ) was a little while ago that I found that out though.

Baggers.

AndreL
09-11-2007, 08:13 AM
Very impressive, can I add this to the goodies section of the next HYDRA CD release?

Andre'

mpark
09-11-2007, 09:49 AM
Yes! I think I've posted three programs and two of them qualified as goodies. Makes me wonder what was wrong with the other one :)

Bamse
09-11-2007, 01:06 PM
Awesome game...

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Living on the planet Earth might be expensive but it includes a free trip around the sun every year...

Experience level:
[ ] Let's connect the motor to pin 1, it's a 6V motor so it should be fine.
[ ] OK, I got my resistors hooked up with the LEDs.
[X] I got the Motor hooked up with the H-bridge and the 555 is supplying the PWM.
[ ] Now, if I can only program the BOE-BOT to interface with he Flux Capacitor.
[ ] I dream in SX28 assembler...

/Bamse

JT Cook
09-11-2007, 09:46 PM
mpark said...
I found a small bug. In PlanetaryDefense_rasterizer, I had a typo in my calculation of the PLL freq:


freq long trunc(colorBurstFrq / 80_000_000.0 * 4_294_967_896.0)


That "8" should be a "2".
However, I also discovered that even with the correct number, the Spin compiler was computing a value that was just a little bit off. So I've replaced that whole line with this:


freq long 192175359 ' colorBurstFrq / 80_000_000.0 * 2^20


I discovered all this while trying to track down some interference in another program using the same video driver. I haven't noticed the interference in Planetary Defense (probably because the screen is mostly black) so it's probably not worth re-downloading, but I've replaced the binary and source in the first post with new versions (0.02).
I just downloaded the program on Friday and it would only show up in black and white. For my system I usually add 5000 to the crystal frequencey and that usually fixes my problem. But when I tried that with your program it didn't change a thing. Now after reading this I know why http://forums.parallax.com/images/smilies/smile.gif .· I'll try using the original line, replace the 8 with·a 2, and try that and see if I get color.

mpark
09-12-2007, 04:29 AM
Bamse -- Thanks!

JT Cook -- I guess you'll also have to change 80_000_000 to 80_040_000 (i.e. add 5000 * 8). That's kind of odd, though. Do you think it's your crystal or is it your TV? Anyway, good luck and let us know how it turns out.

JT Cook
09-12-2007, 07:17 AM
It is the crystal. I built a Hydra using the protoboard, and I just had to change the clock and PLL, but didn't need to add anything to clock value.

Oldbitcollector (Jeff)
12-17-2008, 10:23 AM
I did some editing on this to make it work with the Demoboard / Protoboard setup.

"mouse.spin" is considerably larger than "mouse_iso_010.spin" so I had to remove the credits section
as well as shorten the POINTS announcements to get it to load with the intended sound driver.
Every ounce of memory is used with this game. :)

Attached is a compilable copy with a dummy (silent) version of Nicks sound driver.
Should work perfectly for anyone with a demoboard type setup.

If you drop in the licensed copy of "NS_sound_drv_052_11khz_16bit.spin" from the Hydra Book/Kit,
you'll get full sound as well.

Great game, well worth checking out!

OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard (http://jeffledger.googlepages.com/Protoboard_Introduction.pdf) & Propeller Cookbook 1.4 (http://ucontroller.com/Propeller%20Protoboard%20Designs%20for%20the%20Beg inner.pdf)
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us (http://propeller.warrantyvoid.us)
Got an SD card connected? - PropDOS (http://www.orrtech.net/propdos/)