News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Space Invaders

Started by kelp7, 12:38, 15 June 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kelp7

This might sound silly but I've always struggled to quite understand the programming logic behind the movement of the Invaders in Space Invaders. At some point or another in my past I've coded clones of most of the basic original shooters etc but never did write a Space Invaders clone. I'd like to give it a go on my Z80 machine (yep, not quite an Amstrad really unfortunately :) ).


When the invaders themselves are moved around the screen, what happens when they reach the edge? What I mean is.... if the player has shot one entire column of Invaders the program needs to check that this column doesn't exist anymore, is that right? So then the rest of the Invaders can actually carry on moving further towards the edge of the screen. Are the positions of the Invaders usually held in an array? So you could check which ones are still alive by a value setting in the array?


Any help, as ever, very much appreciated...




HAL6128

When I programed once my Space Invaders in BASIC I made the whole thingy via array. I'm convinced that there might be a better solution, but mine worked at least for the movement. It had a bug: when the opponents are firing back and if an alien has been hit, another should be replaced by firing back. I didn't get that working correctly.

For the movement I had 24 opponents defined in an Array (6 in a row and 4 columns). The first array was for the type of character (shape of the alien), one for X-Position and one for the Y-Position, and another one for the number of opponents at all (which was reduced if one was hit, which speed up the movement routine to the end).

There was a separate routine when moving to the right, one routine for moving to the left, one Routine for moving a step down if the edge has been arrived, and a routine for reoganize the whole array if an Alien has been hit (which includes a routine finding the hit alien by coordinates and number)

Then there's a routine which caculate the most right and left opponent which helped to find the point of reverse movement on the edge.

Cheers.
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

kelp7

Cheers HAL 6128. Really appreciate your reply. It's a solution which I've always wondered about, thanks for giving me food for thought.

kelp7

I wonder perhaps if you could link the alien type (shape of the alien) with its Y position. Use the Y position to address a small table of alien types. Obviously when their Y position changes (they move down a row) you would have to adjust your look-up to the alien type table.

HAL6128

This was my approach:
There are always two different shapes of one alien. Shape A of alien No. 1 has Symbol Nr. X, shape B of alien No. 1 has Symbol Nr. X+1.
With each movement - and it doesent matter if the alien moves right, left or down - it adjust it's look-up by the code:
REM ***entry condition
shape=0
print chr$(X+shape):' first print of alien No.1 (shape A)
...
REM ***movement subroutine
REM *** delete old shape and set new shape
...
shape=1-shape:'toggle between '1' and '0'
...
REM *** calculate new position and print new shape
print chr$(X+shape):'alien No. 1 (shape B)
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

kelp7

Interesting, thanks!


I was thinking that if you had, say, 4 rows of aliens that would be 4 types of alien (okay, 8 types if we have two shapes per alien).


If you had just 4 types, you could DIM SHAPE(4). Each element of the SHAPE() would be a CHR$ number. Then when you are printing the aliens on the screen, you just use the Y position to address the SHAPE() array. You would have to subtract something probably from the Y though to get to the correct element of SHAPE(). Probably more complicated than your solution :) Thanks very much for the example though!


Cheers
kelp

HAL6128

... I made something like creating a container:
1. dimensioning 24 aliens > dim alien(24),aposx(24),aposy(24),achar(24)
every alien has ist own specific Setup
alien(1)=chr$(x):'Alien No.1 with shape A
alien(2)=chr$(x+1):'Alien No. 1 with shape B
...

2. print out the first alien with locate aposx(No. of alien),aposy(No. of alien):print achar(alien(No. of alien)+shape)
3. change shape as described like: shape=1-shape

Of course the whole code is more complex than I roughly described. Attached you will find my approach if there's interest.
But I assume you want to find it out for yourself ;)
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Powered by SMFPacks Menu Editor Mod