Merge branch 'map_generation' into 'master'
Add new room type : chunk rooms See merge request ynerant/squirrel-battle!77
This commit is contained in:
commit
fa0a0a79ea
|
@ -13,7 +13,7 @@ DEFAULT_PARAMS = {
|
||||||
"max_rooms": 20,
|
"max_rooms": 20,
|
||||||
"max_room_tries": 15,
|
"max_room_tries": 15,
|
||||||
"cross_room": 1,
|
"cross_room": 1,
|
||||||
"corridor_chance": .6,
|
"corridor_chance": .2,
|
||||||
"min_v_corr": 2,
|
"min_v_corr": 2,
|
||||||
"max_v_corr": 6,
|
"max_v_corr": 6,
|
||||||
"min_h_corr": 4,
|
"min_h_corr": 4,
|
||||||
|
@ -24,6 +24,10 @@ DEFAULT_PARAMS = {
|
||||||
"loop_max": 5,
|
"loop_max": 5,
|
||||||
"loop_threshold": 15,
|
"loop_threshold": 15,
|
||||||
"spawn_per_region": [1, 2],
|
"spawn_per_region": [1, 2],
|
||||||
|
"room_chances": {
|
||||||
|
"circular": 5,
|
||||||
|
"chunks": 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,6 +258,47 @@ class Generator:
|
||||||
|
|
||||||
return y + length * dy, x + length * dx, dy, dx
|
return y + length * dy, x + length * dx, dy, dx
|
||||||
|
|
||||||
|
def create_chunk_room(self, spawnable: bool = True) \
|
||||||
|
-> Tuple[List[List[Tile]], int, int, int, int]:
|
||||||
|
"""
|
||||||
|
Create and return as a tile grid a room that is composed of multiple
|
||||||
|
overlapping circles of the same radius
|
||||||
|
Also return door info so we know how to place the room in the level
|
||||||
|
"""
|
||||||
|
height, width = 15, 15
|
||||||
|
nb_chunks, r = 6, 3
|
||||||
|
|
||||||
|
h_sup, w_sup, h_off, w_off = self.corr_meta_info()
|
||||||
|
room = [[Tile.EMPTY] * (width + w_sup)
|
||||||
|
for _dummy in range(height + h_sup)]
|
||||||
|
|
||||||
|
def draw_chunk(room: List[List[Tile]], y: int, x: int) -> None:
|
||||||
|
for i in range(y - r, y + r + 1):
|
||||||
|
d = (y - i)**2
|
||||||
|
for j in range(x - r, x + r + 1):
|
||||||
|
if d + (x - j) ** 2 < r ** 2:
|
||||||
|
room[i][j] = Tile.FLOOR
|
||||||
|
|
||||||
|
draw_chunk(room, h_off + height // 2 + 1, w_off + width // 2 + 1)
|
||||||
|
|
||||||
|
min_w, max_w = w_off + r + 1, width + w_off - r - 1
|
||||||
|
min_h, max_h = h_off + r + 1, height + h_off - r - 1
|
||||||
|
for i in range(nb_chunks):
|
||||||
|
y, x = randint(min_h, max_h), randint(min_w, max_w)
|
||||||
|
while room[y][x] != Tile.FLOOR:
|
||||||
|
y, x = randint(min_h, max_h), randint(min_w, max_w)
|
||||||
|
draw_chunk(room, y, x)
|
||||||
|
|
||||||
|
# log all placed tiles as spawn positions
|
||||||
|
if spawnable:
|
||||||
|
self.register_spawn_area(room)
|
||||||
|
|
||||||
|
# attach exit
|
||||||
|
door_y, door_x, dy, dx = self.attach_door(room, h_sup, w_sup,
|
||||||
|
h_off, w_off)
|
||||||
|
|
||||||
|
return room, door_y, door_x, dy, dx
|
||||||
|
|
||||||
def create_circular_room(self, spawnable: bool = True) \
|
def create_circular_room(self, spawnable: bool = True) \
|
||||||
-> Tuple[List[List[Tile]], int, int, int, int]:
|
-> Tuple[List[List[Tile]], int, int, int, int]:
|
||||||
"""
|
"""
|
||||||
|
@ -304,7 +349,19 @@ class Generator:
|
||||||
door info. Set spawnable to False is the room should be marked as a
|
door info. Set spawnable to False is the room should be marked as a
|
||||||
potential spawning region on the map
|
potential spawning region on the map
|
||||||
"""
|
"""
|
||||||
return self.create_circular_room()
|
coef_dict = self.params["room_chances"]
|
||||||
|
sum_coefs = sum(coef_dict[key] for key in coef_dict)
|
||||||
|
target = randint(1, sum_coefs)
|
||||||
|
for key in coef_dict:
|
||||||
|
if target > coef_dict[key]:
|
||||||
|
target -= coef_dict[key]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
if key == "circular":
|
||||||
|
return self.create_circular_room(spawnable=spawnable)
|
||||||
|
elif key == "chunks":
|
||||||
|
return self.create_chunk_room(spawnable=spawnable)
|
||||||
|
|
||||||
def register_spawn_area(self, area: List[List[Tile]]) -> None:
|
def register_spawn_area(self, area: List[List[Tile]]) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
import os
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from ..bootstrap import Bootstrap
|
from ..bootstrap import Bootstrap
|
||||||
|
@ -101,7 +100,6 @@ class TestGame(unittest.TestCase):
|
||||||
Yeah, that's only for coverage.
|
Yeah, that's only for coverage.
|
||||||
"""
|
"""
|
||||||
self.assertRaises(Exception, Bootstrap.run_game)
|
self.assertRaises(Exception, Bootstrap.run_game)
|
||||||
self.assertEqual(os.getenv("TERM", "unknown"), "unknown")
|
|
||||||
|
|
||||||
def test_key_translation(self) -> None:
|
def test_key_translation(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue