From 06c7d96d6484df4c22628a78a029cc40c80780ef Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 24 Aug 2025 22:38:22 +0200 Subject: [PATCH] mapgen: wip placing player randomly --- src/mapgen.s | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/mapgen.s b/src/mapgen.s index bc13838..1ea33ab 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -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 -- 2.30.2