Enemy missiles travel down the screen quite quickly, when they are spawned by an Enemy we pass the enemies direction of travel to the missile and then make the missile veer either left or right accordingly, so if the enemy was going left when they fired the missile then the missile will also veer left.
EVENT SPRITETYPE3 ;======= ENEMY MISSILES ============ ;====================================== ; VARIABLES ; ======================================================= ; DIRECTION - DIRECTION OF ENEMY TRAVEL WHEN RELEASED ; SETTINGA - availabe for use in your game ; SETTINGB - availabe for use in your game ; AIRBORNE - availabe for use in your game ; JUMPSPEED - availabe for use in your game ; ======================================================== SPRITEINK 71 ; bright white SPRITEDOWN ; go down fast (3 times SPRITEDOWN SPRITEDOWN IF DIRECTION = 0 ; was alien going down when fired? ELSE ; if so, do nothing IF DIRECTION < 8 ; was alien going right? SPRITERIGHT ; make missile veer right ELSE IF DIRECTION = 8 ; was alien going straight up? ELSE ; do nothing SPRITELEFT ; alien was going left, veer missile left ENDIF ENDIF ENDIF IF COLLISION PLAYER ; has missile collided with player? IF X > M ; is missile to the right of player? SUBTRACT M FROM X ; subtract M to find out how far to the right IF RND <= 10 ; its a hit! OTHER ; switch to the player LET DIRECTION = 99 ; trigger the player explosion ENDSPRITE ; switch back to this event LET DIRECTION = 99 ; explode the missile ENDIF ADD M TO X ELSE ; not to the right IF X < M ; is missile to the left? SUBTRACT X FROM M ; yes, how far to left? IF M <= 8 ; its a hit! OTHER ;switch to the player LET DIRECTION = 99 ; trigger the player explosion ENDSPRITE ; switch back to this event LET DIRECTION = 99 ; explode the missile ENDIF ADD X TO M ; reset M ELSE ; must have been a direct hit OTHER ; switch to the player LET DIRECTION = 99 ; trigger the player explosion ENDSPRITE ; switch back to this event ENDIF ENDIF ENDIF IF DIRECTION = 99 ; Explosion requested LET TYPE = 6 ; switch to the explosion type LET IMAGE = 4 ; and explosion image LET FRAME = 0 ; and the first frame LET DIRECTION = 2 ; and tell the explosion its an enemy missile ENDIF IF Y >= 188 ; has missile reached bottom of the screen REMOVE ; remove it SUBTRACT 1 FROM S ; decrement the sprite counter ENDIF
