This is the engine room of Shmupkit. The Spawner itself is a blank sprite, and it's event controls which enemies should be spawned, where, how many and sets up all the parameters that control the enemy which are passed to the enemy event.
It's basically a data table of values that are read from whenever the player progresses to a new level/attack wave.
The Spawner makes sure the right sprites, numbers of sprites and delays between sprites are spawned correctly, and ensures there aren't too many sprites on screen at once which could otherwise cause display issues.
EVENT SPRITETYPE7
; VARIABLES
; =======================================================
; DIRECTION - availabe for use in your game
; SETTINGA - STATUS:
; 0 = GET DATA FOR NEXT LEVEL
; 1 = SPAWN ALIENS
; SETTINGB - TIMER BETWEEN SPAWNS
; AIRBORNE - SPAWNER MOVEMENT (not implemented yet)
; JUMPSPEED - # OF ENEMIES SPAWNER
; ========================================================
; ALIEN SPAWNER
; ============
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
IF SETTINGB = G ; has timer reached the delay point?
IF JUMPSPEED < E ; are there still enemies left to spawn?
IF S < 9 ; are there 10 or less enemies already on screen?
SPAWN J K ; spawn an enemy
ADD 1 TO JUMPSPEED ; increment the number spawned
SPAWNED ; switch to the enemy sprite
LET DIRECTION = 0 ; set its initial direction to 0
ENDSPRITE ; return to the spawner
ENDIF
ELSE ; all enemies in this level have been spawned
IF F = 0
ADD 1 TO L ; get ready for next level
IF L = 13 ; have we reached the end of the levels?
LET L = 1 ; yes, start again
ENDIF
LET SETTINGA = 0 ; get data for next level
ENDIF
ENDIF
LET SETTINGB = 0 ; reset the timer
ENDIF
ADD 1 TO SETTINGB ; increment the timer
; Alien Spawner 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
DATA 0 232 16 5 2 12 6 15 69 1 8 100 100
DATA 0 8 32 5 2 6 6 15 70 1 8 100 8
DATA 0 232 146 5 2 6 6 20 71 1 4 100 8
DATA 0 8 146 5 2 6 6 20 66 1 4 100 8
DATA 0 40 8 5 2 6 8 5 69 1 2 140 8
DATA 0 200 8 5 2 6 8 5 69 1 2 140 8
DATA 0 200 8 5 2 6 8 5 69 1 2 140 8
DATA 0 8 128 5 2 6 8 5 67 1 10 100 8
DATA 0 80 8 5 2 6 8 5 67 1 10 100 8
DATA 0 80 8 5 2 6 8 5 67 1 10 100 8
Comentarios