diff options
-rw-r--r-- | definitions.gbasm | 8 | ||||
-rw-r--r-- | entity/actions.gbasm | 3 | ||||
-rw-r--r-- | entity/bunny.gbasm | 55 | ||||
-rw-r--r-- | entity/collisions.gbasm | 2 | ||||
-rw-r--r-- | entity/init.gbasm | 71 | ||||
-rw-r--r-- | main.gbasm | 13 |
6 files changed, 143 insertions, 9 deletions
diff --git a/definitions.gbasm b/definitions.gbasm index 4e60a84..f166d8c 100644 --- a/definitions.gbasm +++ b/definitions.gbasm @@ -22,7 +22,8 @@ ; frame 0 (or 1 ?): movement can be initiated when with button actions ; frame 2: applying bunny attack damages ; frame 3: checking entities health and death if 0 -; frame 4: entity collision map is being updated +; frame 4: new entity spawn +; frame 5: entity collision map is being updated ; frame 15: movement is ended and coordinates are updated .DEFINE mem_bunny_sprite ($cb00) @@ -93,6 +94,9 @@ .DEFINE mem_prepared_color_palette ($c029) +.DEFINE mem_bunny_current_room_idx ($c02a) +.DEFINE mem_enemies_alive_count ($c02b) + .DEFINE next_free_head_higher_bytes $c7 .DEFINE mem_next_free_head_lower_bytes ($c6ff) @@ -111,13 +115,13 @@ .DEFINE mem_dungeon_map_high $c8 .DEFINE mem_room_list $c880 ; Takes the memory from c880 to c89f -.DEFINE mem_number_of_rooms ($c8a0) ; struct room { ; x: u8, ; sizex: u8, ; y: u8, ; sizey: u8, ; } +.DEFINE mem_number_of_rooms ($c8a0) .DEFINE mem_object_list $c900 ; Takes the memory from c900 to c97f ; struct objects { diff --git a/entity/actions.gbasm b/entity/actions.gbasm index 5bc8200..2616e49 100644 --- a/entity/actions.gbasm +++ b/entity/actions.gbasm @@ -182,6 +182,9 @@ Fox_Turn: LD L, A LD (HL), $00 + LD A, $mem_enemies_alive_count + DEC A + LD $mem_enemies_alive_count, A JP NZ, =Fox_Turn.Skip_turn Fox_Turn.Health_check.end: diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm index 7d5a5d0..d3ea7af 100644 --- a/entity/bunny.gbasm +++ b/entity/bunny.gbasm @@ -104,7 +104,7 @@ Move_Bunny: AND $07 BIT 3, D LD $mem_bunny_direction, A - JR Z, =End_movement.end + JP Z, =End_movement.end LD A, $mem_bunny_x LD B, A @@ -131,6 +131,59 @@ Move_Bunny: LD A, $mem_bunny_flags RES 0, A LD $mem_bunny_flags, A + + PUSH DE + Update_current_room: + LD A, $ff + LD $mem_bunny_current_room_idx, A + + LD HL, $mem_room_list + + Update_current_room.loop: + LD A, $mem_bunny_x + LD D, A + LD E, (HL) + CP E + JR C, =Update_current_room.skip + + LD A, E + INC HL + ADD (HL) + CP D + JR C, =Update_current_room.skip + + INC HL + + LD A, $mem_bunny_y + LD D, A + LD E, (HL) + CP E + JR C, =Update_current_room.skip + + LD A, E + INC HL + ADD (HL) + CP D + JR C, =Update_current_room.skip + + LD A, L + SUB $83 + SRA A + SRA A + + LD $mem_bunny_current_room_idx, A + JR =Update_current_room.end + + Update_current_room.skip: + LD A, L + AND $fc + ADD $04 + LD L, A + CP $a0 + JR NZ, =Update_current_room.loop + Update_current_room.end: + POP DE + End_movement.end: Middle_movement_doublespeed_viewport_update: diff --git a/entity/collisions.gbasm b/entity/collisions.gbasm index 1777ddb..2d66dc2 100644 --- a/entity/collisions.gbasm +++ b/entity/collisions.gbasm @@ -92,7 +92,7 @@ Is_Collisionable: ; X in A, Y in B, Result A Reset_Entities_Collision_Map: LD A, $mem_moving_animation_step - CP $04 + CP $05 JR NZ, =Reset_Entities_Collision_Map.end LD HL, $mem_entities_collisions diff --git a/entity/init.gbasm b/entity/init.gbasm index f94cbd5..42248c8 100644 --- a/entity/init.gbasm +++ b/entity/init.gbasm @@ -60,6 +60,12 @@ Initialize_Entities: ADD $0a LD L, A + LD A, $00 + LD $mem_enemies_alive_count, A + + LD A, $ff + LD $mem_bunny_current_room_idx, A + CALL =Initialize_Fox CALL =Initialize_Fox CALL =Initialize_Fox @@ -90,10 +96,39 @@ Fix_Bunny_screen: RET Initialize_Fox: + LD A, $mem_enemies_alive_count + INC A + LD $mem_enemies_alive_count, A + LD A, $0d LD (HL+), A - LD A, $mem_number_of_rooms - CALL =RNG_Bound + LD A, $mem_bunny_current_room_idx + LD $tmp_var_6, A + CP $FF + JR Z, =Initialize_Fox.All_rooms_allowed + LD B, A + Initialize_Fox.Skip_bunny_room: + LD A, $mem_number_of_rooms + CP $01 + JR Z, =Initialize_Fox.All_rooms_allowed + + DEC A + CALL =RNG_Bound + LD $tmp_var_5, A + INC A + LD C, A + LD A, B + CP C + LD A, C + JR C, =Initialize_Fox.Room_restriction.end + DEC A + JR =Initialize_Fox.Room_restriction.end + + Initialize_Fox.All_rooms_allowed: + LD A, $mem_number_of_rooms + CALL =RNG_Bound + Initialize_Fox.Room_restriction.end: + LD $tmp_var_4, A SLA A SLA A ADD $80 @@ -140,3 +175,35 @@ Initialize_Fox: LD L, A 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 + + 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. + LD A, L + AND $f0 + ADD $10 + LD L, A + + LD A, $00 + CP (HL) + JR NZ, =FindFreeEntity.loop + + CALL =Initialize_Fox + RET @@ -112,6 +112,15 @@ VBLANK_Entrypoint: LD A, $tmp_var_5 LD HL, $9c12 CALL =Print_8bit + LD A, $tmp_var_6 + LD HL, $9c0d + CALL =Print_8bit + LD A, $tmp_var_4 + LD HL, $9c0a + CALL =Print_8bit + LD A, $mem_bunny_current_room_idx + LD HL, $9c07 + CALL =Print_8bit LD A, $palette_bold_font LD $reg_bg_palette, A @@ -134,9 +143,6 @@ VBLANK_Entrypoint: CALL =Copy_Dialogue_Buffer CALL =Display_dialogue_cursor - LD A, $reg_lcd_status - LD $tmp_var_5, A - ; LYC LD A, $09 LD $reg_lyc, A @@ -152,6 +158,7 @@ VBLANK_Entrypoint: CALL =Object_Interactions_Check CALL =Entities_Actions + CALL =Respawn_Entities CALL =Prepare_Scrolling_Map Skip_Dungeon_Update: |