dos33fsprogs/ootw/collision.s

586 lines
10 KiB
ArmAsm
Raw Normal View History

2019-08-15 19:12:34 +00:00
TARGET_NONE = $00
TARGET_DOOR = $10
TARGET_SHIELD = $20
TARGET_FRIEND = $30
TARGET_ALIEN = $40
TARGET_PHYSICIST= $80
2019-08-15 19:12:34 +00:00
;=============================
;=============================
; recalc_walk_collision
;=============================
;=============================
; far left limit is LEVEL_LEFT limit
; far right limit is LEVEL_RIGHT limit
; any LOCKED doors in the way also stop things
2019-08-15 18:12:32 +00:00
; FIXME: only door collision if on same level
recalc_walk_collision:
lda RIGHT_LIMIT
sta RIGHT_WALK_LIMIT
lda LEFT_LIMIT
sta LEFT_WALK_LIMIT
lda NUM_DOORS
beq done_recalc_walk_right_collision
recalc_walk_left:
lda PHYSICIST_X
2019-08-16 18:34:16 +00:00
ldy NUM_DOORS
dey
recalc_walk_left_loop:
cmp (DOOR_X),Y
bcc recalc_walk_left_continue ; blt
; only if closer than previous found
lda LEFT_WALK_LIMIT
cmp (DOOR_X),Y
bcs recalc_walk_left_continue ; bge
2019-08-16 18:34:16 +00:00
lda (DOOR_STATUS),Y
cmp #DOOR_STATUS_LOCKED
bne recalc_walk_left_continue
; early exit
lda (DOOR_X),Y
ora #$80
sta LEFT_WALK_LIMIT
jmp done_recalc_walk_left_collision
recalc_walk_left_continue:
2019-08-16 18:34:16 +00:00
dey
bpl recalc_walk_left_loop
done_recalc_walk_left_collision:
lda PHYSICIST_X
2019-08-16 18:34:16 +00:00
ldy #0
recalc_walk_right_loop:
cmp (DOOR_X),Y
bcs recalc_walk_right_continue ; bge
; only if closer than previous found
lda RIGHT_WALK_LIMIT
cmp (DOOR_X),Y
bcc recalc_walk_right_continue ; blt
2019-08-16 18:34:16 +00:00
lda (DOOR_STATUS),Y
cmp #DOOR_STATUS_LOCKED
bne recalc_walk_right_continue
; early exit
lda (DOOR_X),Y
sec
sbc #4
ora #$80
sta RIGHT_WALK_LIMIT
jmp done_recalc_walk_right_collision
recalc_walk_right_continue:
2019-08-16 18:34:16 +00:00
iny
cpy NUM_DOORS
bne recalc_walk_right_loop
done_recalc_walk_right_collision:
rts
2019-08-15 18:12:32 +00:00
;=============================
;=============================
; calc_gun_right_collision
;=============================
;=============================
; far right limit is LEVEL_RIGHT
; any LOCKED or CLOSED doors with SAME_Y to left of LEVEL_RIGHT
2019-08-15 18:12:32 +00:00
; any shield stops things
; our friend stops things
; any enemies stop things
calc_gun_right_collision:
2019-08-15 19:12:34 +00:00
lda #$00
sta RIGHT_SHOOT_TARGET
;=====================================================================
; by default set it to left limit (which is often but not always a wall)
2019-08-15 18:12:32 +00:00
lda RIGHT_LIMIT
and #$7f
sta RIGHT_SHOOT_LIMIT
2019-08-15 19:26:02 +00:00
;===========================
; stop if hit door
calc_gun_right_door:
2019-08-15 18:12:32 +00:00
lda NUM_DOORS
2019-08-15 19:26:02 +00:00
beq done_calc_gun_right_door_collision
2019-08-15 18:12:32 +00:00
calc_gun_right_doors:
2019-08-16 18:34:16 +00:00
ldy #0
2019-08-15 19:26:02 +00:00
calc_gun_right_door_loop:
2019-08-15 18:12:32 +00:00
; only if on same level
lda (DOOR_Y),Y
clc
adc #4
cmp COLLISION_Y
bne calc_gun_right_door_continue
2019-08-15 18:12:32 +00:00
lda COLLISION_X
cmp (DOOR_X),Y
2019-08-15 19:26:02 +00:00
bcs calc_gun_right_door_continue ; bge
2019-08-15 18:12:32 +00:00
2019-08-16 18:34:16 +00:00
lda (DOOR_STATUS),Y
2019-08-15 18:12:32 +00:00
cmp #DOOR_STATUS_LOCKED
beq calc_gun_right_door_there
cmp #DOOR_STATUS_CLOSED
2019-08-15 19:26:02 +00:00
bne calc_gun_right_door_continue
2019-08-15 18:12:32 +00:00
calc_gun_right_door_there:
; early exit
lda (DOOR_X),Y
2019-08-15 18:12:32 +00:00
sta RIGHT_SHOOT_LIMIT
2019-08-15 19:12:34 +00:00
2019-08-16 18:34:16 +00:00
tya ; set target if hit
2019-08-15 19:12:34 +00:00
ora #TARGET_DOOR
sta RIGHT_SHOOT_TARGET
2019-08-15 19:26:02 +00:00
jmp done_calc_gun_right_door_collision
2019-08-15 18:12:32 +00:00
2019-08-15 19:26:02 +00:00
calc_gun_right_door_continue:
2019-08-16 18:34:16 +00:00
iny
cpy NUM_DOORS
2019-08-15 19:26:02 +00:00
bne calc_gun_right_door_loop
done_calc_gun_right_door_collision:
;==========================
; adjust for shield
calc_gun_right_shield:
lda SHIELD_OUT
beq done_calc_gun_right_shield_collision
ldx #0
calc_gun_right_shield_loop:
; FIXME: check for on same level?
lda shield_out,X
beq calc_gun_right_shield_continue
lda COLLISION_X
cmp shield_x,X
bcs calc_gun_right_shield_continue ; bge
; be sure closer than current max limit
lda RIGHT_SHOOT_LIMIT
cmp shield_x,X
bcc calc_gun_right_shield_continue ; blt
calc_gun_right_shield_there:
lda shield_x,X
sta RIGHT_SHOOT_LIMIT
txa ; set target if hit
ora #TARGET_SHIELD
sta RIGHT_SHOOT_TARGET
; can't early exit
calc_gun_right_shield_continue:
inx
cpx #MAX_SHIELDS
bne calc_gun_right_shield_loop
done_calc_gun_right_shield_collision:
;==========================
; adjust for friend
calc_gun_right_friend:
lda friend_room
cmp WHICH_ROOM
bne done_calc_gun_right_friend_collision
lda COLLISION_X
cmp friend_x
bcs calc_gun_right_friend_continue ; bge
; only if closer than previous found
lda RIGHT_SHOOT_LIMIT
cmp friend_x
bcc calc_gun_right_friend_continue ; blt
lda friend_state
cmp #F_DISINTEGRATING
beq calc_gun_right_friend_continue
calc_gun_right_friend_there:
; early exit
lda friend_x
sta RIGHT_SHOOT_LIMIT
; set target if hit
lda #TARGET_FRIEND
sta RIGHT_SHOOT_TARGET
calc_gun_right_friend_continue:
done_calc_gun_right_friend_collision:
2019-08-22 17:20:10 +00:00
;==========================
; adjust for physicist
calc_gun_right_physicist:
lda COLLISION_X
cmp PHYSICIST_X
bcs calc_gun_right_physicist_continue ; bge
; only if closer than previous found
lda RIGHT_SHOOT_LIMIT
cmp PHYSICIST_X
bcc calc_gun_right_physicist_continue ; blt
lda PHYSICIST_STATE
cmp #P_DISINTEGRATING
beq calc_gun_right_physicist_continue
calc_gun_right_physicist_there:
lda PHYSICIST_X
sta RIGHT_SHOOT_LIMIT
; set target if hit
lda #TARGET_PHYSICIST
sta RIGHT_SHOOT_TARGET
calc_gun_right_physicist_continue:
done_calc_gun_right_physicist_collision:
2019-08-15 19:26:02 +00:00
;==========================
; adjust for alien
calc_gun_right_alien:
lda ALIEN_OUT
beq done_calc_gun_right_alien_collision
ldx #0
calc_gun_right_alien_loop:
lda alien_room,X
cmp WHICH_ROOM
bne calc_gun_right_alien_continue
2019-08-15 19:26:02 +00:00
; only if on same level
lda alien_y,X
cmp COLLISION_Y
bne calc_gun_right_alien_continue
2019-08-15 18:12:32 +00:00
lda COLLISION_X
2019-08-15 19:26:02 +00:00
cmp alien_x,X
bcs calc_gun_right_alien_continue ; bge
2019-08-15 18:12:32 +00:00
; only if closer than previous found
lda RIGHT_SHOOT_LIMIT
cmp alien_x,X
bcc calc_gun_right_alien_continue ; blt
2019-08-15 19:26:02 +00:00
lda alien_state,X
cmp #A_DISINTEGRATING
beq calc_gun_right_alien_continue
2019-08-15 18:12:32 +00:00
2019-08-15 19:26:02 +00:00
calc_gun_right_alien_there:
lda alien_x,X
sta RIGHT_SHOOT_LIMIT
txa ; set target if hit
ora #TARGET_ALIEN
sta RIGHT_SHOOT_TARGET
; can't early exit
2019-08-15 19:26:02 +00:00
calc_gun_right_alien_continue:
inx
2019-08-15 20:27:02 +00:00
cpx #MAX_ALIENS
2019-08-15 19:26:02 +00:00
bne calc_gun_right_alien_loop
done_calc_gun_right_alien_collision:
2019-08-15 18:12:32 +00:00
rts
;=============================
;=============================
; calc_gun_left_collision
;=============================
;=============================
; far right limit is LEVEL_LEFT
; any LOCKED or CLOSED doors stop things
; any shield stops things
; our friend stops things
; any enemies stop things
calc_gun_left_collision:
2019-08-15 19:12:34 +00:00
lda #0
sta LEFT_SHOOT_TARGET
;=============================
; by default set to left limit
; tricky as LEFT_LIMIT does some hacks to put it up above $80
2019-08-15 18:12:32 +00:00
lda LEFT_LIMIT
2019-08-15 20:27:02 +00:00
sec
sbc #$80
bpl left_limit_ok
lda #0
left_limit_ok:
2019-08-15 18:12:32 +00:00
sta LEFT_SHOOT_LIMIT
;==========================
; stop if hit door
calc_gun_left_door:
2019-08-15 18:12:32 +00:00
lda NUM_DOORS
2019-08-15 19:26:02 +00:00
beq done_calc_gun_left_door_collision
2019-08-15 18:12:32 +00:00
calc_gun_left_doors:
2019-08-16 18:34:16 +00:00
ldy NUM_DOORS
dey
2019-08-15 19:26:02 +00:00
calc_gun_left_door_loop:
2019-08-15 18:12:32 +00:00
; only if on same level
lda (DOOR_Y),Y
clc
adc #4
cmp COLLISION_Y
bne calc_gun_left_door_continue
lda COLLISION_X
cmp (DOOR_X),Y
2019-08-15 19:26:02 +00:00
bcc calc_gun_left_door_continue ; blt
2019-08-15 18:12:32 +00:00
2019-08-16 18:34:16 +00:00
lda (DOOR_STATUS),Y
2019-08-15 18:12:32 +00:00
cmp #DOOR_STATUS_LOCKED
beq calc_gun_left_door_there
cmp #DOOR_STATUS_CLOSED
2019-08-15 19:26:02 +00:00
bne calc_gun_left_door_continue
2019-08-15 18:12:32 +00:00
calc_gun_left_door_there:
; early exit
lda (DOOR_X),Y
2019-08-15 18:12:32 +00:00
sta LEFT_SHOOT_LIMIT
2019-08-15 19:12:34 +00:00
2019-08-16 18:34:16 +00:00
tya ; set target if hit
2019-08-15 19:12:34 +00:00
ora #TARGET_DOOR
sta LEFT_SHOOT_TARGET
2019-08-15 19:26:02 +00:00
jmp done_calc_gun_left_door_collision
calc_gun_left_door_continue:
2019-08-16 18:34:16 +00:00
dey
2019-08-15 19:26:02 +00:00
bpl calc_gun_left_door_loop
done_calc_gun_left_door_collision:
2019-08-15 20:27:02 +00:00
;==========================
; adjust for shield
calc_gun_left_shield:
lda SHIELD_OUT
beq done_calc_gun_left_shield_collision
ldx #0
calc_gun_left_shield_loop:
lda shield_out,X
beq calc_gun_left_shield_continue
lda COLLISION_X
cmp shield_x,X
bcc calc_gun_left_shield_continue ; blt
; be sure closer than current max limit
lda LEFT_SHOOT_LIMIT
cmp shield_x,X
2019-08-20 20:04:33 +00:00
bcs calc_gun_left_shield_continue ; bge
calc_gun_left_shield_there:
lda shield_x,X
sta LEFT_SHOOT_LIMIT
txa ; set target if hit
ora #TARGET_SHIELD
sta LEFT_SHOOT_TARGET
; can't early exit
calc_gun_left_shield_continue:
inx
cpx #MAX_SHIELDS
bne calc_gun_left_shield_loop
done_calc_gun_left_shield_collision:
;==========================
; adjust for friend
calc_gun_left_friend:
lda friend_room
cmp WHICH_ROOM
bne done_calc_gun_left_friend_collision
lda COLLISION_X
cmp friend_x
bcc calc_gun_left_friend_continue ; blt
; only if closer than previous found
lda LEFT_SHOOT_LIMIT
cmp friend_x
2019-08-20 20:04:33 +00:00
bcs calc_gun_left_friend_continue ; bge
lda friend_state
cmp #F_DISINTEGRATING
beq calc_gun_left_friend_continue
calc_gun_left_friend_there:
lda friend_x
sta LEFT_SHOOT_LIMIT
; set target if hit
lda #TARGET_FRIEND
sta LEFT_SHOOT_TARGET
calc_gun_left_friend_continue:
done_calc_gun_left_friend_collision:
2019-08-22 17:20:10 +00:00
;==========================
; adjust for physicist
calc_gun_left_physicist:
lda COLLISION_X
cmp PHYSICIST_X
beq calc_gun_left_physicist_continue ; ble (not w self)
bcc calc_gun_left_physicist_continue ; blt
; only if closer than previous found
lda LEFT_SHOOT_LIMIT
cmp PHYSICIST_X
bcs calc_gun_left_physicist_continue ; bge
lda PHYSICIST_STATE
cmp #P_DISINTEGRATING
beq calc_gun_left_physicist_continue
calc_gun_left_physicist_there:
lda PHYSICIST_X
sta LEFT_SHOOT_LIMIT
; set target if hit
lda #TARGET_PHYSICIST
sta LEFT_SHOOT_TARGET
calc_gun_left_physicist_continue:
done_calc_gun_left_physicist_collision:
2019-08-15 19:26:02 +00:00
;==========================
; adjust for alien
2019-08-15 18:12:32 +00:00
2019-08-15 19:26:02 +00:00
calc_gun_left_alien:
lda ALIEN_OUT
beq done_calc_gun_left_alien_collision
2019-08-15 20:27:02 +00:00
ldx #MAX_ALIENS
2019-08-15 18:12:32 +00:00
dex
2019-08-15 19:26:02 +00:00
calc_gun_left_alien_loop:
lda alien_room,X
cmp WHICH_ROOM
bne calc_gun_left_alien_continue
2019-08-15 19:26:02 +00:00
; only if on same level
lda alien_y,X
cmp COLLISION_Y
bne calc_gun_left_alien_continue
2019-08-15 19:26:02 +00:00
lda COLLISION_X
2019-08-15 19:26:02 +00:00
cmp alien_x,X
beq calc_gun_left_alien_continue ; if exact equal
; might be ourselves
2019-08-15 20:27:02 +00:00
bcc calc_gun_left_alien_continue ; blt
2019-08-15 19:26:02 +00:00
; only if closer than previous found
lda LEFT_SHOOT_LIMIT
cmp alien_x,X
2019-08-20 20:04:33 +00:00
bcs calc_gun_left_alien_continue ; bge
2019-08-15 19:26:02 +00:00
lda alien_state,X
cmp #A_DISINTEGRATING
beq calc_gun_left_alien_continue
calc_gun_left_alien_there:
; early exit
lda alien_x,X
2019-08-15 20:27:02 +00:00
sta LEFT_SHOOT_LIMIT
2019-08-15 19:26:02 +00:00
txa ; set target if hit
ora #TARGET_ALIEN
2019-08-15 20:27:02 +00:00
sta LEFT_SHOOT_TARGET
2019-08-15 19:26:02 +00:00
jmp done_calc_gun_left_alien_collision
calc_gun_left_alien_continue:
dex
bpl calc_gun_left_alien_loop
done_calc_gun_left_alien_collision:
2019-08-15 18:12:32 +00:00
rts