diff options
author | Astatin <[email protected]> | 2025-01-24 18:08:33 +0900 |
---|---|---|
committer | Astatin <[email protected]> | 2025-01-24 18:08:33 +0900 |
commit | 1a6621e5b1da42ee4b6b9132790ec744efc009c2 (patch) | |
tree | 89aeb457555655d2e4ed74a0fe32bfca74851a26 | |
parent | 57326c9acf9cbb025d54093fb90fd70614659400 (diff) |
Add laser enemy attack
-rw-r--r-- | TODO | 15 | ||||
-rw-r--r-- | animation.gbasm | 19 | ||||
-rw-r--r-- | animations/laser.gbasm | 5 | ||||
-rw-r--r-- | animations/rotatingball.gbasm | 5 | ||||
-rw-r--r-- | animations/sparkles.gbasm | 4 | ||||
-rw-r--r-- | definitions.gbasm | 9 | ||||
-rw-r--r-- | enemiesattacks.gbasm | 1 | ||||
-rw-r--r-- | enemiesattacks/laser.gbasm | 113 | ||||
-rw-r--r-- | enemiesattacks/walk.gbasm | 8 | ||||
-rw-r--r-- | entity/actions.gbasm | 46 | ||||
-rw-r--r-- | entity/bunny.gbasm | 36 | ||||
-rw-r--r-- | main.gbasm | 14 |
12 files changed, 240 insertions, 35 deletions
@@ -1,20 +1,31 @@ +Need to be refactored: + -> AB/BC/XY/YX thingy issue that makes me angry (functions/macro to predict position could be merged after) + -> main is messy and unreadable + -> rework mode checks (heatlh update should happen on both dungeon and dead mode) + -> general structure is messy (why is Update_Animation_Step in entity/action.gbasm ?? What is even entity/action.gbasm supposed to be ??) + -> split fox turn into multiple subfunction that could be reused in other enemies turns functions + -> create an enemy turns thingy directory, move attacks inside of entity/enemies (both enemiesattacks and playerattacks) + -> tiles are duplicated in the tree tilelset and could be reduce to 32 tiles + +Medium term: -> Add special attacks/capacities to the bunny x * Jump x2 (even over an enemy) (attacking or not ?) * Stronger attack x * Weaker attack on multiple foxes x * Freeze a/multiple fox(es) for X turns + * Distance attack (maybe reuse laser of the enemies) -> Limit attacks uses x -> Spawn enemies in far away rooms when less than X enemies on the map. (Maybe despawn some too) - -> Remove some health to the bunny (probably to 10 points, maybe max health growing ?) +? -> Remove some health to the bunny (probably to 10 points, maybe max health growing ?) x -> Add objects to heal -> Add objects get back limited use attacks/learn new attacks - -> Add attacks for the foxes +x -> Add attacks for the foxes x -> Add other types of enemies diff --git a/animation.gbasm b/animation.gbasm index 1307796..7bc997a 100644 --- a/animation.gbasm +++ b/animation.gbasm @@ -1,3 +1,18 @@ +Animation_Wait_Mode: + LD A, $mem_current_mode + CP $enum_animation_wait_mode + RET NZ + + LD A, $mem_animation_wait_frames + DEC A + LD $mem_animation_wait_frames, A + CP $00 + RET NZ + LD A, $enum_dungeon_mode + LD $mem_current_mode, A + LD $mem_requested_mode, A + RET + Display_Animation_List: LD HL, $mem_animation_list CALL =Display_Animation @@ -87,6 +102,10 @@ Animation_Jump_table: JP =Rotating_Ball_Animation NOP + ; 03 + JP =Laser_Animation + NOP + .INCLUDE "animations/sparkles.gbasm" .INCLUDE "animations/rotatingball.gbasm" .INCLUDE "animations/laser.gbasm" diff --git a/animations/laser.gbasm b/animations/laser.gbasm index fba2df4..5c70eaf 100644 --- a/animations/laser.gbasm +++ b/animations/laser.gbasm @@ -100,8 +100,6 @@ Laser_Animation: LD HL, $mem_oam_buffer LD A, $mem_oam_buffer_low LD L, A - ADD $08 - LD $mem_oam_buffer_low, A LD A, C LD (HL+), A @@ -113,6 +111,9 @@ Laser_Animation: LD A, $00 LD (HL+), A + LD A, L + LD $mem_oam_buffer_low, A + POP HL RET diff --git a/animations/rotatingball.gbasm b/animations/rotatingball.gbasm index 2d89cbe..e7e4cbd 100644 --- a/animations/rotatingball.gbasm +++ b/animations/rotatingball.gbasm @@ -67,8 +67,6 @@ Rotating_Ball_Animation: LD HL, $mem_oam_buffer LD A, $mem_oam_buffer_low LD L, A - ADD $08 - LD $mem_oam_buffer_low, A LD A, (DE) ADD C @@ -84,6 +82,9 @@ Rotating_Ball_Animation: LD A, $00 LD (HL+), A + LD A, L + LD $mem_oam_buffer_low, A + POP HL RET diff --git a/animations/sparkles.gbasm b/animations/sparkles.gbasm index 166332c..f91f45c 100644 --- a/animations/sparkles.gbasm +++ b/animations/sparkles.gbasm @@ -55,8 +55,6 @@ Sparkle_Animation: LD HL, $mem_oam_buffer LD A, $mem_oam_buffer_low LD L, A - ADD $08 - LD $mem_oam_buffer_low, A LD D, E SRA D @@ -94,6 +92,8 @@ Sparkle_Animation: LD A, $00 LD (HL+), A + LD A, L + LD $mem_oam_buffer_low, A POP HL RET diff --git a/definitions.gbasm b/definitions.gbasm index 77e2f7a..c293213 100644 --- a/definitions.gbasm +++ b/definitions.gbasm @@ -72,7 +72,8 @@ .DEFINE enum_dungeon_menu_mode $01 .DEFINE enum_dungeon_dialogue_mode $02 .DEFINE enum_loading_mode $03 -.DEFINE enum_dead_mode $0 +.DEFINE enum_dead_mode $04 +.DEFINE enum_animation_wait_mode $05 .DEFINE mem_menu_cursor_position ($c016) .DEFINE mem_last_button_direction ($c017) @@ -98,6 +99,11 @@ .DEFINE mem_bunny_current_room_idx ($c02a) .DEFINE mem_enemies_alive_count ($c02b) +.DEFINE mem_bunny_predicted_x ($c02c) +.DEFINE mem_bunny_predicted_y ($c02d) + +.DEFINE mem_animation_wait_frames ($c02e) + .DEFINE mem_next_free_head_lower_bytes ($c6ff) .DEFINE mem_dungeon_generation_heads $c700 ; Takes the memory from c700 to c717 @@ -175,6 +181,7 @@ ; flags: u8 ; bit 0: speed 2x ; bit 1: shadow mode +; bit 2: end of turn attack mode ; status: u8 ; ; bit 0: whether or not turns should be skipped ; _padding: u56 diff --git a/enemiesattacks.gbasm b/enemiesattacks.gbasm index ce8f5f0..1ab8094 100644 --- a/enemiesattacks.gbasm +++ b/enemiesattacks.gbasm @@ -45,3 +45,4 @@ Check_player_next_to: ; BC = XY of the enemy. D is unchanged. Direction to face .INCLUDE "enemiesattacks/walk.gbasm" .INCLUDE "enemiesattacks/basic.gbasm" +.INCLUDE "enemiesattacks/laser.gbasm" diff --git a/enemiesattacks/laser.gbasm b/enemiesattacks/laser.gbasm new file mode 100644 index 0000000..63aad07 --- /dev/null +++ b/enemiesattacks/laser.gbasm @@ -0,0 +1,113 @@ +Laser_sight_check: ; BC = XY of the enemy. D is unchanged. Direction to face in E (or 0 if not) + LD E, $00 + + ; straight line + distance <= 4 + LD A, $mem_bunny_predicted_x + CP B + JR Z, =.vertical_distance_check + + LD A, $mem_bunny_predicted_y + CP C + RET NZ + + .horizontal_distance_check: + LD A, $mem_bunny_predicted_x + CP B + JR C, =.left + + .right: + SUB $05 + CP B + RET NC + LD E, $enum_direction_right + RET + + .left: + ADD $04 + CP B + RET C + LD E, $enum_direction_left + RET + + .vertical_distance_check: + LD A, $mem_bunny_predicted_y + CP C + JR C, =.up + + .down: + SUB $05 + CP C + RET NC + LD E, $enum_direction_down + RET + + .up: + ADD $04 + CP C + RET C + LD E, $enum_direction_up + RET + +Laser_Attack: ; Direction to face in E. Result in BC (XY), Direction in D + PUSH DE + PUSH BC + + LD A, E + DEC A + AND $03 + SWAP A + SLA A + SLA A + OR $03 ; Laser_Animation + LD D, A + + LD A, C + ADD B + LD B, A + + LD A, $mem_bunny_x + LD C, A + LD A, $mem_bunny_y + ADD C + SUB B + .ABS + SWAP A + LD E, A + + POP BC + LD A, D + CALL =Try_Launch_Animation + + LD A, $enum_animation_wait_mode + LD $mem_requested_mode, A + LD $mem_current_mode, A + LD A, E + SUB $f + LD E, A + LD A, $mem_animation_wait_frames + CP E + JR NC, =.skip_animation_wait_frames_update + + LD A, E + LD $mem_animation_wait_frames, A + + .skip_animation_wait_frames_update: + + LD A, $mem_animation_wait_frames + DBG + + POP DE + + LD A, $mem_bunny_health + SUB $01 + JR C, =.health_underflow_fix + DAA + LD $mem_bunny_health, A + JR =.Skip_health_underflow_fix + + .health_underflow_fix: + LD A, $00 + LD $mem_bunny_health, A + .Skip_health_underflow_fix: + + RET diff --git a/enemiesattacks/walk.gbasm b/enemiesattacks/walk.gbasm index aa66848..9b196e5 100644 --- a/enemiesattacks/walk.gbasm +++ b/enemiesattacks/walk.gbasm @@ -27,10 +27,10 @@ Walking: ; entity XY in BC, Breaks DE JP =.Check_Collision .Follow_bunny: - LD A, $mem_bunny_x + LD A, $mem_bunny_predicted_x LD $tmp_var_1, A - LD A, $mem_bunny_y + LD A, $mem_bunny_predicted_y LD $tmp_var_2, A CALL =RNG_Step @@ -40,10 +40,10 @@ Walking: ; entity XY in BC, Breaks DE CP $00 JR Z, =.skip_invert_axis - LD A, $mem_bunny_y + LD A, $mem_bunny_predicted_y LD $tmp_var_1, A - LD A, $mem_bunny_x + LD A, $mem_bunny_predicted_x LD $tmp_var_2, A LD E, B diff --git a/entity/actions.gbasm b/entity/actions.gbasm index 520eb0a..f97fbc4 100644 --- a/entity/actions.gbasm +++ b/entity/actions.gbasm @@ -74,18 +74,21 @@ Update_Animation_Steps: .update_mode: - LD A, $mem_bunny_health - CP $00 - JR Z =.Dead_mode - LD A, $mem_requested_mode LD $mem_current_mode, A .end: + LD A, $mem_bunny_health + CP $00 + JR Z =.Dead_mode + RET .Dead_mode: + LD A, $20 + LD $mem_bunny_direction, A + LD A, $enum_dead_mode LD $mem_current_mode, A @@ -276,12 +279,20 @@ Fox_Turn: CP $00 JP NZ, =.Start_action_or_movement.end - CALL =Check_player_next_to + ; CALL =Check_player_next_to + CALL =Laser_sight_check LD A, E CP $00 JR Z, =.nyo_basic_attack - CALL =Basic_Attack + ; CALL =Basic_Attack + LD A, L + AND $f0 + ADD $07 + LD L, A + + SET 2, (HL) + JR =.Start_action_or_movement.end .nyo_basic_attack: @@ -296,9 +307,30 @@ Fox_Turn: AND $07 BIT 3, D LD D, A - JR Z, =.End_movement.end + JR Z, =.End_movement.check_end_of_turn_mode_attack LD A, $01 .ADD_A_TO_DIRECTION_BC + + .End_movement.check_end_of_turn_mode_attack: + + LD A, L + AND $f0 + ADD $07 + LD L, A + + BIT 2, (HL) + RES 2, (HL) + JR Z, =.End_movement.end + + CALL =Laser_sight_check + LD A, E + CP $00 + JR Z, =.laser_sight_check_fail + + CALL =Laser_Attack + + .laser_sight_check_fail: + .End_movement.end: .Skip_Turn: diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm index 042f94b..7e9afa5 100644 --- a/entity/bunny.gbasm +++ b/entity/bunny.gbasm @@ -1,14 +1,4 @@ Move_Bunny: - LD A, $mem_bunny_health - CP $00 - JR NZ, =.not_dead - - LD A, $20 - LD $mem_bunny_direction, A - RET - - .not_dead: - LD A, $mem_bunny_flags LD E, $01 BIT 0, A @@ -60,7 +50,7 @@ Move_Bunny: .Start_action_or_movement: LD A, $mem_map_loading_flags BIT 3, A - JR NZ, =.Start_action_or_movement.end + JP NZ, =.Start_action_or_movement.end .Start_action_or_movement.test_movement: @@ -91,6 +81,25 @@ Move_Bunny: LD A, D LD $mem_bunny_direction, A + + BIT 3, D + JR Z, =.Start_action_or_movement.end + + PUSH BC + LD A, B + LD B, C + LD C, A + LD A, $01 + DBG + .ADD_A_TO_DIRECTION_BC + DBG + LD A, B + LD $mem_bunny_predicted_x, A + LD A, C + LD $mem_bunny_predicted_y, A + + POP BC + JR =.Start_action_or_movement.end .Start_action_or_movement.test_action: @@ -225,6 +234,11 @@ Move_Bunny: .End_movement.Update_current_room.end: POP DE + LD A, $mem_bunny_x + LD $mem_bunny_predicted_x, A + LD A, $mem_bunny_y + LD $mem_bunny_predicted_y, A + .End_movement.end: .Middle_movement_doublespeed_viewport_update: @@ -116,10 +116,6 @@ VBLANK_Entrypoint: LD A, $palette_bold_font LD $reg_bg_palette, A - LD HL, $9c00 - LD A, $mem_bunny_health - CALL =Print_8bit - LD HL, $9c12 LD A, $dbg_VBLANK_STATE CALL =Print_8bit @@ -130,6 +126,10 @@ VBLANK_Entrypoint: LD A, $mem_current_mode CP $enum_dungeon_mode JR NZ, =Skip_VBlank_Dungeon_Update + LD HL, $9c00 + LD A, $mem_bunny_health + CALL =Print_8bit + CALL =Display_Prepared_Block CALL =Display_Object Skip_VBlank_Dungeon_Update: @@ -160,9 +160,15 @@ VBLANK_Entrypoint: CALL =Respawn_Entities CALL =Prepare_Scrolling_Map + LD A, $mem_current_mode + LD B, A + LD A, $mem_animation_wait_frames + Skip_Dungeon_Update: + LD A, $mem_current_mode CALL =Loading_Mode_Regular + CALL =Animation_Wait_Mode CALL =Update_Animation_Steps CALL =Check_Open_Menu_button CALL =Move_dialogue_cursor |