Aliens perform a movement pattern which are a combination of directional movements, Direction 0-15, each one representing a point on a 16 point compass, and a number of repetitions.
Patterns are stored in a DATA table at the bottom of the event. Each row of the data table represents a pattern unique to the level the player has progressed to.
In the demo game, aliens in an attack wave are removed when they are shot by the player or exit the screen, but you could easily change this for different gameplay styles.
The number of aliens in an attack wave and other parameters are defined separately in the Spawner Event.
A default alien sprite is included in Sprite Image 2, it has 16 frames, each one corresponding to a direction value, this makes it easy to ensure the correct frame is shown based on the aliens current direction of travel.
Aliens can also shoot missiles at the player, how and when they do this is fully customisable and is based on the settings defined in the Spawner event for each specific attack wave, so you can set how high up the screen they have to be before firing, their probability of firing and how far to the left and right of the player will allow a potential missile launch.
EVENT SPRITETYPE5
;======= ENEMIES ============
;====================================
;
; VARIABLES
; =======================================================
; DIRECTION - CURRENT DIRECTION OF TRAVEL,( 254= OUT OF BOUNDS, 255= EXPLODE)
; SETTINGA - STATUS (0= INITIALISE, 1=GET DIRECTION & REPS, 2=MOVE)
; SETTINGB - # REPETITIONS OF CURRENT DIRECTION
; AIRBORNE - CHANCE OF FIRING WEAPON (0 = NO, 1 = YES)
; JUMPSPEED - availabe for use in your game
; ========================================================
SPRITEINK C ; colour the alien with C value
IF SETTINGA = 0 ; Alien first appears
RESTORE ; Restore the data table
LET RND = L ; Store the Level number in RND
ADD 50 TO RND ; and increase it by 50
WHILE DIRECTION <> RND ; While DIRECTION doesnt = RND
READ DIRECTION ; Read value from DATA table
READ SETTINGB ; Also read second value
ENDWHILE ; Keep going until we find the value in RND
LET SETTINGA = 1 ; When we find it change SA to 1
ENDIF
IF SETTINGA = 1 ; ready to get direction & reptitions
READ DIRECTION ; read the next movement into DIRECTION
READ SETTINGB ; read the repetitions into SettingB
LET SETTINGA = 2 ; ready to do the movement
IF IMAGE 2 ; is this image 2?
LET FRAME = DIRECTION ; yes, set the frame to the same as direction
ENDIF
ENDIF
; COLLISIONS
; ==============================
IF COLLISION 1 ; if hit by a player torpedo
OTHER ; switch to torpedo
LET DIRECTION = 99 ; run the explosion
ENDSPRITE ; return to this Alien
LET DIRECTION = 255 ; request alien explosion
ENDIF
IF COLLISION 0 ; if enemy and player collide
OTHER ; switch to the player
LET DIRECTION = 99 ; trigger the player explosion
ENDSPRITE ; return to this sprite
LET DIRECTION = 255 ; request alien explosion
ENDIF
; EXPLODE THE ALIEN
; =======================
IF DIRECTION = 255 ; Alien explosion requested
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
ENDIF
; MOVEMENT
; ====================
IF DIRECTION = 0 ; Move N
SPRITEUP
SPRITEUP
ENDIF
IF DIRECTION = 1 ; Move NNE
SPRITERIGHT
SPRITEUP
SPRITEUP
ENDIF
IF DIRECTION = 2 ; Move NE
SPRITERIGHT
SPRITERIGHT
SPRITEUP
SPRITEUP
ENDIF
IF DIRECTION = 3 ; Move ENE
SPRITERIGHT
SPRITERIGHT
SPRITEUP
ENDIF
IF DIRECTION = 4 ; Move E
SPRITERIGHT
SPRITERIGHT
ENDIF
IF DIRECTION = 5 ; Move ESE
SPRITERIGHT
SPRITERIGHT
SPRITEDOWN
ENDIF
IF DIRECTION = 6 ; MOVE SE
SPRITERIGHT
SPRITERIGHT
SPRITEDOWN
SPRITEDOWN
ENDIF
IF DIRECTION = 7 ; MOVE SSE
SPRITEDOWN
SPRITEDOWN
SPRITERIGHT
ENDIF
IF DIRECTION = 8 ; MOVE S
SPRITEDOWN
SPRITEDOWN
ENDIF
IF DIRECTION = 9 ; MOVE SSW
SPRITEDOWN
SPRITEDOWN
SPRITELEFT
ENDIF
IF DIRECTION = 10 ; MOVE SW
SPRITEDOWN
SPRITEDOWN
SPRITELEFT
SPRITELEFT
ENDIF
IF DIRECTION = 11 ; MOVE WSW
SPRITEDOWN
SPRITELEFT
SPRITELEFT
ENDIF
IF DIRECTION = 12 ; MOVE W
SPRITELEFT
SPRITELEFT
ENDIF
IF DIRECTION = 13 ; MOVE WNW
SPRITELEFT
SPRITELEFT
SPRITEUP
ENDIF
IF DIRECTION = 14 ; MOVE NW
SPRITELEFT
SPRITELEFT
SPRITEUP
SPRITEUP
ENDIF
IF DIRECTION = 15 ; MOVE NNW
SPRITELEFT
SPRITEUP
SPRITEUP
ENDIF
; 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
; CHECK IF ALIEN CAN RELEASE WEAPON
; =================================
IF Y < Q ; is alien above minimum height for releasing missiles?
IF W > 0 ; yes, can alien release missiles?
IF X < M ; yes, is Alien to the right of player?
SUBTRACT X FROM M ; yes, how far to the right of player?
IF M <= I ; I or less pixels?
LET AIRBORNE = 1 ; run the chance of firing routine
ENDIF
ADD X TO M ; reset M
ELSE
IF M < X ; is alien to the left of player?
SUBTRACT M FROM X ; yes, how far to the left
IF X < = I ; I pixels or less?
LET AIRBORNE = 1; yes, run the chance of firing routine
ENDIF
ADD M TO X ; reset X
ELSE ; enemy must be directly above player
LET AIRBORNE = 1 ; run the chance of firing routine
ENDIF
ENDIF
ENDIF
ENDIF
; CHANCE OF FIRING
; ====================
IF AIRBORNE = 1 ; Chance of firing routine
IF S < 9 ; are there 8 or less sprites on screen?
GETRANDOM H ; yes, get a random number from 0 to the aliens missile probability #
IF RND = 1 ; is it 1?
LET RND = DIRECTION ; yes, store aliens direction in RND
SPAWN 3 6 ; spawn a missile
SPAWNED ; switch to the spawned missile
LET DIRECTION = RND ; set its direction to RND
ENDSPRITE ; switch back to this alien
ENDIF
ENDIF
LET AIRBORNE = 0 ; end the chance of firing routine
ENDIF
; REPETITIONS CHECK
; ======================
SUBTRACT 1 FROM SETTINGB ; decrement repetitions remaining
IF SETTINGB = 0 ; has alien moved all repetitions?
LET SETTINGA = 1 ; get the next direction & # of repetitions
ENDIF
; MOVEMENT PATTERNS
; ========================
DATA 51 0 8 20 7 8 6 8 5 8 4 16
DATA 52 0 8 20 9 8 10 8 11 8 12 16
DATA 53 0 12 48 11 2 10 2 9 2 8 2 7 2 6 2 5 2 4 40 5 2 6 2 7 2 8 2 9 2 10 40
DATA 54 0 4 48 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 40 11 2 10 2 9 2 8 2 7 2 6 40
DATA 55 0 13 26 14 4 15 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 40
DATA 56 0 3 26 1 4 0 4 15 4 14 4 13 4 12 4 11 4 10 4 9 4 8 4 7 4 6 40
DATA 57 0 8 16 7 4 6 4 5 4 4 4 3 4 2 4 1 4 0 4 15 4 14 4 13 4 12 4 11 4 10 4 9 4 8 4 7 4 6 4 5 4 4 60
DATA 58 0 8 16 9 4 10 4 11 4 12 4 13 4 14 4 15 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 2 12 60
DATA 59 0 8 16 9 4 10 4 11 4 12 4 13 4 14 4 15 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 2 12 60
DATA 60 0 4 20 13 4 14 4 15 4 0 8 1 4 2 4 3 4 4 4 8 8 7 2 6 2 5 2 4 40
DATA 61 0 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 11 3 10 3 9 3 8 3 7 3 6 3 5 4 6 4 7 4 8 4 9 4 10 4
DATA 62 0 8 3 4 16 9 24 4 40
DATA 59 0 8 16 9 4 10 4 11 4 12 4 13 4 14 4 15 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 2 12 60
DATA 60 0 4 20 13 4 14 4 15 4 0 8 1 4 2 4 3 4 4 4 8 8 7 2 6 2 5 2 4 40
DATA 61 0 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 11 3 10 3 9 3 8 3 7 3 6 3 5 4 6 4 7 4 8 4 9 4 10 4
DATA 62 0 8 3 4 16 9 24 4 40
Commenti