• Bruce

Vertical Shmup - Part 6 - Killing Aliens

The basic game mechanics have started to take shape so now we'll tackle killing the aliens, first, we'll create a new Sprite for enemy explosions, something like this:












Next, we'll write some code for the Explosion, I'm going to use Sprite Type 6 for explosions:



EVENT SPRITETYPE6


ANIMATE 				   ; regular amination
IF FRAME = 4			   ; are we on the last frame?
   IF DIRECTION = 0	   ; was enemy hit by a torpedo?
      REMOVE			   ; yes, remove this sprite
      SUBTRACT 1 FROM S   ; decrement the sprite counter
   ENDIF
ENDIF

This will remove the explosion once it reaches the last frame, and reduce the number of on screen sprites.


Now, we'll add in some collision detection code into to our Alien sprite event (type 2) Add the code below to the bottom of your Sprite Type 2 event:



							; COLLISIONS
							; ===================
IF COLLISION 1				; if hit by a torpedo
	OTHER					; switch to the torpedo
	IF DIRECTION = 1			; is it unexploded?
		LET DIRECTION = 99	; explode the torpedo
	ENDIF
	ENDSPRITE				; return to this sprite
	LET TYPE = 6				; switch it to the explosion type
	LET IMAGE = 4				; and the explosion image
	LET FRAME = 0				; reset it to first frame
	LET DIRECTION = 0			; this is an alien exploding
ENDIF



This does two things when a collision between a torpedo and an Alien is registered:


1) it tells the torpedo to explode

2) it switches the Alien to the Alien Explosion Type and Image


Let's build and test:


{insert video}


Cool, now we can shoot them!


Although, I can see one obvious flaw, notice how nothing happens when our player spaceship collides with an Alien, we need to fix that so both the Alien and the Player explode.


Head back to your Alien Event (type 2) and add the following code to the bottom:



IF COLLISION 0				; if enemy and player collide
	LET TYPE = 6				; switch it to the explosion type
	LET IMAGE = 4				; and the explosion image
	LET FRAME = 0				; reset it to first frame
	LET DIRECTION = 0			; this is an alen exploding
	OTHER
	LET TYPE = 6				; switch it to the explosion type
	LET IMAGE = 4				; and the explosion image
	LET FRAME = 0				; reset it to first frame
	LET DIRECTION = 1			; this is the player exploding
	ENDSPRITE
ENDIF


Now both will explode when the two ships collide.


We're making some decent progress here, but there's still lots to do, however, before I go any further I think we've got a gameplay decision to make.


NEXT: Part 7 : A Gameplay Decision



9 views0 comments

Recent Posts

See All

A couple of people have asked for some tutorials on creating a Vertical Shoot-em up with MPAGD, something along the lines of Imagine's classic, Arcadia. This sounded like a good challenge....but one I

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