A blast from my programming past

Years ago I programmed regularly in Revolution. I hardly do anymore, but I’m still subscribed to the mailing list and every once in a while someone posts something that I used to be pretty decent at, so I dive back in. This is an example of that. 

An anonymous poster is trying to replicate Galaga in Revolution. Graphic video games like that aren’t really Rev’s strength, and the poster immediately ran into speed problems. Rev just doesn’t have the ability to directly update the locations of multiple objects repeatedly in a way that makes sense for video games. In short, it’s no Flash killer.

That said, there are things you can do to get things done anyway. In particular, the move to points command is your friend. You can use 

   put the width of this stack into w
   put random(w) into x

   repeat with y = –25 to the height of this stack + 25 step 10
      put abs(x + 20 * random(2) – 30) into x
      if x > w then put 2 * w – x into x
      put x,y & cr after p
   end repeat

   move image “enemy” to pointsList in 5 seconds without waiting

and if you have set up the points in pointsList appropriately, you’re set for five seconds. Further, image “enemy” will receive a moveStopped message when it finishes, allowing you to start the process over again. In this version of Galaga, enemies start above screen and go off the bottom, so this works perfectly.

One drawback of this is that they can’t (easily) go off the left side and come in on the right, or vice versa. Off the top of my head the easiest way to do that would be to check as you go along and if the ship ever goes off the side, stop there, calculate how long the move should take, and then write code to pick up from the opposite side when the moveStopped message arrives.

The same sort of thing is even easier for the bullets:

   repeat with i = 1 to 12
      if i > 11 or item 2 of the loc of grc (“fire” & i) < 0 then exit repeat
   end repeat
   if i = 6 then exit rawkeydown
   set the loc of grc (“fire” & i) to the loc of image “ship”
   move grc (“fire” & i) relative (0,(- the height of this stack)) in 2 seconds without waiting

I could have kept track of which bullets were available but I took the easy way and just checked to see if they were off the top of the screen.

Performance. The original code had a hard time moving one enemy and a few bullets. This version handles three enemies and 11 bullets smoothly (on my computer). I’m still simply moving the player’s ship; I’d fix that if I were going to spend any more time on this. If you have Revolution, feel free to download this and poke around.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s