top of page
Writer's pictureBruce

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!





47 views0 comments

Recent Posts

See All

Comments


Want to support my work?....Buy my games!

aboutME

Hello, I'm Bruce and I write games for old 8bit computers using Jonathan Cauldwell's excellent Multi-Platform Arcade Games Designer (MPAGD)

I've written a few successful* games for the Sinclair ZX Spectrum and MSX platforms that have been (largely) well received including Twenty Four Hour Parsley People scoring a 10 out of 10 on Planeta Sinclair.

In my blog I am sharing lots of the code that I wrote for my games, in a way that you can use in your own games.   I've commented it so that you'll learn some of the techniques I use to create interesting new mechanics and help your games stand out from the pack.

MPAGD includes lots of standard scripts, they're great to get you started, but if you're new (or just rusty) when it comes to writing code, hopefully my tutorials will help you get started and  turn your imagination into awesome 8 bit games!

All my code is free to use and do with as you please, but if you find them useful please feel free to buy me a coffee ...or better still - buy or download my games :)

*successful is a very relative term in 8bit computer games

bottom of page