aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-09-26 20:17:33 +0900
committerAstatin <astatin@redacted>2024-09-26 20:17:33 +0900
commit6f0a76fccce2bd8cbe74975623b28f0201b2610a (patch)
tree78c971a170c51e8ef922c310afc3f003f802e882
parent46947d48fe295a0a1a8d243ca6793f59ce3019c1 (diff)
[WIP and completely broken] Reworking the bunny movements & display to decorelate the bunny from moving animation
-rw-r--r--Makefile2
-rw-r--r--definitions.gbasm1
-rw-r--r--entity/actions.gbasm29
-rw-r--r--entity/bunny.gbasm290
-rw-r--r--entity/display.gbasm81
-rw-r--r--entity/init.gbasm8
-rw-r--r--entity/utils.gbasm43
-rw-r--r--main.gbasm5
-rw-r--r--utils.gbasm8
9 files changed, 294 insertions, 173 deletions
diff --git a/Makefile b/Makefile
index 525d037..002e53b 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ build/main.rom: main.gbasm tileset.gbasm
gbasm $< $@
run: build/main.rom
- gb -s 2 $<
+ gb $<
sameboy: build/main.rom
sameboy build/main.rom
diff --git a/definitions.gbasm b/definitions.gbasm
index ac77344..1ada5a8 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -29,6 +29,7 @@
; bit 0: if the object should be reloaded (scroll or first load)
; bit 1: has a movement ended (objects interaction should be checked, entities should update their positions)
; bit 2: if the prepared block should be updated at the next frame
+; bit 3: animation step is going up (?)
.DEFINE mem_prepared_block_tile ($c00d)
.DEFINE mem_prepared_block_position_1 ($c00e)
diff --git a/entity/actions.gbasm b/entity/actions.gbasm
index c39781e..4dafb04 100644
--- a/entity/actions.gbasm
+++ b/entity/actions.gbasm
@@ -56,6 +56,27 @@ Entity_Action:
LD L, A
RET
+Update_Animation_Steps:
+ LD A, $mem_map_loading_flags
+ BIT 3, A
+ JR Z, =Update_Animation_Steps.end:
+
+ LD A, $mem_moving_animation_step
+ INC A
+ AND $0f
+ LD $mem_moving_animation_step, A
+
+ CP $00
+ JR NZ, =Update_Animation_Steps.end
+
+ LD A, $mem_map_loading_flags
+ RES 3, A
+ SET 1, A
+ LD $mem_map_loading_flags, A
+
+ Update_Animation_Steps.end:
+ RET
+
Fox_AI:
PUSH HL
@@ -120,10 +141,10 @@ Fox_AI:
AND $08
LD B, A
- LD A, $04
- CALL =RNG_Bound
+ CALL =RNG_Step
+ AND $03
INC A
- OR $08
+ OR B
LD B, A
PUSH BC
@@ -144,5 +165,3 @@ Fox_AI:
POP HL
RET
-
-
diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm
index 81e19a6..5571d03 100644
--- a/entity/bunny.gbasm
+++ b/entity/bunny.gbasm
@@ -1,126 +1,210 @@
Move_Bunny:
- PUSH HL
- LD C, $00 ; (bit 0 = has_scrolled, bit 1 = has ended movement)
- LD A, $mem_bunny_direction
- BIT 3, A
- JR NZ, =Move_Bunny.check_direction
-
- LD B, $00
- Move_Bunny.check_start_action:
- LD A, $mem_button_action
- BIT 0, A
- JR Z, =Move_Bunny.check_start_action.end
- LD B, $10
- Move_Bunny.check_start_action.end:
- LD A, $mem_bunny_direction
- AND $0f
- OR B
- LD $mem_bunny_direction, A
- LD A, $mem_bunny_direction
- AND $f0
- LD B, A
- LD A, $mem_button_direction
- CP $00
- JP Z, =Move_Bunny.end
- SET 3, A
- OR B
- LD $mem_bunny_direction, A
-
- Move_Bunny.check_collision:
- LD A, $mem_moving_animation_step
+ Start_action_or_movement:
+ LD A, $mem_map_loading_flags
+ BIT 3, A
+ JR NZ, =Start_action_or_movement.end
+ LD A, $mem_button_direction
CP $00
- JR NZ, =Move_Bunny.check_collision.end
+ JP Z, =Start_action_or_movement.end
+ SET 3, A
+ LD $mem_bunny_direction, A
- ; THIS ASSUMES THAT THE BUNNY IS ALWAYS THE FIRST ENTITY IN THE LIST
- LD HL, $mem_entities_list
- LD A, $mem_bunny_direction
+ LD A, $mem_map_loading_flags
+ SET 3, A
+ LD $mem_map_loading_flags, A
+ Start_action_or_movement.end:
- PUSH BC
- CALL =Get_Position_After_Move
- LD A, C
- CALL =Is_Collisionable
- CALL =Carve_Entity_Collision_Map
- POP BC
- CP $00
- JR Z, =Move_Bunny.check_collision.end
- Move_Bunny.check_collision.collision:
+ End_movement:
+ LD A, $mem_map_loading_flags
+ BIT 3, A
+ JR Z, =End_movement.end
+ LD A, $mem_moving_animation_step
+ CP $0f
+ JR NZ, =End_movement.end
LD A, $mem_bunny_direction
RES 3, A
LD $mem_bunny_direction, A
- JP =Move_Bunny.end
-
- Move_Bunny.check_collision.end:
- Move_Bunny.check_direction:
- LD A, $mem_bunny_direction
-
- DEC A
- LD B, $01 ; Direction of the movement (+1)
- BIT 0, A
- JR NZ, =Move_Bunny.check_direction_end
- LD B, $FF ; Direction of the movement (-1)
+ AND $07
+ LD D, A
+ LD A, $mem_bunny_x
+ LD B, A
+ LD A, $mem_bunny_y
+ LD C, A
+ LD A, $01
+ .ADD_A_TO_DIRECTION_BC
+ LD A, B
+ LD $mem_bunny_x, A
+ LD A, C
+ LD $mem_bunny_y, A
+ End_movement.end:
- Move_Bunny.check_direction_end:
- BIT 1, A
- JR NZ, =Move_Bunny.vertical_viewport_move
+ Scroll_viewport:
+ LD A, $mem_map_loading_flags
+ BIT 3, A
+ JR Z, =Scroll_viewport.end
+ LD A, $mem_bunny_direction
+ BIT 3, A
+ JR Z, =Scroll_viewport.end
- Move_Bunny.horizontal_viewport_move:
- SET 0, C
- LD A, $reg_viewport_x
- ADD B
- LD $reg_viewport_x, A
- JP =Move_Bunny.check_end_of_movement
+ Move_Bunny.check_direction:
+ LD A, $mem_bunny_direction
- Move_Bunny.vertical_viewport_move:
- SET 0, C
- LD A, $reg_viewport_y
- ADD B
- LD $reg_viewport_y, A
+ DEC A
+ LD B, $01 ; Direction of the movement (+1)
+ BIT 0, A
+ JR NZ, =Move_Bunny.check_direction_end
+ LD B, $FF ; Direction of the movement (-1)
- Move_Bunny.check_end_of_movement:
- LD A, $mem_moving_animation_step
- INC A
- AND $0f
- LD $mem_moving_animation_step, A
- JR NZ, =Move_Bunny.end
- SET 1, C
- LD A, $mem_bunny_direction
- RES 3, A
- LD $mem_bunny_direction, A
- AND $07
- DEC A
+ Move_Bunny.check_direction_end:
BIT 1, A
- JR NZ, =Move_Bunny.vertical_tile_move
+ JR NZ, =Move_Bunny.vertical_viewport_move
- Move_Bunny.horizontal_tile_move:
- BIT 0, C
- JR Z, =Move_Bunny.horizontal_tile_move.move_viewport_end
- LD A, $mem_viewport_x
- ADD B
- LD $mem_viewport_x, A
- Move_Bunny.horizontal_tile_move.move_viewport_end:
- LD A, $mem_bunny_x
+ Move_Bunny.horizontal_viewport_move:
+ SET 0, C
+ LD A, $reg_viewport_x
ADD B
- LD $mem_bunny_x, A
- JP =Move_Bunny.end
+ LD $reg_viewport_x, A
+ JP =Scroll_viewport.end
- Move_Bunny.vertical_tile_move:
- BIT 0, C
- JR Z, =Move_Bunny.vertical_tile_move.move_viewport_end
- LD A, $mem_viewport_y
- ADD B
- LD $mem_viewport_y, A
- Move_Bunny.vertical_tile_move.move_viewport_end:
- LD A, $mem_bunny_y
+ Move_Bunny.vertical_viewport_move:
+ SET 0, C
+ LD A, $reg_viewport_y
ADD B
- LD $mem_bunny_y, A
+ LD $reg_viewport_y, A
+
+ Scroll_viewport.end:
- Move_Bunny.end:
- LD A, C
- LD $mem_map_loading_flags, A
- POP HL
RET
+
+; LD C, $00 ; (bit 0 = has_scrolled, bit 1 = has ended movement)
+; LD A, $mem_bunny_direction
+; BIT 3, A
+; JR NZ, =Move_Bunny.check_direction
+;
+; LD B, $00
+; Move_Bunny.check_start_action:
+; LD A, $mem_button_action
+; BIT 0, A
+; JR Z, =Move_Bunny.check_start_action.end
+; LD B, $10
+; Move_Bunny.check_start_action.end:
+; LD A, $mem_bunny_direction
+; AND $0f
+; OR B
+; LD $mem_bunny_direction, A
+; LD A, $mem_map_loading_flags
+; SET 3, A
+; LD $mem_map_loading_flags, A
+;
+; LD A, $mem_bunny_direction
+; AND $f0
+; LD B, A
+; LD A, $mem_button_direction
+; CP $00
+; JP Z, =Move_Bunny.end
+; SET 3, A
+; OR B
+; LD $mem_bunny_direction, A
+; LD A, $mem_map_loading_flags
+; SET 3, A
+; LD $mem_map_loading_flags, A
+;
+; Move_Bunny.check_collision:
+; LD A, $mem_moving_animation_step
+; CP $00
+; JR NZ, =Move_Bunny.check_collision.end
+;
+; ; THIS ASSUMES THAT THE BUNNY IS ALWAYS THE FIRST ENTITY IN THE LIST
+; PUSH HL
+; LD HL, $mem_entities_list
+; LD A, $mem_bunny_direction
+;
+; PUSH BC
+; CALL =Get_Position_After_Move
+; LD A, C
+; CALL =Is_Collisionable
+; CALL =Carve_Entity_Collision_Map
+; POP BC
+; POP HL
+; CP $00
+; JR Z, =Move_Bunny.check_collision.end
+;
+; Move_Bunny.check_collision.collision:
+; LD A, $mem_bunny_direction
+; RES 3, A
+; LD $mem_bunny_direction, A
+; JP =Move_Bunny.end
+;
+; Move_Bunny.check_collision.end:
+;
+; Move_Bunny.check_direction:
+; LD A, $mem_bunny_direction
+;
+; DEC A
+; LD B, $01 ; Direction of the movement (+1)
+; BIT 0, A
+; JR NZ, =Move_Bunny.check_direction_end
+; LD B, $FF ; Direction of the movement (-1)
+;
+; Move_Bunny.check_direction_end:
+;
+; BIT 1, A
+; JR NZ, =Move_Bunny.vertical_viewport_move
+;
+; Move_Bunny.horizontal_viewport_move:
+; SET 0, C
+; LD A, $reg_viewport_x
+; ADD B
+; LD $reg_viewport_x, A
+; JP =Move_Bunny.check_end_of_movement
+;
+; Move_Bunny.vertical_viewport_move:
+; SET 0, C
+; LD A, $reg_viewport_y
+; ADD B
+; LD $reg_viewport_y, A
+;
+; Move_Bunny.check_end_of_movement:
+; LD A, $mem_moving_animation_step
+; CP $0f
+; JR NZ, =Move_Bunny.end
+; SET 1, C
+; LD A, $mem_bunny_direction
+; AND $07
+; LD $mem_bunny_direction, A
+; DEC A
+;
+; BIT 1, A
+; JR NZ, =Move_Bunny.vertical_tile_move
+;
+; Move_Bunny.horizontal_tile_move:
+; BIT 0, C
+; JR Z, =Move_Bunny.horizontal_tile_move.move_viewport_end
+; LD A, $mem_viewport_x
+; ADD B
+; LD $mem_viewport_x, A
+; Move_Bunny.horizontal_tile_move.move_viewport_end:
+; LD A, $mem_bunny_x
+; ADD B
+; LD $mem_bunny_x, A
+; JP =Move_Bunny.end
+;
+; Move_Bunny.vertical_tile_move:
+; BIT 0, C
+; LD A, $mem_viewport_y
+; ADD B
+; LD $mem_viewport_y, A
+; Move_Bunny.vertical_tile_move.move_viewport_end:
+; LD A, $mem_bunny_y
+; ADD B
+; LD $mem_bunny_y, A
+;
+; Move_Bunny.end:
+; LD A, C
+; LD $mem_map_loading_flags, A
+; RET
diff --git a/entity/display.gbasm b/entity/display.gbasm
index 2a54e76..25cd759 100644
--- a/entity/display.gbasm
+++ b/entity/display.gbasm
@@ -83,6 +83,7 @@ Display_Entity:
LD A, $mem_bunny_direction
BIT 3, A
JR Z, =Display_Entity.Viewport_offset_end
+ LD A, $mem_bunny_direction
AND $07
CP $enum_direction_down
JR Z, =Display_Entity.Viewport_offset_down
@@ -139,71 +140,43 @@ Display_Entity:
LD A, (HL+)
BIT 3, A
LD D, A
- LD A, $00
- JR Z, =Display_Entity.Not_Moving_Animation
-
- LD A, D
- AND $07
+ Display_Entity.Moving_Animation:
+ JR Z, =Display_Entity.Moving_Animation.end
- CP $enum_direction_down
- JR Z, =Display_Entity.moving_offset_down
- CP $enum_direction_right
- JR Z, =Display_Entity.moving_offset_right
- CP $enum_direction_up
- JR Z, =Display_Entity.moving_offset_up
-
- Display_Entity.moving_offset_left:
LD A, $mem_moving_animation_step
- XOR $ff
- ADD B
- LD B, A
-
- JR =Display_Entity.moving_offset_end
+ .ADD_A_TO_DIRECTION_BC
+ Display_Entity.Moving_Animation.end:
- Display_Entity.moving_offset_right:
- LD A, $mem_moving_animation_step
- INC A
- ADD B
- LD B, A
-
- JR =Display_Entity.moving_offset_end
+ Display_Entity.Action_Animation:
+ LD A, D
+ AND $f0
+ CP $10
+ JR NZ, =Display_Entity.Action_Animation.end
- Display_Entity.moving_offset_up:
LD A, $mem_moving_animation_step
+ SUB $08
+ .ABS
XOR $ff
- ADD C
- LD C, A
+ INC A
+ ADD $08
+ .ADD_A_TO_DIRECTION_BC
+ Display_Entity.Action_Animation.end:
- JR =Display_Entity.moving_offset_end
+ Display_Entity.Moving_Hops:
+ LD A, D
+ BIT 3, A
+ LD A, $00
+ JR Z, =Display_Entity.Moving_Hops.not_moving
- Display_Entity.moving_offset_down:
LD A, $mem_moving_animation_step
- INC A
+ Display_Entity.Moving_Hops.not_moving:
+ SUB $08
+ .ABS
+ SUB $04
+ .ABS
ADD C
LD C, A
-
- Display_Entity.moving_offset_end:
-
-
- LD A, $mem_moving_animation_step
- Display_Entity.Not_Moving_Animation:
-
- SUB $08
- BIT 7, A
- JR Z, =Display_Entity.Hop_ABS1_end
-
- ; Adding hop animation to Y
- XOR $ff
- INC A
- Display_Entity.Hop_ABS1_end:
- SUB $04
- BIT 7, A
- JR Z, =Display_Entity.Hop_ABS2_end
- XOR $ff
- INC A
- Display_Entity.Hop_ABS2_end:
- ADD C
- LD C, A
+ Display_Entity.Moving_Hops.end:
LD A, D
AND $07
diff --git a/entity/init.gbasm b/entity/init.gbasm
index 3c007b9..b6817d1 100644
--- a/entity/init.gbasm
+++ b/entity/init.gbasm
@@ -48,14 +48,6 @@ Initialize_Entities:
CALL =Initialize_Fox
CALL =Initialize_Fox
CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
- CALL =Initialize_Fox
Fix_Bunny_screen:
LD A, $mem_bunny_x
diff --git a/entity/utils.gbasm b/entity/utils.gbasm
index 23abb3a..19d1275 100644
--- a/entity/utils.gbasm
+++ b/entity/utils.gbasm
@@ -45,4 +45,47 @@ Get_Position_After_Move: ; entity (whatever alignement) in HL, direction to test
POP HL
RET
+.MACRODEF ADD_A_TO_DIRECTION_BC ; Direction in D, XY in BC (muted), offset in A
+ PUSH AF
+ LD A, D
+ AND $07
+
+ CP $enum_direction_down
+ JR Z, =$down
+ CP $enum_direction_right
+ JR Z, =$right
+ CP $enum_direction_up
+ JR Z, =$up
+
+ $left:
+ POP AF
+ XOR $ff
+ ADD B
+ LD B, A
+
+ JR =$end
+
+ $right:
+ POP AF
+ INC A
+ ADD B
+ LD B, A
+
+ JR =$end
+
+ $up:
+ POP AF
+ XOR $ff
+ ADD C
+ LD C, A
+
+ JR =$end
+
+ $down:
+ POP AF
+ INC A
+ ADD C
+ LD C, A
+ $end:
+.END
diff --git a/main.gbasm b/main.gbasm
index 1a08035..ba1f003 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -26,13 +26,14 @@ VBLANK_Entrypoint:
CALL =Display_Object
CALL $OAM_DMA_Transfer_routine
LD HL, $9800
- LD A, $mem_bunny_direction
+ LD A, $mem_bunny_x
CALL =Print_8bit
CALL =Object_Interactions_Check
CALL =Pad_Button_Check
CALL =Entities_Actions
+ CALL =Update_Animation_Steps
CALL =Prepare_Scrolling_Map
CALL =Display_Entities
@@ -45,10 +46,10 @@ VBLANK_Entrypoint:
.INCLUDE "map/loading.gbasm"
.INCLUDE "map/generation.gbasm"
.INCLUDE "map/objects.gbasm"
+.INCLUDE "entity/utils.gbasm"
.INCLUDE "entity/init.gbasm"
.INCLUDE "entity/bunny.gbasm"
.INCLUDE "entity/actions.gbasm"
.INCLUDE "entity/collisions.gbasm"
.INCLUDE "entity/display.gbasm"
-.INCLUDE "entity/utils.gbasm"
.INCLUDE "tileset.gbasm"
diff --git a/utils.gbasm b/utils.gbasm
index e6dba4c..857acbc 100644
--- a/utils.gbasm
+++ b/utils.gbasm
@@ -23,6 +23,14 @@ bzero: ; dest = HL, n = BC
JR NZ =bzero.loop
RET
+.MACRODEF ABS
+ BIT 7, A
+ JR Z, =$end
+ XOR $ff
+ INC A
+ $end:
+.END
+
Print_8bit: ; Number in A, Memory Tilemap position in HL
PUSH AF
PUSH BC