From 403cd5a3b463843b732115783151da0445ed4e1b Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 17 Jan 2021 15:34:23 -0500 Subject: [PATCH] tfv: split enemy code off battle --- games/tfv/Makefile | 2 +- games/tfv/tfv_battle.s | 302 ----------------------------------- games/tfv/tfv_battle_enemy.s | 272 +++++++++++++++++++++++++++++++ games/tfv/tfv_battle_menu.s | 23 +++ games/tfv/tfv_world.s | 1 + 5 files changed, 297 insertions(+), 303 deletions(-) create mode 100644 games/tfv/tfv_battle_enemy.s diff --git a/games/tfv/Makefile b/games/tfv/Makefile index 0f8f5999..b00dafef 100644 --- a/games/tfv/Makefile +++ b/games/tfv/Makefile @@ -77,7 +77,7 @@ TFV_WORLD: tfv_world.o tfv_world.o: tfv_world.s zp.inc \ tfv_overworld.s tfv_drawmap.s \ tfv_battle.s tfv_battle_menu.s tfv_battle_limit.s tfv_battle_summons.s \ - tfv_battle_magic.s \ + tfv_battle_magic.s tfv_battle_enemy.s \ tfv_battle_boss.s \ help_overworld.s rotate_intro.s \ sound_effects.s speaker_tone.s \ diff --git a/games/tfv/tfv_battle.s b/games/tfv/tfv_battle.s index 4ebfb15f..b41fadfd 100644 --- a/games/tfv/tfv_battle.s +++ b/games/tfv/tfv_battle.s @@ -292,191 +292,13 @@ done_battle: rts -; Metrocat (summon?) -; Environment: grass, beach, forest, ice - -; Enemies: HP ATTACK WEAKNESS RESIST -; Killer Crab RND-32 PINCH MALAISE FIRE -; Plain Fish BUBBLE FIRE ICE - -; Evil Tree RND-16 LEAVE FIRE ICE -; Wood Elf SING MALAISE BOLT - -; Giant Bee RND-64 BUZZSAW ICE NONE -; Procrastinon RND-32 PUTOFF NONE MALAISE - -; Ice Fish RND-32 AUGER FIRE ICE -; EvilPenguin WADDLE FIRE ICE - -; Battle. -; Forest? Grassland? Artic? Ocean? -; ATTACK REST -; MAGIC LIMIT -; SUMMON RUN -; -; SUMMONS -> METROCAT VORTEXCN -; MAGIC -> HEAL FIRE -; ICE MALAISE -; BOLT -; LIMIT -> SLICE ZAP -; DROP -; -; 1 2 3 -;0123456789012345678901234567890123456789| -;----------------------------------------| -; | HP LIMIT | -> FIGHT/LIMIT 21 -;KILLER CRAB | DEATER 128/255 128 | ZAP 22 -; | | REST 23 -; | | RUN AWAY 24 -; -;Sound effects? -; -;List hits -; ;****** ** **** **** ** ** ****** **** ****** ****** ****** ;** ** **** ** ** ** ** ** ** ** ** ** ** ** ;** ** ** **** **** ****** **** ****** ** ****** ****** ;** ** ** ** ** ** ** ** ** ** ** ** ** ;****** ****** ****** **** ** **** ****** ** ****** ** -; Background depend on map location? -; Room for guinea pig in party? - -; Attacks -> HIT, ZAP, HEAL, RUNAWAY -;#define MAGIC_NONE 0 -;#define MAGIC_FIRE 1 -;#define MAGIC_ICE 2 -;#define MAGIC_MALAISE 4 -;#define MAGIC_BOLT 8 -;#define MAGIC_HEAL 16 - -; struct enemy_type { -; char *name; -; int hp_base,hp_mask; -; char *attack_name; -; int weakness,resist; -; unsigned char *sprite; -;}; - - - ;============================= - ; Init Enemy - ;============================= -init_enemy: - - ; select type - - ; random, with weight toward proper terrain - ; 50% completely random, 50% terrain based? - - ; enemy_type=random_8()%0x7; -; enemy_hp=enemies[enemy_type].hp_base+ -; (rand()&enemies[enemy_type].hp_mask); - - lda #0 ; hardcode crab for now - sta ENEMY_TYPE - sta ENEMY_X - - lda #$30 ; BCD - sta ENEMY_HP - - lda #30 - sta ENEMY_COUNT - - lda #killer_crab_sprite - sta draw_enemy_smc2+1 - - rts - - -;static struct enemy_type enemies[9]={ -; [0]= { -; .name="Killer Crab", -; .hp_base=50, -; .hp_mask=0x1f, -; .attack_name="Pinch", -; .weakness=MAGIC_MALAISE, -; .resist=MAGIC_FIRE, -; .sprite=killer_crab, -; }, -; [1]= { -; .name="Plain Fish", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Bubble", -; .weakness=MAGIC_FIRE, -; .resist=MAGIC_ICE, -; .sprite=plain_fish, -; }, -; [2]= { -; .name="Evil Tree", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Leaves", -; .weakness=MAGIC_FIRE, -; .resist=MAGIC_ICE, -; .sprite=evil_tree, -; }, -; [3]= { -; .name="Wood Elf", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Song", -; .weakness=MAGIC_MALAISE, -; .resist=MAGIC_BOLT|MAGIC_HEAL, -; .sprite=wood_elf, -; }, -; [4]= { -; .name="Giant Bee", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Buzzsaw", -; .weakness=MAGIC_ICE, -; .resist=MAGIC_NONE, -; .sprite=giant_bee, -; }, -; [5]= { -; .name="Procrastinon", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Putoff", -; .weakness=MAGIC_NONE, -; .resist=MAGIC_MALAISE, -; .sprite=procrastinon, -; }, -; [6]= { -; .name="Ice Fish", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Auger", -; .weakness=MAGIC_FIRE, -; .resist=MAGIC_ICE, -; .sprite=ice_fish, -; }, -; [7]= { -; .name="Evil Penguin", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="Waddle", -; .weakness=MAGIC_FIRE, -; .resist=MAGIC_ICE, -; .sprite=evil_penguin, -; }, -; [8]= { -; .name="Act.Principl", -; .hp_base=10, -; .hp_mask=0x1f, -; .attack_name="BIRDIE", -; .weakness=MAGIC_NONE, -; .resist=MAGIC_ICE|MAGIC_FIRE, -; .sprite=roboknee1, -; }, -;}; - - ;=========================== ; gr put num ;=========================== @@ -537,64 +359,9 @@ gr_put_num_ones: rts -; -; ATTACK SKIP -; MAGIC LIMIT -; SUMMON ESCAPE -; -; SUMMONS -> METROCAT VORTEXCN -; MAGIC -> HEAL FIRE -; ICE MALAISE -; BOLT -; LIMIT -> SLICE ZAP -; DROP -; -; State Machine -; -; time -; BOTTOM -------> MAIN_MENU ----->ATTACK -; ------->SKIP -; ------->MAGIC_MENU -; ------->LIMIT_MENU -; ------->SUMMON_MENU -; ------->ESCAPE -; -; - -; static int enemy_attacking=0; - - - ;========================= - ; damage enemy - ;========================= - ; amount to damage in DAMAGE_VAL -damage_enemy: - lda DAMAGE_VAL - cmp ENEMY_HP - bcs damage_enemy_too_much ; bge - - ; enemy hp is BCD - sed - - sec - lda ENEMY_HP - sbc DAMAGE_VAL - - cld - - jmp damage_enemy_update - -damage_enemy_too_much: - lda #0 - -damage_enemy_update: - sta ENEMY_HP - - rts - ;=================== ; heal self ;=================== @@ -757,58 +524,6 @@ attack_actually_draw: rts - ;=============================== - ; enemy attack - ;=============================== -enemy_attack: - -; int ax=enemy_x; -; int damage=10; - -; enemy_attacking=1; - -; while(ax<30) { - - ; put attack name on - ; occasionally attack with that enemy's power? - ; occasionally heal self? - -; gr_copy_to_current(0xc00); - - ; draw first so behind enemy -; grsim_put_sprite(tfv_stand_left,tfv_x,20); -; grsim_put_sprite(tfv_led_sword,tfv_x-5,20); - -; if (ax&1) { -; grsim_put_sprite(enemies[enemy_type].sprite,ax,20); -; } -; else { -; grsim_put_sprite(enemies[enemy_type].sprite,ax,20); -; } - -; draw_battle_bottom(enemy_type); - -; page_flip(); - -; ax+=1; - -; usleep(20000); -; } -; enemy_attacking=0; - -; damage_tfv(damage); -; gr_put_num(25,10,damage); -; draw_battle_bottom(enemy_type); - -; page_flip(); -; usleep(250000); - -; return damage; -;} - - rts - - victory_string: .byte 13,21,"EXPERIENCE +2",0 .byte 16,22,"MONEY +1",0 @@ -891,23 +606,6 @@ done_attack: - ;================================ - ; draw enemy - ; relies on self-modifying code - ; position in XPOS,YPOS - -draw_enemy: - -draw_enemy_smc1: - lda #$a5 - sta INL -draw_enemy_smc2: - lda #$a5 - -battle_actual_draw_enemy: - sta INH - jmp put_sprite_crop ; tail call - ;============================ diff --git a/games/tfv/tfv_battle_enemy.s b/games/tfv/tfv_battle_enemy.s new file mode 100644 index 00000000..963d653c --- /dev/null +++ b/games/tfv/tfv_battle_enemy.s @@ -0,0 +1,272 @@ + +; Environment: grass, beach, forest, ice + +; Enemies: HP ATTACK WEAKNESS RESIST +; Killer Crab RND-32 PINCH MALAISE FIRE +; Plain Fish BUBBLE FIRE ICE + +; Evil Tree RND-16 LEAVE FIRE ICE +; Wood Elf SING MALAISE BOLT + +; Giant Bee RND-64 BUZZSAW ICE NONE +; Procrastinon RND-32 PUTOFF NONE MALAISE + +; Ice Fish RND-32 AUGER FIRE ICE +; EvilPenguin WADDLE FIRE ICE + +; Battle. +; Forest? Grassland? Artic? Ocean? +; ATTACK REST +; MAGIC LIMIT +; SUMMON RUN +; +; SUMMONS -> METROCAT VORTEXCN +; MAGIC -> HEAL FIRE +; ICE MALAISE +; BOLT +; LIMIT -> SLICE ZAP +; DROP +; +; 1 2 3 +;0123456789012345678901234567890123456789| +;----------------------------------------| +; | HP LIMIT | -> FIGHT/LIMIT 21 +;KILLER CRAB | DEATER 128/255 128 | ZAP 22 +; | | REST 23 +; | | RUN AWAY 24 +; + +; struct enemy_type { +; char *name; +; int hp_base,hp_mask; +; char *attack_name; +; int weakness,resist; +; unsigned char *sprite; +;}; + + + ;============================= + ; Init Enemy + ;============================= +init_enemy: + + ; select type + + ; random, with weight toward proper terrain + ; 50% completely random, 50% terrain based? + + ; enemy_type=random_8()%0x7; +; enemy_hp=enemies[enemy_type].hp_base+ +; (rand()&enemies[enemy_type].hp_mask); + + lda #0 ; hardcode crab for now + sta ENEMY_TYPE + sta ENEMY_X + + lda #$30 ; BCD + sta ENEMY_HP + + lda #30 + sta ENEMY_COUNT + + lda #killer_crab_sprite + sta draw_enemy_smc2+1 + + rts + + +;static struct enemy_type enemies[9]={ +; [0]= { +; .name="Killer Crab", +; .hp_base=50, +; .hp_mask=0x1f, +; .attack_name="Pinch", +; .weakness=MAGIC_MALAISE, +; .resist=MAGIC_FIRE, +; .sprite=killer_crab, +; }, +; [1]= { +; .name="Plain Fish", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Bubble", +; .weakness=MAGIC_FIRE, +; .resist=MAGIC_ICE, +; .sprite=plain_fish, +; }, +; [2]= { +; .name="Evil Tree", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Leaves", +; .weakness=MAGIC_FIRE, +; .resist=MAGIC_ICE, +; .sprite=evil_tree, +; }, +; [3]= { +; .name="Wood Elf", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Song", +; .weakness=MAGIC_MALAISE, +; .resist=MAGIC_BOLT|MAGIC_HEAL, +; .sprite=wood_elf, +; }, +; [4]= { +; .name="Giant Bee", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Buzzsaw", +; .weakness=MAGIC_ICE, +; .resist=MAGIC_NONE, +; .sprite=giant_bee, +; }, +; [5]= { +; .name="Procrastinon", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Putoff", +; .weakness=MAGIC_NONE, +; .resist=MAGIC_MALAISE, +; .sprite=procrastinon, +; }, +; [6]= { +; .name="Ice Fish", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Auger", +; .weakness=MAGIC_FIRE, +; .resist=MAGIC_ICE, +; .sprite=ice_fish, +; }, +; [7]= { +; .name="Evil Penguin", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="Waddle", +; .weakness=MAGIC_FIRE, +; .resist=MAGIC_ICE, +; .sprite=evil_penguin, +; }, +; [8]= { +; .name="Act.Principl", +; .hp_base=10, +; .hp_mask=0x1f, +; .attack_name="BIRDIE", +; .weakness=MAGIC_NONE, +; .resist=MAGIC_ICE|MAGIC_FIRE, +; .sprite=roboknee1, +; }, +;}; + + + ;========================= + ; damage enemy + ;========================= + ; amount to damage in DAMAGE_VAL +damage_enemy: + lda DAMAGE_VAL + cmp ENEMY_HP + bcs damage_enemy_too_much ; bge + + ; enemy hp is BCD + sed + + sec + lda ENEMY_HP + sbc DAMAGE_VAL + + cld + + jmp damage_enemy_update + +damage_enemy_too_much: + lda #0 + +damage_enemy_update: + sta ENEMY_HP + + rts + + + + + ;=============================== + ; enemy attack + ;=============================== +enemy_attack: + +; int ax=enemy_x; +; int damage=10; + +; enemy_attacking=1; + +; while(ax<30) { + + ; put attack name on + ; occasionally attack with that enemy's power? + ; occasionally heal self? + +; gr_copy_to_current(0xc00); + + ; draw first so behind enemy +; grsim_put_sprite(tfv_stand_left,tfv_x,20); +; grsim_put_sprite(tfv_led_sword,tfv_x-5,20); + +; if (ax&1) { +; grsim_put_sprite(enemies[enemy_type].sprite,ax,20); +; } +; else { +; grsim_put_sprite(enemies[enemy_type].sprite,ax,20); +; } + +; draw_battle_bottom(enemy_type); + +; page_flip(); + +; ax+=1; + +; usleep(20000); +; } +; enemy_attacking=0; + +; damage_tfv(damage); +; gr_put_num(25,10,damage); +; draw_battle_bottom(enemy_type); + +; page_flip(); +; usleep(250000); + +; return damage; +;} + + rts + + + + + ;================================ + ; draw enemy + ; relies on self-modifying code + ; position in XPOS,YPOS + +draw_enemy: + +draw_enemy_smc1: + lda #$a5 + sta INL +draw_enemy_smc2: + lda #$a5 + +battle_actual_draw_enemy: + sta INH + jmp put_sprite_crop ; tail call + + + + + + + diff --git a/games/tfv/tfv_battle_menu.s b/games/tfv/tfv_battle_menu.s index ed4ba1b4..6c640724 100644 --- a/games/tfv/tfv_battle_menu.s +++ b/games/tfv/tfv_battle_menu.s @@ -675,3 +675,26 @@ battle_menu_limit: .byte 24,21,"SLICE",0 ; 0 .byte 24,22,"DROP",0 ; 2 .byte 31,21,"ZAP",0 ; 1 +; +; ATTACK SKIP +; MAGIC LIMIT +; SUMMON ESCAPE +; +; SUMMONS -> METROCAT VORTEXCN +; MAGIC -> HEAL FIRE +; ICE MALAISE +; BOLT +; LIMIT -> SLICE ZAP +; DROP +; +; State Machine +; +; time +; BOTTOM -------> MAIN_MENU ----->ATTACK +; ------->SKIP +; ------->MAGIC_MENU +; ------->LIMIT_MENU +; ------->SUMMON_MENU +; ------->ESCAPE +; +; diff --git a/games/tfv/tfv_world.s b/games/tfv/tfv_world.s index ffb6ba63..5fac8dc7 100644 --- a/games/tfv/tfv_world.s +++ b/games/tfv/tfv_world.s @@ -59,6 +59,7 @@ .include "tfv_battle.s" .include "tfv_battle_menu.s" +.include "tfv_battle_enemy.s" .include "tfv_battle_magic.s" .include "tfv_battle_limit.s" .include "tfv_battle_summons.s"