dos33fsprogs/games/lemm/move_lemming.s

629 lines
9.6 KiB
ArmAsm
Raw Normal View History

2022-03-22 03:00:30 +00:00
; TODO: auto-size this based on MAX_LEMMINGS
lemming_x:
.byte 0,0,0,0,0,0,0,0,0,0
lemming_y:
.byte 0,0,0,0,0,0,0,0,0,0
lemming_direction:
.byte 0,0,0,0,0,0,0,0,0,0
lemming_out:
.byte 0,0,0,0,0,0,0,0,0,0
lemming_frame:
.byte 0,0,0,0,0,0,0,0,0,0
lemming_status:
.byte 0,0,0,0,0,0,0,0,0,0
lemming_exploding:
.byte 0,0,0,0,0,0,0,0,0,0
2022-03-23 01:10:57 +00:00
lemming_fall_distance:
.byte 0,0,0,0,0,0,0,0,0,0
2022-03-25 00:27:20 +00:00
lemming_attribute:
.byte 0,0,0,0,0,0,0,0,0,0
2022-03-13 06:28:37 +00:00
;==========================
; move them
;==========================
2022-03-10 06:10:42 +00:00
move_lemmings:
2022-03-11 05:53:18 +00:00
ldy #0
2022-03-30 18:46:46 +00:00
sty CURRENT_LEMMING ; reset loop
2022-03-22 04:05:49 +00:00
move_lemming_loop:
2022-03-30 18:46:46 +00:00
ldy CURRENT_LEMMING ; get current in Y
2022-03-11 05:53:18 +00:00
lda lemming_out,Y
2022-03-10 06:10:42 +00:00
2022-03-30 18:46:46 +00:00
beq skip_move_lemming ; if not out, don't move
2022-03-11 05:53:18 +00:00
really_move_lemming:
2022-03-12 23:03:53 +00:00
; bump frame
tya
tax
2022-03-30 18:46:46 +00:00
inc lemming_frame,X ; only can inc with X
2022-03-12 23:03:53 +00:00
2022-03-30 18:46:46 +00:00
lda lemming_status,Y ; use jump table based on status
2022-03-27 18:05:47 +00:00
tax
lda move_lemming_jump_h,X
pha
lda move_lemming_jump_l,X
pha
rts ; jump to it
2022-03-30 18:46:46 +00:00
skip_move_lemming:
2022-03-27 18:05:47 +00:00
done_move_lemming:
2022-03-10 06:10:42 +00:00
2022-03-30 18:46:46 +00:00
jsr collision_check_ground
2022-03-13 21:18:19 +00:00
2022-03-30 18:46:46 +00:00
inc CURRENT_LEMMING ; loop until done
2022-03-27 18:05:47 +00:00
lda CURRENT_LEMMING
cmp #MAX_LEMMINGS
2022-03-30 18:46:46 +00:00
bne move_lemming_loop
2022-03-27 18:05:47 +00:00
really_done_checking_lemming:
rts
move_lemming_jump_l:
.byte <(do_lemming_falling-1)
.byte <(do_lemming_walking-1)
.byte <(do_lemming_digging-1)
.byte <(do_lemming_exploding-1)
.byte <(do_lemming_particles-1)
.byte <(do_lemming_splatting-1)
.byte <(do_lemming_floating-1)
.byte <(do_lemming_climbing-1)
.byte <(do_lemming_bashing-1)
.byte <(do_lemming_stopping-1)
.byte <(do_lemming_mining-1)
.byte <(do_lemming_building-1)
.byte <(do_lemming_shrugging-1)
.byte <(do_lemming_pullup-1)
move_lemming_jump_h:
.byte >(do_lemming_falling-1)
.byte >(do_lemming_walking-1)
.byte >(do_lemming_digging-1)
.byte >(do_lemming_exploding-1)
.byte >(do_lemming_particles-1)
.byte >(do_lemming_splatting-1)
.byte >(do_lemming_floating-1)
.byte >(do_lemming_climbing-1)
.byte >(do_lemming_bashing-1)
.byte >(do_lemming_stopping-1)
.byte >(do_lemming_mining-1)
.byte >(do_lemming_building-1)
.byte >(do_lemming_shrugging-1)
.byte >(do_lemming_pullup-1)
;=========================
2022-03-13 21:18:19 +00:00
;=========================
; falling
;=========================
2022-03-27 18:05:47 +00:00
;=========================
2022-03-10 06:10:42 +00:00
do_lemming_falling:
2022-03-27 18:05:47 +00:00
tya
tax
inc lemming_y,X ; fall speed
inc lemming_y,X
inc lemming_fall_distance,X ; how far
lda lemming_fall_distance,X
cmp #12
bcc not_fallen_enough ; blt
lda lemming_attribute,X
bpl not_fallen_enough ; see if high bit set
; we can switch to floating
lda #LEMMING_FLOATING
sta lemming_status,X
lda #0
sta lemming_frame,X
not_fallen_enough:
2022-03-30 18:46:46 +00:00
; jsr collision_check_ground
2022-03-27 18:05:47 +00:00
2022-03-25 01:25:26 +00:00
jmp done_move_lemming
2022-03-10 06:10:42 +00:00
2022-03-23 01:10:57 +00:00
2022-03-27 18:05:47 +00:00
;=========================
2022-03-25 01:25:26 +00:00
;=========================
; floating
;=========================
2022-03-27 18:05:47 +00:00
;=========================
2022-03-25 01:25:26 +00:00
do_lemming_floating:
2022-03-27 18:05:47 +00:00
tya
tax
inc lemming_y,X ; fall speed
lda #0
sta lemming_fall_distance,X
2022-03-30 18:46:46 +00:00
; jsr collision_check_ground
2022-03-27 18:05:47 +00:00
2022-03-10 06:10:42 +00:00
jmp done_move_lemming
2022-03-25 01:25:26 +00:00
2022-03-27 18:05:47 +00:00
;=========================
2022-03-13 21:18:19 +00:00
;=========================
; walking
;=========================
2022-03-27 18:05:47 +00:00
;=========================
2022-03-10 06:10:42 +00:00
do_lemming_walking:
2022-03-11 05:53:18 +00:00
2022-03-18 05:59:15 +00:00
; see if ground has risen up
jsr collision_check_hill
2022-03-11 05:53:18 +00:00
2022-03-13 06:28:37 +00:00
; collision detect walls
2022-03-22 04:05:49 +00:00
ldy CURRENT_LEMMING
lda lemming_y,Y
2022-03-11 05:53:18 +00:00
clc
adc #3 ; waist-high?
2022-03-22 04:05:49 +00:00
tax
2022-03-11 05:53:18 +00:00
2022-03-22 04:05:49 +00:00
lda hposn_high,X
2022-03-13 06:28:37 +00:00
clc
adc #$20
2022-03-11 05:53:18 +00:00
sta GBASH
2022-03-22 04:05:49 +00:00
lda hposn_low,X
2022-03-11 05:53:18 +00:00
sta GBASL
2022-03-13 21:18:19 +00:00
; increment
; only do this every 4th frame?
2022-03-22 04:05:49 +00:00
lda lemming_frame,Y
2022-03-13 21:18:19 +00:00
and #$3
beq walking_increment
2022-03-22 04:05:49 +00:00
bne walking_done
2022-03-13 21:18:19 +00:00
walking_increment:
; actually incrememt
2022-03-22 04:05:49 +00:00
clc ; increment/decrement X
lda lemming_x,Y
adc lemming_direction,Y ; A is now incremented version
; sta lemming_x,Y
tay ; Y is now incremented version
2022-03-11 05:53:18 +00:00
2022-03-22 04:05:49 +00:00
lda (GBASL),Y ; collision check
2022-03-11 05:53:18 +00:00
and #$7f
beq walking_no_wall
walking_yes_wall:
2022-03-22 04:05:49 +00:00
; we hit a wall, reverse course, undo the increment
; Y is updated
jsr check_at_exit_xiny
2022-03-11 05:53:18 +00:00
2022-03-13 21:18:19 +00:00
; reverse direction
2022-03-22 04:05:49 +00:00
ldy CURRENT_LEMMING
lda lemming_direction,Y
2022-03-11 05:53:18 +00:00
eor #$ff
clc
adc #1
2022-03-22 04:05:49 +00:00
sta lemming_direction,Y
jmp walking_no_increment
2022-03-11 05:53:18 +00:00
walking_no_wall:
2022-03-22 04:05:49 +00:00
; y is incremented version
2022-03-11 05:53:18 +00:00
tya
2022-03-22 04:05:49 +00:00
ldy CURRENT_LEMMING
sta lemming_x,Y
2022-03-11 05:53:18 +00:00
2022-03-22 04:05:49 +00:00
walking_no_increment:
2022-03-11 04:02:08 +00:00
2022-03-30 18:46:46 +00:00
; jsr collision_check_ground
2022-03-10 06:10:42 +00:00
2022-03-22 04:05:49 +00:00
walking_done:
2022-03-11 05:53:18 +00:00
jmp done_move_lemming
2022-03-25 01:25:26 +00:00
2022-03-22 04:05:49 +00:00
;=====================
; digging
;=====================
2022-03-10 06:10:42 +00:00
do_lemming_digging:
2022-03-30 18:46:46 +00:00
lda lemming_y,Y ; point to spot below us
2022-03-11 05:53:18 +00:00
clc
adc #9
2022-03-22 04:05:49 +00:00
tax
2022-03-11 05:53:18 +00:00
2022-03-22 04:05:49 +00:00
lda hposn_high,X
2022-03-13 06:28:37 +00:00
clc
2022-03-30 18:46:46 +00:00
adc #$20 ; point to background
2022-03-11 05:53:18 +00:00
sta GBASH
2022-03-22 04:05:49 +00:00
lda hposn_low,X
2022-03-11 05:53:18 +00:00
sta GBASL
2022-03-22 04:05:49 +00:00
lda lemming_x,Y
tay
2022-03-30 18:46:46 +00:00
2022-03-11 05:53:18 +00:00
lda #$0
2022-03-30 18:46:46 +00:00
sta (GBASL),Y ; erase bg
2022-03-11 05:53:18 +00:00
2022-03-30 18:46:46 +00:00
ldx CURRENT_LEMMING ; dig down
2022-03-22 04:05:49 +00:00
inc lemming_y,X
2022-03-11 05:53:18 +00:00
2022-03-27 18:05:47 +00:00
jmp done_move_lemming
2022-03-11 05:53:18 +00:00
2022-03-10 06:10:42 +00:00
2022-03-25 01:25:26 +00:00
;=====================
; mining
;=====================
do_lemming_mining:
lda lemming_y,Y
clc
adc #9
tax
lda hposn_high,X ; set up collision check underfoot
clc
adc #$20
sta GBASH
lda hposn_low,X
sta GBASL
lda lemming_x,Y ; if fell through,then fall
tay
lda (GBASL),Y
and #$7f
beq mining_falling
mining_mining:
ldy CURRENT_LEMMING
lda lemming_frame,Y
and #$f
bne no_mining_this_frame
ldx #0
stx HGR_COLOR
; (X,A) to (X,A+Y) where X is xcoord/7
jsr hgr_box_page_toggle
ldy CURRENT_LEMMING
lda lemming_x,Y
tax
lda lemming_y,Y
ldy #9
jsr hgr_box
jsr hgr_box_page_toggle
ldy CURRENT_LEMMING
lda lemming_x,Y
tax
lda lemming_y,Y
ldy #9
jsr hgr_box
ldx CURRENT_LEMMING
inc lemming_y,X
inc lemming_y,X
inc lemming_y,X
lda lemming_x,X
clc
adc lemming_direction,X
sta lemming_x,X
no_mining_this_frame:
jmp done_mining
mining_falling:
ldy CURRENT_LEMMING
lda #LEMMING_FALLING
sta lemming_status,Y
done_mining:
jmp done_move_lemming
2022-03-30 18:46:46 +00:00
;=====================
; bashing
;=====================
do_lemming_bashing:
.if 0
jsr collide_below
mining_mining:
ldy CURRENT_LEMMING
lda lemming_frame,Y
and #$f
bne no_mining_this_frame
ldx #0
stx HGR_COLOR
; (X,A) to (X,A+Y) where X is xcoord/7
jsr hgr_box_page_toggle
ldy CURRENT_LEMMING
lda lemming_x,Y
tax
lda lemming_y,Y
ldy #9
jsr hgr_box
jsr hgr_box_page_toggle
ldy CURRENT_LEMMING
lda lemming_x,Y
tax
lda lemming_y,Y
ldy #9
jsr hgr_box
ldx CURRENT_LEMMING
inc lemming_y,X
inc lemming_y,X
inc lemming_y,X
lda lemming_x,X
clc
adc lemming_direction,X
sta lemming_x,X
no_mining_this_frame:
jmp done_mining
mining_falling:
ldy CURRENT_LEMMING
lda #LEMMING_FALLING
sta lemming_status,Y
done_mining:
.endif
jmp done_move_lemming
2022-03-25 01:25:26 +00:00
;=====================
2022-03-27 18:05:47 +00:00
; do nothing
2022-03-25 01:25:26 +00:00
;=====================
2022-03-27 18:05:47 +00:00
; placeholders
2022-03-30 18:46:46 +00:00
do_lemming_exploding: ; nothing special
2022-03-27 18:05:47 +00:00
do_lemming_pullup:
do_lemming_shrugging:
2022-03-30 18:46:46 +00:00
do_lemming_stopping: ; nothing special
2022-03-27 18:05:47 +00:00
do_lemming_building:
2022-03-30 18:46:46 +00:00
2022-03-27 18:05:47 +00:00
do_lemming_climbing:
2022-03-30 18:46:46 +00:00
do_lemming_splatting: ; nothing special
do_lemming_particles: ; work done in draw
2022-03-25 01:25:26 +00:00
2022-03-27 18:05:47 +00:00
jmp done_move_lemming
2022-03-25 01:25:26 +00:00
2022-03-11 06:22:51 +00:00
;==========================
; remove lemming from game
2022-03-22 04:05:49 +00:00
;==========================
2022-03-23 01:10:57 +00:00
; Y points to CURRENT_LEMMING
; if C set it means they exited
2022-03-11 06:22:51 +00:00
2022-03-23 01:10:57 +00:00
remove_lemming:
2022-03-22 04:05:49 +00:00
2022-03-23 01:10:57 +00:00
bcc didnt_exit
2022-03-22 04:05:49 +00:00
2022-03-23 01:36:44 +00:00
sed
lda PERCENT_RESCUED_L
clc
adc PERCENT_ADD
sta PERCENT_RESCUED_L
bcc no_percent_oflo
inc PERCENT_RESCUED_H
2022-03-23 04:34:33 +00:00
no_percent_oflo:
2022-03-22 04:05:49 +00:00
cld
2022-03-11 06:22:51 +00:00
2022-03-23 04:34:33 +00:00
jsr update_percent_in
2022-03-23 01:36:44 +00:00
2022-03-23 01:10:57 +00:00
didnt_exit:
2022-03-23 01:36:44 +00:00
sed ; decrement BCD value
lda LEMMINGS_OUT
sec
sbc #1
sta LEMMINGS_OUT
cld
2022-03-23 01:10:57 +00:00
jsr click_speaker
lda #0
2022-03-23 04:34:33 +00:00
ldy CURRENT_LEMMING
2022-03-23 01:10:57 +00:00
sta lemming_out,Y
2022-03-11 06:22:51 +00:00
jsr update_lemmings_out
2022-03-23 01:10:57 +00:00
; if that was the last one, then level over
2022-03-22 04:05:49 +00:00
lda LEMMINGS_OUT
bne not_last_lemming
lda #LEVEL_WIN
sta LEVEL_OVER
not_last_lemming:
2022-03-10 06:10:42 +00:00
rts
2022-03-11 06:22:51 +00:00
2022-03-16 01:00:30 +00:00
2022-03-13 06:28:37 +00:00
;=============================
; collision check ground
;=============================
2022-03-11 04:02:08 +00:00
collision_check_ground:
2022-03-30 18:46:46 +00:00
ldy CURRENT_LEMMING
2022-03-22 04:05:49 +00:00
lda lemming_y,Y
2022-03-11 04:02:08 +00:00
clc
2022-03-30 18:46:46 +00:00
adc #9 ; FIXME: should be 10?
2022-03-22 04:05:49 +00:00
tax
2022-03-11 04:02:08 +00:00
2022-03-22 04:05:49 +00:00
lda hposn_high,X
2022-03-13 06:28:37 +00:00
clc
adc #$20 ; check bg, not fg
2022-03-11 04:02:08 +00:00
sta GBASH
2022-03-22 04:05:49 +00:00
lda hposn_low,X
2022-03-11 04:02:08 +00:00
sta GBASL
2022-03-22 04:05:49 +00:00
lda lemming_x,Y
tay
2022-03-11 04:02:08 +00:00
lda (GBASL),Y
and #$7f
2022-03-18 05:59:15 +00:00
beq ground_falling ; if empty space below us, fall
2022-03-23 01:10:57 +00:00
2022-03-30 18:46:46 +00:00
on_the_ground:
; if we get here we're on the ground
; if we were previously falling/floating we need to do something
; otherwise do nothing
ldy CURRENT_LEMMING
lda lemming_status,Y
cmp #LEMMING_FALLING
beq hit_ground
cmp #LEMMING_FLOATING
beq hit_ground
bne done_check_ground ; could rts here?
hit_ground:
2022-03-23 01:10:57 +00:00
; hit ground walking
ldy CURRENT_LEMMING
lda lemming_fall_distance,Y
2022-03-23 04:34:33 +00:00
cmp #32
2022-03-23 01:10:57 +00:00
bcs lemming_goes_splat
lda #0
sta lemming_fall_distance,Y
2022-03-18 05:59:15 +00:00
lda #LEMMING_WALKING ; else, walk
2022-03-25 01:25:26 +00:00
jmp update_status_check_ground
2022-03-23 01:10:57 +00:00
2022-03-30 18:46:46 +00:00
; nothing beneath us, falling
2022-03-11 04:02:08 +00:00
ground_falling:
2022-03-25 01:25:26 +00:00
ldy CURRENT_LEMMING
lda lemming_status,Y ; if floating, don't go back to fall
cmp #LEMMING_FLOATING
beq done_check_ground
2022-03-11 04:02:08 +00:00
lda #LEMMING_FALLING
2022-03-25 01:25:26 +00:00
update_status_check_ground:
2022-03-22 04:05:49 +00:00
ldy CURRENT_LEMMING
sta lemming_status,Y
2022-03-25 01:25:26 +00:00
done_check_ground:
2022-03-11 04:02:08 +00:00
rts
2022-03-18 05:59:15 +00:00
2022-03-23 01:10:57 +00:00
lemming_goes_splat:
2022-03-24 04:21:50 +00:00
lda #LEMMING_SPLATTING
sta lemming_status,Y
lda #0
sta lemming_frame,Y
; clc
; jsr remove_lemming
2022-03-23 01:10:57 +00:00
rts
2022-03-18 05:59:15 +00:00
;=============================
; collision check hill
;=============================
collision_check_hill:
2022-03-22 04:05:49 +00:00
lda lemming_y,Y
2022-03-18 05:59:15 +00:00
clc
adc #8
2022-03-22 04:05:49 +00:00
tax
2022-03-18 05:59:15 +00:00
2022-03-22 04:05:49 +00:00
lda hposn_high,X
2022-03-18 05:59:15 +00:00
clc
adc #$20 ; check bg, not fg
sta GBASH
2022-03-22 04:05:49 +00:00
lda hposn_low,X
2022-03-18 05:59:15 +00:00
sta GBASL
2022-03-22 04:05:49 +00:00
lda lemming_x,Y
tay
2022-03-18 05:59:15 +00:00
lda (GBASL),Y
and #$7f
beq on_ground ; if empty space below us, good
underground:
2022-03-22 04:05:49 +00:00
ldx CURRENT_LEMMING
dec lemming_y,X ; bump us up
2022-03-18 05:59:15 +00:00
on_ground:
rts
2022-03-22 04:05:49 +00:00
;=============================
; check at exit
;=============================
check_at_exit_xiny:
tya
ldy CURRENT_LEMMING
jmp check_at_exit_y
check_at_exit:
; see if at exit
ldy CURRENT_LEMMING
; check X
lda lemming_x,Y
check_at_exit_y:
exit_x1_smc:
cmp #31
bcc not_done_level
exit_x2_smc:
cmp #35
bcs not_done_level
; check Y
lda lemming_y,Y
exit_y1_smc:
cmp #116
bcc not_done_level
exit_y2_smc:
cmp #127
bcs not_done_level
; done level
2022-03-23 01:10:57 +00:00
sec
2022-03-22 04:05:49 +00:00
jsr remove_lemming
not_done_level:
rts