;############## Calcuzap by Patrick Davidson - basic enemy handling ;############## Move/draw enemies ; Calls the code specified by the enemy 'type'. The 'type', which must ; be a multiple of 3, is an index into the table of jumps for enemy code. ; Enemy routines should move the enemy and draw its image. They are ; called with HL pointing to the enemy entry, and can change all registers. process_enemies: ld hl,enemies ld b,e_count ld a,b ld (enemies_left),a loop_enemies: ld a,(hl) push hl push bc and %11000000 jr z,no_flash ld de,Draw_Sprite_Flash ld (Draw_Sprite+1),de ld a,(hl) sub %1000000 ld (hl),a no_flash: ld a,(hl) and %111111 #ifdef TI84CE call do_enemy #else ld de,no_enemy call dispatch_ADE #endif pop bc pop hl ld de,e_size add hl,de djnz loop_enemies ld hl,enemy_delay ld a,(hl) or a jr z,no_enemy_delay dec (hl) ret nz ld hl,(enemy_entry) jp (hl) no_enemy_delay: ld a,(enemies_left) or a jp z,next_level cp 13 ret nc ld a,(flag_spin) add a,a ret z ld hl,enemies ld b,e_count loop_go_on_rampage: ld a,(hl) or a jr z,skip_rampage cp 13 jr nc,skip_rampage ld (hl),30 push hl ld de,e_misc add hl,de push hl call get_rand pop hl and 6 ld (hl),a pop hl skip_rampage: ld de,e_size add hl,de djnz loop_go_on_rampage ret #ifdef TI84CE do_enemy: push hl ld bc,0 ld c,a ld hl,no_enemy add hl,bc ld hl,(hl) ex (sp),hl ret #endif ;############## Enemy table starts here no_enemy: #ifdef TI84CE .dl null_enemy ; 0 = no enemy here .dl enemy_down ; 3 = enemy in process of entering .dl enemy_right .dl enemy_up .dl enemy_left .dl exploding_enemy ; 15 = exploding enemy .dl boss_entering ; 18 = basic boss entering .dl boss_main ; 21 = boss main .dl triangle_right ; 24 = triangle going right .dl triangle_left ; 27 = triangle going left .dl rampaging_enemy ; 30 = enemy bouncing randomly .dl pattern_wait ; 33 = patterned enemy waiting to enter .dl pattern_active .dl swoop_wait .dl swoop_active .dl swoop_right .dl swoop_up ; 48 .dl megaboss ; 51 .dl zigzag_waiting ; 54 .dl zigzag ; 57 .dl special_explode ; 60 .dl escape_pod ; 63 #else jp null_enemy ; 0 = no enemy here jp enemy_down ; 3 = enemy in process of entering jp enemy_right jp enemy_up jp enemy_left jp exploding_enemy ; 15 = exploding enemy jp boss_entering ; 18 = basic boss entering jp boss_main ; 21 = boss main jp triangle_right ; 24 = triangle going right jp triangle_left ; 27 = triangle going left jp rampaging_enemy ; 30 = rampaging spinner jp pattern_wait ; 33 = patterned enemy waiting to enter jp pattern_active ; 36 = patterned enemy while active jp swoop_wait ; 39 = waiting to swoop in jp swoop_active ; 42 jp swoop_right jp swoop_up ; 48 jp megaboss jp zigzag_waiting ; 54 jp zigzag ; 57 jp special_explode ; 60 jp escape_pod ; 63 #endif ; Special explosion that launches and escape pod afterwards special_explode: push hl call exploding_enemy pop hl ld a,(hl) or a ret nz push hl ld (hl),63 inc hl inc (hl) inc (hl) inc hl inc (hl) inc (hl) ld de,e_dmg-e_y add hl,de ld (hl),9 pop hl jp escape_pod exploding_enemy: inc hl ld b,(hl) ; X coordinate inc hl ld c,(hl) ; Y coordinate inc hl #ifdef TI84CE ld de,(hl) inc hl inc hl #else ld e,(hl) inc hl ld d,(hl) ; DE = image pointer #endif ld a,(de) inc a jr z,enemy_gone push hl push de ld l,c call Draw_Sprite_Packed pop de pop hl inc hl dec (hl) ; decrement next frame counter ret nz ld (hl),2 ; 2 cycles to next frame ex de,hl ; HL -> image ld bc,394 add hl,bc ; HL -> next image ex de,hl dec hl #ifdef TI84CE dec hl dec hl ld (hl),de #else ld (hl),d ; store updated image pointer dec hl ld (hl),e #endif ret enemy_gone: dec hl dec hl dec hl #ifdef TI84CE dec hl #endif dec hl ld (hl),0 push bc call drop_bonus_maybe pop bc ld de,(7*256)+14 jp Erase_Rectangle ; ############# Spin enemies if flag is set, called with HL -> X coordinate, leave HL unchanged maybe_spin: ld a,(flag_spin) add a,a ret z always_spin: push hl ld hl,(spin_image) ld de,394 ld a,(frame_count) rra and 3 jr z,first_frame ld b,a loop_spin: add hl,de djnz loop_spin first_frame: ex de,hl pop hl inc hl inc hl #ifdef TI84CE ld (hl),de #else ld (hl),e inc hl ld (hl),d dec hl #endif dec hl dec hl ret null_enemy: ld hl,enemies_left dec (hl) ret