;############## Calcuzap by Patrick Davidson - shooting by enemies ;############## Randomly shoot by megaboss or not megaboss_shoot_maybe: push hl inc hl ld b,(hl) ; B = X coordinate of enemy call get_rand and $EC pop hl ret nz ld a,12 ; default type is straight down ld (eshoot_type+1),a xor a push bc call aim_boss_shoot pop bc ld a,12 ; default type is straight down ld (eshoot_type+1),a ld a,6 push bc call aim_boss_shoot pop bc ld a,12 ld (eshoot_type+1),a jp aim_boss_shoot heavy_shoot_maybe: push hl inc hl ld b,(hl) call get_rand and $EE pop hl ret nz ld a,12 ld (eshoot_type+1),a ld a,2 jp aim_boss_shoot ;############## Randomly drop bonus or not drop_bonus_maybe: ld a,15 ld (eshoot_type+1),a push hl inc hl ; HL -> X ld a,(hl) cp 208-10 ; check if off right side jr c,norightedge_bonus ld (hl),208-10 ; set X to right side minus width norightedge_bonus: call get_rand pop hl and $3F dec a jr z,drop_bonus_points dec a jr z,drop_bonus_life dec a ret nz ld a,(level) cp 36 jr nc,drop_bonus_4 cp 20 jr nc,drop_bonus_3 cp 4 ret c ld de,img_bonus_weapon jr to_enemy_shoot_offset_2 drop_bonus_4: ld de,img_bonus_weapon_4 #ifdef TI84CE jr to_enemy_shoot_offset_2 #else jr enemy_shoot_offset_2 #endif drop_bonus_3: ld de,img_bonus_weapon_3 #ifdef TI84CE jr to_enemy_shoot_offset_2 #else jr enemy_shoot_offset_2 #endif drop_bonus_points: ld de,img_bonus_points #ifdef TI84CE jr to_enemy_shoot_offset_2 #else jr enemy_shoot_offset_2 #endif drop_bonus_life: ld de,img_bonus_life to_enemy_shoot_offset_2: jr enemy_shoot_offset_2 ;############## Randomly shoot by boss or not boss_shoot_maybe: push hl inc hl ld b,(hl) ; B = X coordinate of enemy inc hl inc hl #ifdef TI84CE ld de,(hl) #else ld e,(hl) inc hl ld d,(hl) ; DE -> enemy_image #endif dec de ld a,(de) ; C = original enemy strength ld c,a call get_rand and $EC pop hl ret nz bit 0,c ; use mild boss depending on original strength jr z,mild_boss_shoot ld a,12 ; default type is straight down ld (eshoot_type+1),a xor a ; 0 = X offset for first bullet bit 3,c jr z,left_not_ufo inc a left_not_ufo: push bc call aim_boss_shoot pop bc ld a,12 ld (eshoot_type+1),a ld a,9 ; 9 = X offset for second bullet bit 3,c jr z,right_not_ufo dec a right_not_ufo: ; default type is straight down aim_boss_shoot: ld (ebullet_x_offset+1),a ; save X offset add a,b ; A = bullet starting X ld de,(p_x) cp e jr c,player_to_right player_to_left: sub e ; A = bullet X - player X (distance to right / 2) ld de,img_boss_bullet cp 19 jp c,enemy_shoot_x_set ; distance less than 10, almost straight down ld a,18 jr eshoot_type_in_A player_to_right: sub e ; A = bullet X - player X (distance to right / 2) ld de,img_boss_bullet add a,14 #ifdef TI84CE jp c,enemy_shoot_x_set #else jr c,enemy_shoot_x_set ; distance less than 10, almost straight down #endif ld a,21 eshoot_type_in_A: ld (eshoot_type+1),a #ifdef TI84CE jp enemy_shoot_x_set #else jr enemy_shoot_x_set #endif mild_boss_shoot: ld a,12 ld (eshoot_type+1),a ld a,7 ld de,img_boss_bullet call enemy_shoot ld de,img_boss_bullet enemy_shoot_offset_2: ld a,2 jr enemy_shoot ;############## Randomly shoot at full diagonal or not diagonal_shoot_maybe: push hl call get_rand and $EE pop hl ret nz do_diagonal_shoot: inc hl ld b,(hl) ; B = enemy X coordinate inc hl ld de,(p_x) ; E = player X, D = player Y sub (hl) ; A = delta Y (player - enemy) srl a ; A = delta Y / 2 srl a ; A = delta Y / 4 dec hl dec hl ; HL -> enemy type ld d,a ; D = delta Y / 4 ld a,e sub b ; A = delta X jr c,enemy_at_right cp d ld a,3 jr c,enemy_shoot_type_A ; DY >> DX, so aim straight down ld a,27 jr enemy_shoot_type_A ; shoot to right enemy_at_right: neg cp d ld a,3 jr c,enemy_shoot_type_A ; DY >> DX, so aim stright down ld a,24 jr enemy_shoot_type_A ; shoot to left ;############## Randomly shoot by normal enemy or not enemy_shoot_maybe: push hl call get_rand and $EE pop hl ret nz ld a,(flag_spin) cp 2 jr nc,do_diagonal_shoot ld a,(default_weapon) enemy_shoot_type_A: ld (eshoot_type+1),a ld de,(enemy_image) inc de ld a,(de) ; A = enemy width sra a ; A = enemy width / 2 dec a ; A = enemy width / 2 - 1 push af dec de ld a,(de) ld de,img_enemy_bullet cp 16 jr nz,not_arrow ld de,img_enemy_bullet_arrow ld a,12 ld (eshoot_type+1),a not_arrow: pop af ;############## Search for and fill an enemy bullet structure enemy_shoot: ld (ebullet_x_offset+1),a enemy_shoot_x_set: ld (eshoot_image+1),de push hl ld hl,enemy_bullets ; Locate unused enemy bullet in HL ld b,eb_count ld de,eb_size loop_search_ebullets: ld a,(hl) or a jr z,found_ebullet add hl,de djnz loop_search_ebullets pop hl ret found_ebullet: pop de ; DE -> enemy push de eshoot_type: ld (hl),3 ; new enemy bullet inc hl inc de ld a,(de) ebullet_x_offset: add a,2 ; eb_x = e_x + 2 ld (hl),a inc hl inc de ld a,(de) add a,10 ; eb_y = e_y + 10 ld (hl),a eshoot_image: ld de,img_enemy_bullet inc hl #ifdef TI84CE ld (hl),de #else ld (hl),e inc hl ld (hl),d #endif pop hl ret #ifdef TI84CE get_rand_full: ld de,0 ld e,l ld hl,scroll_message add hl,de ld hl,rand_counter2 inc (hl) add a,(hl) ld hl,rand_inc xor (hl) ld (hl),a #endif get_rand: ld hl,(rand_inc) ld a,h add a,l ld (rand_counter),a ret