dos33fsprogs/ootw/laser.s

356 lines
4.3 KiB
ArmAsm
Raw Normal View History

2019-08-15 20:27:02 +00:00
; FIXME: merge a lot of the target code
2019-08-10 01:46:04 +00:00
; Handle laser
2019-08-10 02:25:10 +00:00
; should handle multiple at once?
2019-08-10 01:46:04 +00:00
2019-08-10 02:25:10 +00:00
; when pressed, find empty slot?
; initially 10 wide, from gun to right or left
; expand to 20 wide
; stop when encounter door, enemy, or edge of screen
; should bounds check carefully
2019-08-10 01:46:04 +00:00
2019-08-10 02:25:10 +00:00
; should handle shooting while crouching
2019-08-10 01:46:04 +00:00
MAX_LASERS = 2
laser_out:
2019-08-10 02:25:10 +00:00
laser0_out: .byte $0
laser1_out: .byte $0
laser_start:
2019-08-10 02:25:10 +00:00
laser0_start: .byte $0
laser1_start: .byte $0
laser_end:
laser0_end: .byte $0
laser1_end: .byte $0
laser_y:
2019-08-10 02:25:10 +00:00
laser0_y: .byte $0
laser1_y: .byte $0
laser_direction:
2019-08-10 02:25:10 +00:00
laser0_direction: .byte $0
laser1_direction: .byte $0
laser_count:
2019-08-10 03:01:15 +00:00
laser0_count: .byte $0
laser1_count: .byte $0
2019-08-10 02:25:10 +00:00
;=========================
; fire laser
;=========================
fire_laser:
lda PHYSICIST_X
sta COLLISION_X
lda PHYSICIST_Y
sta COLLISION_Y
2019-08-10 02:25:10 +00:00
lda laser0_out
bne done_fire_laser
2019-08-10 03:01:15 +00:00
; activate laser slot
2019-08-10 02:25:10 +00:00
inc laser0_out
2019-08-10 03:01:15 +00:00
; reset count
lda #0
sta laser0_count
2019-08-10 02:25:10 +00:00
; set y
2019-08-10 01:46:04 +00:00
lda PHYSICIST_Y
clc
adc #4
2019-08-16 17:53:37 +00:00
ldx PHYSICIST_STATE
cpx #P_CROUCH_SHOOTING
bne laser_crouch_done
laser_crouch:
clc
adc #4
laser_crouch_done:
2019-08-10 02:25:10 +00:00
sta laser0_y
2019-08-10 01:46:04 +00:00
2019-08-10 03:01:15 +00:00
; set direction
2019-08-10 01:46:04 +00:00
lda DIRECTION
2019-08-10 02:25:10 +00:00
sta laser0_direction
2019-08-10 01:46:04 +00:00
beq laser_left
bne laser_right
2019-08-10 02:25:10 +00:00
; set x
2019-08-10 01:46:04 +00:00
laser_left:
2019-08-15 18:12:32 +00:00
jsr calc_gun_left_collision
ldx PHYSICIST_X
dex
stx laser0_end
txa
2019-08-10 03:01:15 +00:00
sec
sbc #10
2019-08-10 02:25:10 +00:00
sta laser0_start
2019-08-10 01:46:04 +00:00
2019-08-10 02:25:10 +00:00
jmp done_fire_laser
2019-08-10 01:46:04 +00:00
laser_right:
2019-08-15 18:12:32 +00:00
jsr calc_gun_right_collision
2019-08-10 01:46:04 +00:00
lda PHYSICIST_X
clc
adc #5
2019-08-10 02:25:10 +00:00
sta laser0_start
2019-08-10 01:46:04 +00:00
clc
adc #10
sta laser0_end
2019-08-10 02:25:10 +00:00
done_fire_laser:
rts
2019-08-10 02:25:10 +00:00
;====================
; draw laser
;====================
2019-08-10 01:46:04 +00:00
2019-08-10 02:25:10 +00:00
draw_laser:
2019-08-10 01:46:04 +00:00
ldx #0
draw_laser_loop:
lda laser_out,X
2019-08-10 02:25:10 +00:00
beq done_draw_laser
txa
pha ; save X on stack
2019-08-10 02:25:10 +00:00
lda #$10
sta hlin_color_smc+1
lda #$0f
sta hlin_mask_smc+1
ldy laser_y,X
sec
lda laser_end,X
sbc laser_start,X
sta LASER_TEMP
lda laser_start,X
ldx LASER_TEMP
2019-08-10 01:46:04 +00:00
jsr hlin
pla ; restore X from stack
tax
2019-08-10 02:25:10 +00:00
done_draw_laser:
inx
cpx #MAX_LASERS
bne draw_laser_loop
2019-08-10 02:25:10 +00:00
2019-08-10 01:46:04 +00:00
rts
2019-08-10 02:25:10 +00:00
;===================
; move laser
;===================
move_laser:
ldx #0
move_laser_loop:
lda laser_out,X
2019-08-10 02:25:10 +00:00
beq done_move_laser
2019-08-10 03:01:15 +00:00
; slow down laser
lda laser_count,X
2019-08-10 03:01:15 +00:00
and #$3
bne no_move_laser
lda laser_direction,X
2019-08-10 03:01:15 +00:00
bne move_laser_right
move_laser_left:
lda laser_count,X
cmp #4
bcc still_starting_left
cmp #8
bcc still_shooting_left
2019-08-10 03:01:15 +00:00
continue_shooting_left:
still_shooting_left:
lda laser_end,X
sec
sbc #10
sta laser_end,X
still_starting_left:
lda laser_start,X
2019-08-10 03:01:15 +00:00
sec
sbc #10
sta laser_start,X
2019-08-10 03:01:15 +00:00
laser_edge_detect_left:
lda laser_end,X
2019-08-15 18:12:32 +00:00
cmp LEFT_SHOOT_LIMIT
2019-08-15 20:27:02 +00:00
bmi disable_laser_left
2019-08-10 03:01:15 +00:00
lda laser_start,X
2019-08-15 18:12:32 +00:00
cmp LEFT_SHOOT_LIMIT
bpl no_move_laser
2019-08-15 18:12:32 +00:00
lda LEFT_SHOOT_LIMIT
sta laser_start,X
2019-08-10 03:01:15 +00:00
jmp no_move_laser
move_laser_right:
lda laser_count,X
2019-08-10 03:01:15 +00:00
cmp #4
bcc still_starting_right
cmp #8
bcc still_shooting_right
continue_shooting_right:
lda laser_start,X
2019-08-10 02:25:10 +00:00
clc
adc #10
sta laser_start,X
2019-08-10 02:25:10 +00:00
2019-08-10 03:01:15 +00:00
still_shooting_right:
lda laser_end,X
clc
adc #10
sta laser_end,X
2019-08-10 03:01:15 +00:00
still_starting_right:
laser_edge_detect_right:
; detect if totally off screen
lda laser_start,X
2019-08-15 18:12:32 +00:00
cmp RIGHT_SHOOT_LIMIT
2019-08-15 20:27:02 +00:00
bcs disable_laser_right
2019-08-10 03:01:15 +00:00
lda laser_end,X
2019-08-15 18:12:32 +00:00
cmp RIGHT_SHOOT_LIMIT
2019-08-10 03:01:15 +00:00
bcc no_move_laser
2019-08-10 02:25:10 +00:00
2019-08-15 18:12:32 +00:00
lda RIGHT_SHOOT_LIMIT
sta laser_end,X
2019-08-10 02:25:10 +00:00
2019-08-10 03:01:15 +00:00
no_move_laser:
inc laser_count,X
2019-08-10 02:25:10 +00:00
done_move_laser:
inx
cpx #MAX_LASERS
bne move_laser_loop
2019-08-10 02:25:10 +00:00
rts
2019-08-15 20:27:02 +00:00
;===================
; hit something, left
2019-08-15 20:27:02 +00:00
;===================
disable_laser_left:
lda LEFT_SHOOT_TARGET
jmp hit_something_common
;====================
; hit something, right
;====================
disable_laser_right:
lda RIGHT_SHOOT_TARGET
;======================
; hit something, common
;======================
hit_something_common:
pha
; disable laser
lda #0
sta laser_out,X
2019-08-15 20:27:02 +00:00
pla
tay
2019-08-15 20:27:02 +00:00
and #$f0
cmp #TARGET_ALIEN
beq laser_hit_alien
cmp #TARGET_FRIEND
beq laser_hit_friend
2019-08-22 17:20:10 +00:00
cmp #TARGET_PHYSICIST
beq laser_hit_physicist
; FIXME: reduce shields if hit them?
jmp done_hit_something
2019-08-15 20:27:02 +00:00
laser_hit_alien:
2019-08-15 20:27:02 +00:00
tya
2019-08-15 20:27:02 +00:00
and #$f
tay
2019-08-15 20:27:02 +00:00
lda #A_DISINTEGRATING
sta alien_state,Y
2019-08-15 20:27:02 +00:00
lda #0
sta alien_gait,Y
2019-08-15 20:27:02 +00:00
jmp done_hit_something
2019-08-15 20:27:02 +00:00
laser_hit_friend:
2019-08-15 20:27:02 +00:00
lda #F_DISINTEGRATING
sta friend_state
2019-08-15 20:27:02 +00:00
lda #FAI_DISINTEGRATING
sta friend_ai_state
2019-08-15 20:27:02 +00:00
lda #0
sta friend_gait
2019-08-15 20:27:02 +00:00
jmp done_hit_something
2019-08-15 20:27:02 +00:00
laser_hit_physicist:
2019-08-15 20:27:02 +00:00
lda #P_DISINTEGRATING
sta PHYSICIST_STATE
lda #0
sta GAIT
2019-08-15 20:27:02 +00:00
done_hit_something:
jmp done_move_laser
; rts
2019-08-15 20:27:02 +00:00
2019-08-10 02:25:10 +00:00
2019-08-15 20:27:02 +00:00