dos33fsprogs/games/tfv/tfv_battle.s

615 lines
8.5 KiB
ArmAsm
Raw Normal View History

2021-01-17 21:12:06 +00:00
;
; handle battles
;
2021-01-05 20:32:11 +00:00
;================================
; do battle
;================================
2021-01-04 16:53:13 +00:00
2021-01-05 20:32:11 +00:00
do_battle:
2021-01-04 16:53:13 +00:00
;========================
; rotate intro
; this happens first as it stomps on zero page
jsr rotate_intro
2021-01-18 20:49:02 +00:00
; set start position
2021-01-11 20:20:43 +00:00
lda #34
sta HERO_X
2021-01-17 21:12:06 +00:00
lda #20
sta HERO_Y
2021-01-12 05:44:03 +00:00
2021-01-18 20:49:02 +00:00
; reset state
2021-01-11 20:20:43 +00:00
lda #0
sta BATTLE_STATE
2021-01-12 05:44:03 +00:00
sta MENU_STATE
sta MENU_POSITION
2021-01-18 20:49:02 +00:00
sta ENEMY_DEAD
2021-01-19 05:32:10 +00:00
sta ENEMY_ATTACKING
sta QUEUED_ATTACK
2021-01-11 20:20:43 +00:00
2021-01-18 20:49:02 +00:00
; start battle count part-way in
2021-01-12 05:44:03 +00:00
lda #20
sta BATTLE_COUNT
2021-01-04 16:53:13 +00:00
2021-01-18 05:52:12 +00:00
;======================
; update hp and mp
jsr update_hero_hp_menu
jsr update_hero_mp_menu
2021-02-07 20:13:07 +00:00
;=============
2021-01-19 19:39:37 +00:00
; start music
lda SOUND_STATUS
and #SOUND_MOCKINGBOARD
beq no_mockingboard
2021-01-19 21:27:24 +00:00
jsr music_load_fighting
2021-01-19 19:39:37 +00:00
jsr pt3_init_song
cli
no_mockingboard:
2021-01-17 21:12:06 +00:00
;========================
; zoom to battlefield
2021-01-19 18:51:00 +00:00
lda #0
sta ANIMATE_LOOP
battlefield_zoom_loop:
2021-01-17 21:12:06 +00:00
2021-01-19 18:51:00 +00:00
lda ANIMATE_LOOP
asl
tay
lda plains_animation,Y ; lda #<(plains_battle)
sta getsrc_smc+1
lda plains_animation+1,Y ; lda #>(plains_battle)
sta getsrc_smc+2
2021-01-05 20:32:11 +00:00
2021-01-19 18:51:00 +00:00
lda #$c
2021-01-05 20:32:11 +00:00
2021-01-19 18:51:00 +00:00
jsr decompress_lzsa2_fast
2021-01-05 20:32:11 +00:00
2021-01-19 18:51:00 +00:00
jsr gr_copy_to_current
2021-01-05 20:32:11 +00:00
2021-01-19 19:02:55 +00:00
; sorta zoom in the hero
; 8 -> 38,28
; 9 -> 36,24
; 10 -> 34,20
lda ANIMATE_LOOP
cmp #8
bcc battlefield_zoom_done_hero
sec
sbc #8
tay
lda hero_zoom_x,Y
sta HERO_X
lda hero_zoom_y,Y
sta HERO_Y
jsr draw_hero_and_sword
battlefield_zoom_done_hero:
; zoom in enemy too? trickier
2021-01-19 18:51:00 +00:00
jsr page_flip
2021-01-11 20:20:43 +00:00
2021-01-19 19:02:55 +00:00
lda #240
2021-01-19 18:51:00 +00:00
jsr WAIT
2021-01-11 20:20:43 +00:00
2021-01-19 18:51:00 +00:00
inc ANIMATE_LOOP
lda ANIMATE_LOOP
cmp #11
bne battlefield_zoom_loop
2021-01-11 20:20:43 +00:00
2021-01-19 18:51:00 +00:00
;=============================
; Init Enemy
jsr init_enemy
;==========================
; Draw background
; jsr draw_battle_background
2021-01-05 20:32:11 +00:00
2021-01-12 05:44:03 +00:00
; update bottom of screen
2021-01-11 20:20:43 +00:00
jsr draw_battle_bottom
2021-01-05 20:32:11 +00:00
2021-01-17 21:12:06 +00:00
;========================================
; main battle loop
;========================================
2021-01-11 20:20:43 +00:00
main_battle_loop:
2021-01-05 20:32:11 +00:00
2021-01-17 21:12:06 +00:00
;============================
; copy background into place
2021-01-11 20:20:43 +00:00
jsr gr_copy_to_current
2021-01-05 20:32:11 +00:00
2021-01-11 20:20:43 +00:00
;========================================
; draw our hero
2021-01-05 20:32:11 +00:00
; check if hero deal
lda HERO_HP_HI
bne hero_not_dead ; hitpoint hi not zero
lda HERO_HP_LO
beq battle_draw_hero_down ; hitpoint hi && lo zero
; not dead, so draw running or standing
hero_not_dead:
lda BATTLE_STATE
and #BATTLE_STATE_RUNNING
2021-01-11 20:20:43 +00:00
bne battle_draw_hero_running
jmp battle_draw_normal_hero
2021-01-05 20:32:11 +00:00
2021-01-11 20:20:43 +00:00
battle_draw_hero_down:
2021-01-05 20:32:11 +00:00
2021-01-17 21:12:06 +00:00
jsr draw_hero_down
2021-01-13 20:17:15 +00:00
jmp battle_done_draw_hero
2021-01-11 20:20:43 +00:00
battle_draw_hero_running:
; grsim_put_sprite(tfv_stand_right,ax,20);
; grsim_put_sprite(tfv_walk_right,ax,20);
lda HERO_X
sta XPOS
lda #20
sta YPOS
2021-01-13 05:43:21 +00:00
lda BATTLE_COUNT
2021-01-11 20:20:43 +00:00
and #$8
beq battle_draw_running_walk
battle_draw_running_stand:
lda #<tfv_stand_right_sprite
sta INL
lda #>tfv_stand_right_sprite
2021-01-13 20:17:15 +00:00
sta INH
jsr put_sprite_crop
jmp battle_done_draw_hero
2021-01-11 20:20:43 +00:00
battle_draw_running_walk:
lda #<tfv_walk_right_sprite
sta INL
lda #>tfv_walk_right_sprite
2021-01-12 05:44:03 +00:00
sta INH
jsr put_sprite_crop
2021-01-13 20:17:15 +00:00
jmp battle_done_draw_hero
2021-01-11 20:20:43 +00:00
2021-01-13 20:17:15 +00:00
battle_draw_normal_hero:
; grsim_put_sprite(tfv_stand_left,ax,20);
2021-01-11 20:20:43 +00:00
2021-01-15 04:26:24 +00:00
lda #20
sta HERO_Y
2021-01-19 04:35:44 +00:00
jsr draw_battle_hero_and_sword
2021-01-11 20:20:43 +00:00
battle_done_draw_hero:
2021-01-05 20:32:11 +00:00
2021-01-12 05:44:03 +00:00
;===========================
; draw enemy
battle_draw_enemy:
2021-01-05 20:32:11 +00:00
2021-01-12 05:44:03 +00:00
; grsim_put_sprite(enemies[enemy_type].sprite,enemy_x,20);
2021-01-11 20:20:43 +00:00
2021-01-12 05:44:03 +00:00
lda ENEMY_X
sta XPOS
lda #20
sta YPOS
2021-01-13 17:16:20 +00:00
jsr draw_enemy
2021-01-05 20:32:11 +00:00
2021-01-12 05:44:03 +00:00
battle_done_draw_enemy:
2021-01-05 20:32:11 +00:00
2021-01-12 05:44:03 +00:00
;=======================================
; draw bottom status
jsr draw_battle_bottom
;=======================================
; page_flip
jsr page_flip
2021-01-04 16:53:13 +00:00
2021-01-17 21:12:06 +00:00
;=======================================
; handle if dead
2021-01-04 16:53:13 +00:00
lda HERO_HP_HI
bne done_battle_handle_dead
lda HERO_HP_LO
2021-01-17 21:12:06 +00:00
bne done_battle_handle_dead
; pause for 1.5s
ldx #15
jsr long_wait
jsr battle_game_over
done_battle_handle_dead:
2021-01-11 20:20:43 +00:00
2021-01-12 05:44:03 +00:00
;=======================
; handle keypresses
2021-01-11 20:20:43 +00:00
jsr get_keypress
2021-01-12 05:44:03 +00:00
sta LAST_KEY
2021-01-11 20:20:43 +00:00
cmp #'Q'
bne not_quit
jmp done_battle
2021-01-11 20:20:43 +00:00
not_quit:
2021-01-17 21:12:06 +00:00
;========================================
; delay for framerate
2021-01-19 05:32:10 +00:00
lda #50
2021-01-18 20:49:02 +00:00
jsr WAIT
2021-01-17 21:12:06 +00:00
2021-01-12 05:44:03 +00:00
;========================
; handle enemy attacks
2021-01-04 16:53:13 +00:00
2021-01-19 05:32:10 +00:00
lda ENEMY_DEAD
bne battle_done_enemy_attack
2021-01-12 05:44:03 +00:00
lda ENEMY_COUNT
bne battle_no_enemy_attack
battle_start_enemy_attack:
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
; attack and decrement HP
jsr enemy_attack
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
battle_no_enemy_attack:
2021-01-04 16:53:13 +00:00
2021-01-19 05:32:10 +00:00
dec ENEMY_COUNT ; countdown until attack
battle_done_enemy_attack:
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
;===============================
; handle battle counter
update_battle_counter:
lda BATTLE_COUNT
cmp #64
bcc inc_battle_count ; blt
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
; battle timer expired, take action
; If running, escape
2021-01-17 21:12:06 +00:00
; TODO: randomly fail at running?
lda BATTLE_STATE
and #BATTLE_STATE_RUNNING
2021-01-17 21:12:06 +00:00
beq battle_open_menu
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
; we bravely ran away
jmp done_battle
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
2021-01-17 21:12:06 +00:00
;======================
2021-01-12 05:44:03 +00:00
; activate menu
2021-01-17 21:12:06 +00:00
battle_open_menu:
2021-01-12 05:44:03 +00:00
lda MENU_STATE
cmp #MENU_NONE
bne menu_activated
; move to main menu
lda #MENU_MAIN
sta MENU_STATE
2021-01-17 21:12:06 +00:00
jsr menu_ready_noise
2021-01-12 05:44:03 +00:00
menu_activated:
jsr battle_menu_keypress
jmp done_battle_count
inc_battle_count:
inc BATTLE_COUNT
done_battle_count:
;========================
; check enemy defeated
2021-01-18 20:49:02 +00:00
; if enemy_hp zero and enemy dead < 10
lda ENEMY_DEAD
beq battle_enemy_is_not_dead_yet
battle_enemy_is_dead:
inc ENEMY_DEAD
lda ENEMY_DEAD
cmp #15
bne end_check_enemy_dead
2021-01-18 20:49:02 +00:00
jsr victory_dance
jmp done_battle
battle_enemy_is_not_dead_yet:
lda ENEMY_HP_HI
bne end_check_enemy_dead
lda ENEMY_HP_LO
bne end_check_enemy_dead
2021-01-12 05:44:03 +00:00
2021-01-18 20:49:02 +00:00
; make enemy dead
inc ENEMY_DEAD
2021-01-12 05:44:03 +00:00
end_check_enemy_dead:
;====================
; run queued attack
lda QUEUED_ATTACK
beq end_queued_attack
cmp #QUEUED_DO_ATTACK
beq queued_attack_action
cmp #QUEUED_DO_MAGIC
beq queued_magic_action
cmp #QUEUED_DO_LIMIT
beq queued_limit_action
cmp #QUEUED_DO_SUMMON
beq queued_summon_action
jmp end_queued_attack
queued_attack_action:
lda #0
sta MENU_STATE
; attack and decrement HP
jsr attack
jsr done_attack
jmp done_queued_attack
queued_magic_action:
lda #0
sta MENU_STATE
jsr magic_attack
jsr done_attack
jmp done_queued_attack
queued_limit_action:
lda #0
sta MENU_STATE
jsr limit_break
jsr done_attack
jmp done_queued_attack
queued_summon_action:
lda #0
sta MENU_STATE
jsr summon
jsr done_attack
jmp done_queued_attack
done_queued_attack:
lda #0
sta QUEUED_ATTACK
end_queued_attack:
2021-01-12 05:44:03 +00:00
end_battle_loop:
2021-01-04 16:53:13 +00:00
2021-01-11 20:20:43 +00:00
jmp main_battle_loop
2021-01-05 20:32:11 +00:00
2021-01-11 20:20:43 +00:00
done_battle:
jsr clear_bottoms
2021-01-19 19:39:37 +00:00
; disable music
lda SOUND_STATUS
and #SOUND_MOCKINGBOARD
beq no_mockingboard_end
sei
jsr clear_ay_both
no_mockingboard_end:
2021-01-17 21:12:06 +00:00
rts
2021-01-05 20:32:11 +00:00
2021-01-17 21:12:06 +00:00
battle_game_over:
2021-01-05 20:32:11 +00:00
rts
2021-01-17 20:34:23 +00:00
2021-01-17 21:12:06 +00:00
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
2021-01-12 05:44:03 +00:00
;====================================
; victory dance
;====================================
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
victory_dance:
2021-01-19 21:27:24 +00:00
; start music
lda SOUND_STATUS
and #SOUND_MOCKINGBOARD
beq no_mockingboard_victory
sei
jsr clear_ay_both
jsr music_load_victory
jsr pt3_init_song
cli
no_mockingboard_victory:
2021-01-13 17:45:24 +00:00
lda #34
sta HERO_X
2021-01-16 17:58:30 +00:00
lda #20
sta HERO_Y
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
; update XP and money
inc HERO_XP
inc HERO_XP
inc HERO_MONEY
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
ldx #25
stx ANIMATE_LOOP
victory_dance_loop:
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
jsr gr_copy_to_current
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
jsr clear_bottom
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
lda #<victory_string
sta OUTL
lda #>victory_string
sta OUTH
jsr move_and_print
jsr move_and_print
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
txa
and #1
beq victory_wave
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
victory_stand:
2021-01-04 16:53:13 +00:00
2021-01-16 17:58:30 +00:00
jsr draw_hero_and_sword
2021-01-13 17:45:24 +00:00
jmp victory_draw_done
victory_wave:
2021-01-16 17:58:30 +00:00
jsr draw_hero_victory
2021-01-13 17:45:24 +00:00
victory_draw_done:
jsr page_flip
; delay
lda #255
jsr WAIT
2021-01-04 16:53:13 +00:00
2021-01-13 17:45:24 +00:00
dec ANIMATE_LOOP
bne victory_dance_loop
2021-01-04 16:53:13 +00:00
2021-01-12 05:44:03 +00:00
rts
2021-01-04 16:53:13 +00:00
2021-01-13 05:43:21 +00:00
2021-01-18 04:48:12 +00:00
victory_string:
.byte 13,21,"EXPERIENCE +2",0
.byte 16,22,"MONEY +1",0
2021-01-19 18:51:00 +00:00
.if 0
;==========================
;==========================
; Draw battle background
;==========================
;==========================
draw_battle_background:
;==========================
; Draw sky
ldx #0 ; blue from 0 .. 10
battle_sky_loop:
lda gr_offsets,X
sta GBASL
lda gr_offsets+1,X
clc
adc #$8 ; store to $C00
sta GBASH
lda #$66 ; COLOR_MEDIUMBLUE
ldy #0
battle_sky_inner:
sta (GBASL),Y
iny
cpy #40
bne battle_sky_inner
inx
inx
cpx #10
bne battle_sky_loop
; green from 10 .. 40
battle_ground_loop:
lda gr_offsets,X
sta GBASL
lda gr_offsets+1,X
clc
adc #$8 ; store to $C00
sta GBASH
lda #$CC ; COLOR_LIGHTGREEN
; FIXME: should be GROUNDCOLOR
ldy #0
battle_ground_inner:
sta (GBASL),Y
iny
cpy #40
bne battle_ground_inner
inx
inx
cpx #40
bne battle_ground_loop
; Draw some background images for variety?
rts
.endif
plains_animation:
.word plains_anim01
.word plains_anim02
.word plains_anim03
.word plains_anim04
.word plains_anim05
.word plains_anim06
.word plains_anim07
.word plains_anim08
.word plains_anim09
.word plains_anim10
.word plains_battle
2021-01-19 19:02:55 +00:00
; 8 -> 38,28
; 9 -> 36,24
; 10 -> 34,20
hero_zoom_x:
.byte 38,36,34
hero_zoom_y:
.byte 28,24,20