aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-09-10 18:23:30 +0900
committerAstatin <astatin@redacted>2024-09-10 18:23:30 +0900
commitd0401c01144b73a1bfe62ac7e9db902cefd784a5 (patch)
tree817bd06e9e8d1912bafaeebb373b9cb331fc0e39
parent240deda011c7ad562507759c1839d8ece785de77 (diff)
Entities now have their own behaviour function (including bunny)
-rw-r--r--bunny.gbasm15
-rw-r--r--definitions.gbasm2
-rw-r--r--entities.gbasm151
-rw-r--r--main.gbasm2
4 files changed, 166 insertions, 4 deletions
diff --git a/bunny.gbasm b/bunny.gbasm
index 5212a05..0c72578 100644
--- a/bunny.gbasm
+++ b/bunny.gbasm
@@ -33,6 +33,13 @@ Initialize_Bunny:
ADD D
LD (HL+), A
INC HL
+ LD BC, =Move_Bunny
+ LD A, B
+ LD (HL+), A
+ LD A, C
+ LD (HL+), A
+ INC HL
+ INC HL
LD A, $0d
LD (HL+), A
LD A, $10
@@ -40,8 +47,11 @@ Initialize_Bunny:
LD (HL+), A
LD A, $03
LD (HL+), A
-
-
+ LD BC, =Fox_AI
+ LD A, B
+ LD (HL+), A
+ LD A, C
+ LD (HL+), A
Fix_Bunny_screen:
LD A, $mem_bunny_x
@@ -67,6 +77,7 @@ Fix_Bunny_screen:
RET
Move_Bunny:
+ ; IF HL IS EVER USED, IT SHOULD BE PUSHED HERE
LD C, $00 ; (bit 0 = has_scrolled, bit 1 = has ended movement)
LD A, $mem_bunny_direction
BIT 3, A
diff --git a/definitions.gbasm b/definitions.gbasm
index 7ac2721..db861e2 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -26,7 +26,7 @@
.DEFINE mem_map_loading_flags ($c00c)
; bit 0: if the object should be reloaded (scroll or first load)
-; bit 1: if the interactions should be checked (at the end of a movement)
+; 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
.DEFINE mem_prepared_block_tile ($c00d)
diff --git a/entities.gbasm b/entities.gbasm
index 03786d9..c8b155c 100644
--- a/entities.gbasm
+++ b/entities.gbasm
@@ -4,12 +4,29 @@ Prepare_Entities:
LD HL, $mem_entites_list
CALL =Prepare_Entity
CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
+ CALL =Prepare_Entity
RET
Prepare_Entity:
LD A, (HL+)
LD E, A
+ CP $00
+ JP Z, =Prepare_Entity.skip
+
LD A, (HL+)
ADD $80
LD D, A
@@ -245,5 +262,139 @@ Prepare_Entity:
LD $tmp_var_1, A
POP HL
+ INC HL
+ INC HL
+ INC HL
+ INC HL
+
Prepare_Entity.skip:
RET
+
+Entities_Behaviours:
+ LD HL, $mem_entites_list
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ CALL =Entity_Behaviour
+ RET
+
+Entity_Behaviour:
+ LD A, (HL+)
+ CP $00
+ JR Z, =Entity_Behaviour.skip
+
+ INC HL
+ INC HL
+ INC HL
+
+ LD A, (HL+)
+ LD D, A
+ LD A, (HL+)
+ LD E, A
+
+ PUSH HL
+
+ LD A, L
+ AND $f8
+ LD L, A
+
+ ; This is confusing but this thing is actually CALL DE
+ LD BC, =Entity_Behaviour.interaction_end
+ PUSH BC
+ PUSH DE
+ RET
+ Entity_Behaviour.interaction_end:
+
+ POP HL
+
+ INC HL
+ INC HL
+ Entity_Behaviour.skip:
+ RET
+
+Fox_AI:
+ PUSH HL
+
+ INC HL
+ INC HL
+ INC HL
+
+ LD A, $mem_map_loading_flags
+ BIT 1, A
+ JR Z, =Fox_AI.Update_Position.end
+
+ LD A, (HL)
+ BIT 3, A
+ JR Z, =Fox_AI.Update_Position.end
+
+ RES 3, A
+ DEC A
+
+ LD C, A
+ AND $01
+ SLA A
+ AND $02
+ DEC A
+ LD B, A
+
+ LD A, L
+ AND $f8
+ INC A
+ LD L, A
+
+ BIT 1, C
+ JR NZ, =Fox_AI.vertical_tile_move
+
+ Fox_AI.horizontal_tile_move:
+ LD A, (HL)
+ ADD B
+ LD (HL), A
+ JP =Fox_AI.Update_Position.end
+
+ Fox_AI.vertical_tile_move:
+ INC HL
+ LD A, (HL)
+ ADD B
+ LD (HL), A
+
+ Fox_AI.Update_Position.end:
+
+ LD A, L
+ AND $f8
+ ADD $03
+ LD L, A
+
+ LD A, $mem_moving_animation_step
+ CP $01
+ JR NZ, =Fox_AI.end
+
+ LD A, $mem_bunny_direction
+ BIT 3, A
+ JR Z, =Fox_AI.end
+
+ CALL =RNG_Step
+ AND $08
+ LD B, A
+
+ LD A, $04
+ CALL =RNG_Bound
+ INC A
+ OR B
+ LD (HL), A
+
+ Fox_AI.end:
+
+ POP HL
+ RET
diff --git a/main.gbasm b/main.gbasm
index eb1ea52..0b4493d 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -29,7 +29,7 @@ VBLANK_Entrypoint:
CALL =Object_Interactions_Check
CALL =Pad_Button_Check
- CALL =Move_Bunny
+ CALL =Entities_Behaviours
CALL =Prepare_Scrolling_Map
CALL =Prepare_Entities