dos33fsprogs/ootw/ootw_c1_sluggy.s

830 lines
12 KiB
ArmAsm
Raw Normal View History

2019-01-20 04:51:58 +00:00
; Sluggy Freelance
2019-01-24 21:03:29 +00:00
2019-08-19 21:16:44 +00:00
; slug behavior from game:
; cavern1: three slugs (2 on ceiling)
; cavern2: four slugs (1 on ceiling) but 3 more will respawn on ceiling
; as you kill them
; so 7 total to track
2019-01-24 21:03:29 +00:00
; Crawl forward. When close, attack.
; Ceiling: crawl until within X of physicist
; then swing a few times and fall
; face toward physicist when start crawling
; Attacks: only attack if on ground and physicist is on ground
; will attempt to attack if you jump over
; Off edge of screen: will disappear but will respawn if leave/re-enter
2019-08-20 03:36:36 +00:00
; Fall from ceiling when get too close, also earthquakes?
; algorithm unclear
2019-01-24 21:03:29 +00:00
2019-01-20 04:51:58 +00:00
;==================================
; draw slugs
;==================================
2019-08-19 21:16:44 +00:00
NUM_SLUGS = 7
2019-01-20 04:51:58 +00:00
2019-08-19 21:16:44 +00:00
; 1 is out, 2 is respawn?
slugg_out:
2019-01-20 04:51:58 +00:00
slugg0_out: .byte 1 ; 0
2019-08-19 21:16:44 +00:00
slugg1_out: .byte 1 ; 0
slugg2_out: .byte 1 ; 0
2019-01-20 04:51:58 +00:00
2019-08-19 21:16:44 +00:00
slugg3_out: .byte 1 ; 0
slugg4_out: .byte 1 ; 0
slugg5_out: .byte 1 ; 0
slugg6_out: .byte 1 ; 0
2019-01-20 04:51:58 +00:00
2019-08-19 21:16:44 +00:00
slugg_attack:
slugg0_attack: .byte 0 ; 1
slugg1_attack: .byte 0
2019-01-20 04:51:58 +00:00
slugg2_attack: .byte 0
2019-01-21 04:46:05 +00:00
slugg3_attack: .byte 0 ; 1
slugg4_attack: .byte 0
slugg5_attack: .byte 0
2019-01-21 05:07:32 +00:00
slugg6_attack: .byte 0
2019-08-19 21:16:44 +00:00
slugg_dying:
slugg0_dying: .byte 0 ; 2
slugg1_dying: .byte 0
slugg2_dying: .byte 0
slugg3_dying: .byte 0 ; 2
slugg4_dying: .byte 0
slugg5_dying: .byte 0
2019-01-21 05:07:32 +00:00
slugg6_dying: .byte 0
2019-08-19 21:16:44 +00:00
slugg_x:
slugg0_x: .byte 30 ; 3
slugg1_x: .byte 30
slugg2_x: .byte 30
slugg3_x: .byte 30 ; 3
slugg4_x: .byte 30
slugg5_x: .byte 30
2019-01-21 05:07:32 +00:00
slugg6_x: .byte 30
2019-08-19 21:16:44 +00:00
slugg_y:
slugg0_y: .byte 30 ; 4
slugg1_y: .byte 30
slugg2_y: .byte 2
slugg3_y: .byte 30 ; 4
slugg4_y: .byte 30
slugg5_y: .byte 30
slugg6_y: .byte 2
2019-08-19 21:16:44 +00:00
slugg_dir:
slugg0_dir: .byte $ff ; 5
slugg1_dir: .byte $ff
slugg2_dir: .byte $ff
slugg3_dir: .byte $ff ; 5
slugg4_dir: .byte $ff
slugg5_dir: .byte $ff
2019-01-21 05:07:32 +00:00
slugg6_dir: .byte $ff
2019-08-19 21:16:44 +00:00
slugg_gait:
slugg0_gait: .byte 0 ; 6
slugg1_gait: .byte 0
slugg2_gait: .byte 0
slugg3_gait: .byte 0 ; 6
slugg4_gait: .byte 0
slugg5_gait: .byte 0
2019-01-21 05:07:32 +00:00
slugg6_gait: .byte 0
2019-08-19 21:16:44 +00:00
slugg_falling:
slugg0_falling: .byte 0 ; 7
slugg1_falling: .byte 0
slugg2_falling: .byte 0
slugg3_falling: .byte 0 ; 7
slugg4_falling: .byte 0
slugg5_falling: .byte 0
2019-01-24 21:03:29 +00:00
slugg6_falling: .byte 0
2019-01-21 05:07:32 +00:00
2019-01-21 04:46:05 +00:00
;========================
; Init the slug creatures
;========================
init_slugs:
; outside loop, init ceiling-ness
; ground slugs
lda #30
sta slugg0_y
sta slugg3_y
sta slugg4_y
sta slugg5_y
; ceiling slugs
lda #2
sta slugg1_y
sta slugg2_y
sta slugg6_y
2019-01-21 04:46:05 +00:00
ldx #0
init_slug_loop:
2019-01-21 05:07:32 +00:00
; Mark slug as out and alive
2019-08-19 21:16:44 +00:00
; if slugs 4,5,6 then get 2 for respawn
2019-01-21 05:07:32 +00:00
lda #1
2019-08-19 21:16:44 +00:00
cpx #4
bcc regular_slug ; blt
lda #2
regular_slug:
sta slugg_out,X
2019-01-21 05:07:32 +00:00
2019-08-20 03:36:36 +00:00
; Put 1st slug on floor, rest on ceiling
; Mark slug as not attacking, dying, or falling
2019-01-21 05:07:32 +00:00
2019-01-21 04:46:05 +00:00
lda #0
2019-08-19 21:16:44 +00:00
sta slugg_attack,X
sta slugg_dying,X
2019-08-20 03:36:36 +00:00
sta slugg_falling,X
2019-01-21 05:07:32 +00:00
; Point the slug in the correct direction (left in this case)
2019-01-21 04:46:05 +00:00
lda #$ff
2019-08-19 21:16:44 +00:00
sta slugg_dir,X
2019-01-21 04:46:05 +00:00
; pick X
2019-01-21 05:07:32 +00:00
jsr init_slug_x
2019-01-21 05:07:32 +00:00
2019-01-21 04:46:05 +00:00
2019-01-21 05:07:32 +00:00
; Make the slug movement random so they don't all move in sync
2019-01-21 04:46:05 +00:00
jsr random16
2019-01-21 05:07:32 +00:00
lda SEEDL
2019-08-19 21:16:44 +00:00
sta slugg_gait,X
2019-01-21 04:46:05 +00:00
2019-01-21 05:07:32 +00:00
; incrememnt struct pointer until all are initialized
2019-08-19 21:16:44 +00:00
inx
cpx #NUM_SLUGS
2019-01-21 04:46:05 +00:00
bne init_slug_loop
2019-01-21 05:07:32 +00:00
; FIXME: originally forced some spacing between them
2019-01-21 04:46:05 +00:00
rts
init_slug_x:
; Randomly pick an X value to appear at
jsr random16
lda SEEDL
and #$1f
clc
adc #8 ; appear from x = 8..32
cmp #32
bcc slugx_not_too_high ; blt
lsr ; div by two if too large
slugx_not_too_high:
sta slugg_x,X
rts
2019-01-21 04:46:05 +00:00
2019-08-20 03:36:36 +00:00
;========================
; Refresh slugs
;========================
; call when re-enter room
; any falling slugs put on ground
; any off-screen slugs, respawn
refresh_slugs:
ldx #0
refresh_slug_loop:
; put falling slugs on ground
lda #0
sta slugg_falling,X
lda slugg_y,X
cmp #2
beq refresh_y_ok
lda #30
sta slugg_y,X
refresh_y_ok:
; if X out of range, redo
lda slugg_x,X
bmi refresh_x
cmp #38
bcs refresh_x
jmp refresh_x_fine
refresh_x:
jsr init_slug_x
refresh_x_fine:
; should also do something about attack/destroy
; but that only an issue if they leave the room
; really suddenly somehow
inx
cpx #NUM_SLUGS
bne refresh_slug_loop
2019-08-20 03:36:36 +00:00
rts
;========================
2019-01-21 04:46:05 +00:00
;========================
; Draw the slug creatures
;========================
2019-08-20 03:36:36 +00:00
;========================
2019-01-20 04:51:58 +00:00
draw_slugs:
2019-01-21 05:07:32 +00:00
ds_smc1:
2019-01-24 21:03:29 +00:00
ldx #0 ; loop through all. self-modify
2019-01-20 04:51:58 +00:00
stx WHICH_SLUG
draw_slugs_loop:
ldx WHICH_SLUG
2019-08-19 21:16:44 +00:00
lda slugg_out,X
2019-01-20 04:51:58 +00:00
bne check_kicked ; don't draw if not there
jmp slug_done
check_kicked:
2019-08-19 21:16:44 +00:00
lda slugg_dying,X ; only kick if alive
2019-01-20 04:51:58 +00:00
bne check_attack
2019-08-19 21:16:44 +00:00
lda slugg_y,X ; only kick if on ground
2019-01-24 21:03:29 +00:00
cmp #30
bne check_attack
2019-01-20 04:51:58 +00:00
;==================
; see if kicked
lda PHYSICIST_STATE
cmp #P_KICKING
beq were_kicking
cmp #P_CROUCH_KICKING
2019-03-15 17:00:47 +00:00
bne check_attack
2019-01-20 04:51:58 +00:00
were_kicking:
2019-01-20 04:51:58 +00:00
lda PHYSICIST_X
sec
2019-08-19 21:16:44 +00:00
sbc slugg_x,X ; -4 to +4
2019-01-20 04:51:58 +00:00
clc
adc #4
and #$f8
bne not_kicked
kicked:
2019-08-19 21:16:44 +00:00
; lda #2
; sta slugg_out,X
2019-01-20 04:51:58 +00:00
lda #10
2019-08-19 21:16:44 +00:00
sta slugg_dying,X
2019-01-20 04:51:58 +00:00
lda DIRECTION
2019-08-19 21:16:44 +00:00
sta slugg_dir,X
2019-01-20 04:51:58 +00:00
not_kicked:
check_attack:
;==================
; see if attack
2019-08-19 21:16:44 +00:00
lda slugg_out,X ; only attack if out
2019-08-20 03:36:36 +00:00
beq no_attack
2019-01-20 04:51:58 +00:00
2019-08-19 21:16:44 +00:00
lda slugg_y,X ; only attack if on ground
2019-01-24 21:03:29 +00:00
cmp #30
bne no_attack
2019-08-20 03:36:36 +00:00
lda slugg_dying,X ; only attack if not exploding
bne no_attack
lda slugg_falling,X ; only attack if not falling
bne no_attack
; lda PHYSICIST_Y ; only attack if physicist on ground
; cmp #22
; bne no_attack
lda PHYSICIST_STATE ; don't attack if jumping
cmp #P_JUMPING
beq no_attack
cmp #P_JUMPING|STATE_RUNNING
beq no_attack
2019-01-24 21:03:29 +00:00
2019-01-20 04:51:58 +00:00
lda PHYSICIST_X
sec
2019-08-19 21:16:44 +00:00
sbc slugg_x,X ; -2 to +2
2019-01-20 04:51:58 +00:00
clc
adc #2
and #$fc
bne no_attack
attack:
;=================
; start an attack
lda #1
2019-08-19 21:16:44 +00:00
sta slugg_attack,X
2019-01-20 04:51:58 +00:00
lda PHYSICIST_STATE ; don't re-attack if already dead
cmp #P_COLLAPSING
beq no_attack
2019-01-20 04:51:58 +00:00
lda #P_COLLAPSING ; start collapsing
sta PHYSICIST_STATE
2019-01-20 04:51:58 +00:00
lda #0
sta GAIT
2019-01-20 04:51:58 +00:00
stx WHICH_SLUG
jsr slug_cutscene
ldx WHICH_SLUG
no_attack:
2019-08-20 03:36:36 +00:00
;====================
; see if should fall
lda slugg_y,X ; first see if on ceiling
cmp #30
beq no_falling
lda slugg_falling,X
bne no_falling
lda slugg_x,X ; see if near physicist
sec
sbc PHYSICIST_X
clc
adc #8 ; fall if within 8 of physicist
cmp #16
2019-08-20 03:36:36 +00:00
bcs no_falling ; bge
lda #1
sta slugg_falling,X
lda #0
sta slugg_gait,X
no_falling:
2019-08-19 21:16:44 +00:00
inc slugg_gait,X ; increment slug gait counter
2019-01-20 04:51:58 +00:00
2019-08-19 21:16:44 +00:00
lda slugg_gait,X ; only move every 64 frames
2019-01-20 04:51:58 +00:00
and #$3f
cmp #$00
bne slug_no_move
2019-08-20 03:36:36 +00:00
lda slugg_falling,X ; don't move X if falling
bne slug_no_move ; move Y instead in some cases
2019-01-20 04:51:58 +00:00
slug_move:
2019-08-19 21:16:44 +00:00
lda slugg_x,X
2019-01-20 04:51:58 +00:00
clc
2019-08-19 21:16:44 +00:00
adc slugg_dir,X
sta slugg_x,X
;
; we let slugs go off the end, we catch it on room re-init
; though in theory if we wait long enough the slug will wrap
;slug_check_right:
; cmp #39
; bne slug_check_left
; jmp remove_slug
;slug_check_left:
; cmp #0
; bne slug_no_move
; jmp remove_slug
2019-01-20 04:51:58 +00:00
slug_no_move:
;===============================
;===============================
; DRAW SLUG
;===============================
;===============================
;==============
; if exploding
;==============
2019-08-19 21:16:44 +00:00
lda slugg_dying,X
2019-08-20 03:36:36 +00:00
beq check_draw_falling
2019-01-20 04:51:58 +00:00
slug_exploding:
stx WHICH_SLUG
tax ; urgh can't forget tax
lda slug_die_progression,X
sta INL
lda slug_die_progression+1,X
sta INH
ldx WHICH_SLUG
bit SPEAKER
lda FRAMEL
and #$f
bne no_progress
bit SPEAKER
2019-08-19 21:16:44 +00:00
dec slugg_dying,X
dec slugg_dying,X
2019-01-20 04:51:58 +00:00
bne no_progress
jmp remove_slug
no_progress:
jmp slug_selected
2019-08-20 03:36:36 +00:00
;===============
; if falling
;===============
check_draw_falling:
lda slugg_falling,X
beq check_draw_attacking
tay
dey
lda FRAMEL ; slow things down
and #$7
bne done_falling_slugs
2019-08-20 03:36:36 +00:00
; actually fall
cpy #7
beq falling_slugs
falling_slug_inc:
inc slugg_falling,X
lda slugg_falling,X
cmp #13
bne done_falling_slugs
; transition to ground slug
lda #0
sta slugg_falling,X
; set direction
lda slugg_x,X
cmp PHYSICIST_X
bpl slug_transition_left
lda #1
bne slug_transition_store
slug_transition_left:
lda #$ff
slug_transition_store:
sta slugg_dir,X
jmp done_falling_slugs
falling_slugs:
lda slugg_y,X
cmp #30
beq falling_slug_inc
clc
adc #2
sta slugg_y,X
done_falling_slugs:
lda slug_falling_progression_lo,Y
sta INL
lda slug_falling_progression_hi,Y
sta INH
jmp slug_selected
2019-01-20 04:51:58 +00:00
;==============
; if attacking
;==============
check_draw_attacking:
2019-08-19 21:16:44 +00:00
lda slugg_attack,X
beq check_slug_ceiling
2019-01-20 04:51:58 +00:00
slug_attacking:
2019-08-19 21:16:44 +00:00
lda slugg_gait,X
2019-01-20 04:51:58 +00:00
stx WHICH_SLUG
and #$70
lsr
lsr
lsr
tax
lda slug_attack_progression,X
sta INL
lda slug_attack_progression+1,X
sta INH
ldx WHICH_SLUG
jmp slug_selected
;==============
; if on ceiling
;==============
check_slug_ceiling:
2019-08-19 21:16:44 +00:00
lda slugg_y,X
cmp #30
beq slug_normal
2019-08-20 03:36:36 +00:00
;=====================
; ceiling slug
;=====================
slug_ceiling:
2019-08-19 21:16:44 +00:00
lda slugg_gait,X
and #$20
beq slug_ceiling_squinched
slug_ceiling_flat:
lda #<slug_ceiling1
sta INL
lda #>slug_ceiling1
sta INH
bne slug_selected
slug_ceiling_squinched:
lda #<slug_ceiling2
sta INL
lda #>slug_ceiling2
sta INH
jmp slug_selected
2019-08-20 03:36:36 +00:00
2019-01-20 04:51:58 +00:00
;==============
; if normal
;==============
slug_normal:
2019-08-19 21:16:44 +00:00
lda slugg_gait,X
2019-01-20 04:51:58 +00:00
and #$20
beq slug_squinched
slug_flat:
lda #<slug1
sta INL
lda #>slug1
sta INH
bne slug_selected
slug_squinched:
lda #<slug2
sta INL
lda #>slug2
sta INH
;================
; end slug normal
;================
slug_selected:
2019-08-19 21:16:44 +00:00
lda slugg_x,X
2019-01-20 04:51:58 +00:00
sta XPOS
2019-08-19 21:16:44 +00:00
lda slugg_y,X
2019-01-20 04:51:58 +00:00
sec
sbc EARTH_OFFSET
sta YPOS
2019-08-19 21:16:44 +00:00
lda slugg_dir,X
2019-01-20 04:51:58 +00:00
stx WHICH_SLUG
bmi slug_right
slug_left:
2019-08-20 03:36:36 +00:00
jsr put_sprite_crop
2019-01-20 04:51:58 +00:00
jmp slug_done
slug_right:
2019-08-20 03:36:36 +00:00
jsr put_sprite_flipped_crop
2019-01-20 04:51:58 +00:00
slug_done:
2019-08-19 21:16:44 +00:00
ldx WHICH_SLUG
inx
2019-01-20 04:51:58 +00:00
stx WHICH_SLUG
2019-01-21 05:07:32 +00:00
ds_smc2:
2019-08-19 21:16:44 +00:00
cpx #3
2019-01-20 04:51:58 +00:00
beq slug_exit
jmp draw_slugs_loop
slug_exit:
rts
2019-08-20 03:36:36 +00:00
2019-01-20 04:51:58 +00:00
remove_slug:
dec slugg_out,X
beq slug_removed
; was higher, so re-spawn
; respawn on ceiling
lda #2
sta slugg_y,X
; direction=left
lda #$ff
sta slugg_dir,X
; put in random spot
jsr init_slug_x
slug_removed:
2019-01-20 04:51:58 +00:00
jmp slug_done
2019-08-20 03:36:36 +00:00
;===========================
;===========================
; slug cutscene
;===========================
;===========================
slug_cutscene:
;====================
; First the slug part
lda #$8
sta DRAW_PAGE
jsr clear_top
lda #<slug_background
sta INL
lda #>slug_background
sta INH
lda #15
sta XPOS
lda #10
sta YPOS
jsr put_sprite
lda #$0
sta DRAW_PAGE
jsr gr_copy_to_current
jsr page_flip
jsr gr_copy_to_current
jsr page_flip
ldx #0
stx CUTFRAME
sluggy_loop:
jsr gr_copy_to_current
ldx CUTFRAME
lda slug_frames,X
sta INL
lda slug_frames+1,X
sta INH
lda #15
sta XPOS
lda #18
sta YPOS
jsr put_sprite
jsr page_flip
ldx #2
long_delay:
lda #250
jsr WAIT
dex
bne long_delay
ldx CUTFRAME
inx
inx
stx CUTFRAME
cpx #12
beq sluggy_end
jmp sluggy_loop
sluggy_end:
;====================
; Then the leg part
lda #$8
sta DRAW_PAGE
jsr clear_top
lda #<leg_background
sta INL
lda #>leg_background
sta INH
lda #15
sta XPOS
lda #10
sta YPOS
jsr put_sprite
lda #$0
sta DRAW_PAGE
jsr gr_copy_to_current
jsr page_flip
jsr gr_copy_to_current
jsr page_flip
ldx #0
stx CUTFRAME
leg_loop:
jsr gr_copy_to_current
ldx CUTFRAME
lda leg_frames,X
sta INL
lda leg_frames+1,X
sta INH
lda #18
sta XPOS
lda #18
sta YPOS
jsr put_sprite
jsr page_flip
ldx #4
long_delay2:
lda #250
jsr WAIT
dex
bne long_delay2
ldx CUTFRAME
inx
inx
stx CUTFRAME
cpx #12
beq leg_end
jmp leg_loop
leg_end:
;=============================
; Restore background to $c00
jmp cavern_load_background
; rts ; tail call?
; sluggy freelance
slug_frames:
.word sluggy1
.word sluggy2
.word sluggy3
.word sluggy4
.word sluggy5
.word sluggy6
leg_frames:
.word leg1
.word leg2
.word leg3
.word leg4
.word leg5
.word leg5