aboutsummaryrefslogtreecommitdiff
path: root/map
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-05-02 15:28:14 +0200
committerAstatin <[email protected]>2025-05-02 15:28:14 +0200
commit4e618ff322cc0a6b1b7b8947983e4055b96e43d2 (patch)
treed28235e111fb147bfe3488a33a15dcd0d8012295 /map
parentf137ecaba8297bb99b33559832e3131fda3646c2 (diff)
Make stairs avoid bunny room
Diffstat (limited to 'map')
-rw-r--r--map/objects.gbasm22
-rw-r--r--map/utils.gbasm29
2 files changed, 48 insertions, 3 deletions
diff --git a/map/objects.gbasm b/map/objects.gbasm
index bb3a35a..a79a954 100644
--- a/map/objects.gbasm
+++ b/map/objects.gbasm
@@ -27,12 +27,27 @@ Find_Free_Object_slot: ; Return free object slot in HL ($80 if none is found)
RET
+Spawn_object_in_random_room_avoid_bunny: ; Object tile in A, Object jump table id in E, Object pointer in HL
+ LD (HL+), A
+
+ .retry:
+ CALL =.retry.entrypoint
+ JR =.retry
+ .retry.entrypoint:
+ LD A, $mem_bunny_current_room_idx
+ CALL =Pick_Random_Room_Avoid_A
+ JR =Spawn_object_in_random_room.place_object_in_room_A
+
Spawn_object_in_random_room: ; Object tile in A, Object jump table id in E, Object pointer in HL
LD (HL+), A
- .place_in_random_room:
+ .retry:
+ CALL =.retry.entrypoint
+ JR =.retry
+ .retry.entrypoint:
LD A, $mem_number_of_rooms
CALL =RNG_Bound
+ .place_object_in_room_A:
SLA A
SLA A
ADD low($mem_room_list)
@@ -69,7 +84,8 @@ Spawn_object_in_random_room: ; Object tile in A, Object jump table id in E, Obje
CALL =Is_Collisionable
CP $00
- JR NZ, =.place_in_random_room
+ RET NZ
+ ADD SP, $02
CALL =Check_other_object_collision
CP $00
@@ -139,7 +155,7 @@ Check_other_object_collision: ; Object in HL (with only sprite x & y set), will
Spawn_stairs:
LD A, $60
LD E, $01
- JP =Spawn_object_in_random_room
+ JP =Spawn_object_in_random_room_avoid_bunny
Spawn_carrot:
LD A, $64
diff --git a/map/utils.gbasm b/map/utils.gbasm
new file mode 100644
index 0000000..cf2c4ce
--- /dev/null
+++ b/map/utils.gbasm
@@ -0,0 +1,29 @@
+Pick_Random_Room_Avoid_A: ; input A = room to avoid (or FF if none), output A = chosen room idx
+ PUSH BC
+ CP $FF
+ JR Z, =.All_rooms_allowed
+ LD B, A
+ .Skip_bunny_room:
+ LD A, $mem_number_of_rooms
+ CP $01
+ JR Z, =.All_rooms_allowed
+
+ DEC A
+ CALL =RNG_Bound
+ INC A
+ LD C, A
+ LD A, B
+ CP C
+ LD A, C
+ JR C, =.Room_restriction.end
+ DEC A
+
+ JR =.Room_restriction.end
+
+ .All_rooms_allowed:
+ LD A, $mem_number_of_rooms
+ CALL =RNG_Bound
+ .Room_restriction.end:
+ POP BC
+ RET
+