To make spawning enemies a bit more player friendly spawns are now shown before the enemy actually appears.
The way to implement this is quite simple. We've got a neat object system running already, so we make the spawn animation just another type.
Once the spawn life time is up the object is replaced in spot with the proper object type.
During a spawn point process we store the target type in SPRITE_ANNOYED (since spawns do not get annoyed):
;store spawn type in SPRITE_ANNOYED
ldx PARAM7
lda PARAM5
sta SPRITE_ANNOYED,x
The spawns behaviour is straight forward, animate, count life time down and finally spawn the final object:
;------------------------------------------------------------
;Spawn
;------------------------------------------------------------
!zone BehaviourSpawn
BehaviourSpawn
inc SPRITE_ANIM_DELAY,x
lda SPRITE_ANIM_DELAY,x
cmp #3beq .UpdateAnimation
rts
.UpdateAnimation
lda #0
sta SPRITE_ANIM_DELAY,x
lda SPRITE_POINTER_BASE,x
eor #$01
sta SPRITE_POINTER_BASE,x
inc SPRITE_MOVE_POS,x
lda SPRITE_MOVE_POS,x
cmp #20beq .SpawnNow
rts
.SpawnNow
lda SPRITE_ANNOYED,x
sta PARAM3
lda SPRITE_CHAR_POS_X,x
sta PARAM1
lda SPRITE_CHAR_POS_Y,x
sta PARAM2
stx PARAM7
lda #1
jsr SpawnObject
ldx PARAM7
rts
The rest is too simple to show it here line by line, add new constants for the sprite, add the entry to the behaviour and hurt tables, add entries to the type start tables (color, sprite, etc.) and we're done.
And now the player is not killed by suddenly appearing enemies.