mapgen: wip placing player randomly
authorLukas Krickl <lukas@krickl.dev>
Sun, 24 Aug 2025 20:38:22 +0000 (22:38 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 24 Aug 2025 20:38:22 +0000 (22:38 +0200)
src/mapgen.s

index bc1383860188d194f4695f9829bbc9cee0fd274f..1ea33ab6c9d3869c3b5fc2846843ef98208854dc 100644 (file)
@@ -9,7 +9,6 @@ mapgen_init:
        call mapgen_seed
        call mapgen_make_doors
        call mapgen_select_player_spawn
-       call mapgen
        ret
        
        ; selects a room pattern table
@@ -582,6 +581,7 @@ mapgent_unit_randomize_or_reaload_position:
        ; selects a random room that has an exit and
        ; sets the map cursor
        ; then places the player on a tile without flags
+       ; calls mapgen after player is placed to make the map
 mapgen_select_player_spawn:
        call rand
        and a, FLOOR_MAP_COUNT-1
@@ -598,8 +598,32 @@ mapgen_select_player_spawn:
        ; write selected room
        ld a, e 
        ld [player_map_cursor], a
-
-       ; TODO: move player position
        
+       call mapgen
+
+@try_placement_again:
+               call rand
+               and a, MAP_H-1
+               ld b, a ; y pos
+               call rand
+               and a, MAP_W-1
+               ld c, a ; x pos
+
+               ; get tile data
+               push bc
+               call map_get_tile
+               cp a, 0x00 ; we want no flags here
+               pop bc
+       jr z, @try_placement_again REL
+
+       ; otherwise write position
+       ld hl, player_unit
+       ld de, act_pos_y
+       add hl, de
+       ld a, b
+       ;ld [hl+], a ; write y
+
+       ld a, c
+       ;ld [hl], a ; write x
 
        ret