aboutsummaryrefslogtreecommitdiff
path: root/entity
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-03-18 19:12:59 +0900
committerAstatin <[email protected]>2025-03-18 19:12:59 +0900
commit579e73311319868d8b186e3442098358d839b3b3 (patch)
treeb21d556c7c6a5e72b0c25a224711c2e553e46abb /entity
parenta29c10798a8064542ac04a5160baaa9b406ef239 (diff)
Add generation events to be executed on floor generation
Diffstat (limited to 'entity')
-rw-r--r--entity/bunny.gbasm1
-rw-r--r--entity/init.gbasm47
2 files changed, 29 insertions, 19 deletions
diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm
index 32cff97..29f66d9 100644
--- a/entity/bunny.gbasm
+++ b/entity/bunny.gbasm
@@ -147,7 +147,6 @@ Move_Bunny:
DEC A
DAA
LD (HL+), A
- DBG
SET 3, (HL)
LD A, $24
diff --git a/entity/init.gbasm b/entity/init.gbasm
index e9a3cbc..5d5676a 100644
--- a/entity/init.gbasm
+++ b/entity/init.gbasm
@@ -95,8 +95,6 @@ Initialize_Entities:
LD A, $ff
LD $mem_bunny_current_room_idx, A
- LD A, $07
- CALL =Initialize_Entity
CALL =Initialize_Enemy
CALL =Initialize_Enemy
CALL =Initialize_Enemy
@@ -136,7 +134,7 @@ Initialize_Enemy: ; HL => pointer to entity struct
AND $03
ADD $03
-Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
+Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index, 1 in $tmp_var_3 if should retry if collsion (could potentially fail multiple time/infinite loop)
LD E, A
SLA A
SLA A
@@ -166,6 +164,8 @@ Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
LD A, C
JR C, =Initialize_Enemy.Room_restriction.end
DEC A
+
+ LD A, E
JR =Initialize_Enemy.Room_restriction.end
Initialize_Enemy.All_rooms_allowed:
@@ -220,7 +220,13 @@ Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
LD (HL), A
POP BC
- RET
+
+ LD A, $tmp_var_3
+ CP $01
+ RET Z
+
+ LD A, E
+ JP =Initialize_Entity
.no_collision:
CALL =Carve_Entity_Collision_Map
@@ -286,26 +292,14 @@ Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
RET
-Respawn_Entities:
- LD A, $mem_moving_animation_step
- CP $04
- RET NZ
-
- LD A, $mem_enemies_alive_count
- CP $05
- RET NC
-
- CALL =RNG_Step
- AND $0f
- CP $00
- RET NZ
-
+FindFreeEntity:
LD HL, $mem_entities_list
FindFreeEntity.loop:
; This loop supposes that there is indeed enough space for a new entity
; to be spawn (thus the previous mem_enemies_alive_count).
; If entities are changed at some point to contain things that are not
; counted in mem_enemies_alive_count, this could result in an infinite loop.
+ ; (Technically the quest goals can spawn other entities. We assume that the enemies alive count and the quest goal entities spawned will never exceed 15 together)
LD A, L
AND $f0
ADD $10
@@ -314,6 +308,23 @@ Respawn_Entities:
LD A, $00
CP (HL)
JR NZ, =FindFreeEntity.loop
+ RET
+
+Respawn_Entities:
+ LD A, $mem_moving_animation_step
+ CP $04
+ RET NZ
+
+ LD A, $mem_enemies_alive_count
+ CP $05
+ RET NC
+
+ CALL =RNG_Step
+ AND $0f
+ CP $00
+ RET NZ
+
+ CALL =FindFreeEntity
CALL =Initialize_Enemy
RET