Bruce

Aug 2, 20223 min

Vertical Shmup - Part 12 - Final tidying and improvements

If you recall, when we gave the Aliens the ability to fire missiles, one of tests that the code performs is to see if the Alien is positioned in the range 8pixels either side of the player - this seems a bit restrictive to me, so let's add a new Variable to the Spawner event (TYPE 7) which will allow us to define the distance either side of the player that an alien needs to be in to be allowed the chance of firing their missile.

We'll add in variable I to the list of values we'll read in

IF SETTINGA = 0 ; first time we run this
 
LET JUMPSPEED = 0 ; reset the enemies spawned counter
 
LET SETTINGB = 0 ; reset the timer
 
RESTORE ; start from the beginning of the data table
 
REPEAT L ; get the data for this level
 
READ AIRBORNE ; get the spawner movement
 
READ X ; get starting x position
 
READ Y ; get starting y position
 
READ J ; get the enemy sprite type
 
READ K ; get the enemy image
 
READ E ; how many enemies in this level?
 
READ G ; delay between releasing each enemy
 
READ P ; points for a kill
 
READ C ; colour
 
READ W ; weapon
 
READ H ; fire weapon probability
 
READ Q ; min height to release weapons
 
READ I ; x distance for alien weapon triggering
 
ENDREPEAT
 
LET D = E ; how many kills to get bonus?
 
LET F = E ; enemies remaining
 
ADD 1 TO SETTINGA ; prevent this running again
 
ENDIF
 

Then make sure to add a new value to the end of each row in your data table:

DATA 0 132 8 5 2 8 8 5 67 1 10 100 8
 
DATA 0 100 8 5 2 10 8 10 68 1 10 100 32

By altering these values you can make the aliens fire when further horizontally away from the player (or when nearer)

Next, there's some code in the Alien event (Type 5) that is repetitive, we could save a few bytes by optimising it, specifically the test to see if the player is out of bounds:

We could optimise this by using the DIRECTION variable, setting it to 254 whenever an enemy leaves the screen:

So, we will change this:

; BOUNDARY CHECKING
 
; ===================
 
IF X <= LEFTEDGE ; if alien reaches the left edge
 
REMOVE ; remove it
 
SUBTRACT 1 FROM S ; decrement the sprite counter
 
SUBTRACT 1 FROM F ; decrement the number of aliens still in
 
ENDIF
 

 
IF X >= RIGHTEDGE ; if alien reaches the right edge
 
REMOVE ; remove it
 
SUBTRACT 1 FROM S ; decrement the sprite counter
 
SUBTRACT 1 FROM F ; decrement the number of aliens still in
 
ENDIF
 

 
IF Y >= BOTTOMEDGE ; if alien reaches the right edge
 
REMOVE ; remove it
 
SUBTRACT 1 FROM S ; decrement the sprite counter
 
SUBTRACT 1 FROM F ; decrement the number of aliens still in
 
ENDIF

to this:

; BOUNDARY CHECKING
 
; ===================
 
IF X <= LEFTEDGE ; if alien reaches the left edge
 
LET DIRECTION = 254 ; enemy is out of bounds
 
ENDIF
 

 
IF X >= RIGHTEDGE ; if alien reaches the right edge
 
LET DIRECTION = 254 ; enemy is out of bounds
 
ENDIF
 

 
IF Y >= BOTTOMEDGE ; if alien reaches the right edge
 
LET DIRECTION = 254 ; enemy is out of bounds
 
ENDIF
 

 
IF DIRECTION =254 ; is enemy out of bounds?
 
REMOVE ; remove it
 
SUBTRACT 1 FROM S ; decrement the sprite counter
 
SUBTRACT 1 FROM F ; decrement the alien counter
 
ENDIF

That should save us a few bytes, plus makes it easy if we want to remove a sprite (but not kill it) in other parts of the game.

And that, I think, should wrap it all up for now and give you a lightweight (currently uses approx 14,500 bytes) framework for building Shoot em ups in MPAGD.

I'm off o tidy up the comments in the code then I'll release the whole project on the itch website so you can get started quickly!

    370
    0