help me set this up so it generates a random room with height map : extends Node var…
- User
help me set this up so it generates a random room with height map :
extends Node
var max_rooms = 10 var room_min_size = Vector2(5, 5) var room_max_size = Vector2(10, 10) var map_size = Vector2(100, 100) var rooms = [] var room_scene: PackedScene = preload("res://Scenes/rooms/Room.tscn") func _ready(): print("Preloaded room_scene is: ", room_scene) # Check that the room_scene variable is indeed a PackedScene if room_scene is PackedScene: print("Confirmed that room_scene is a PackedScene") generate_dungeon() else: print("room_scene is not a PackedScene, it is: ", room_scene.get_class())
func generate_dungeon(): var rng = RandomNumberGenerator.new() rng.randomize() for i in range(max_rooms): var room_width = rng.randi_range(room_min_size.x, room_max_size.x) var room_height = rng.randi_range(room_min_size.y, room_max_size.y) var x = rng.randi_range(0, map_size.x - room_width) var y = rng.randi_range(0, map_size.y - room_height) var room_pos = Vector2(x, y) var room_size = Vector2(room_width, room_height) create_room(room_pos, room_size)
# Optional code for hallways – not included here for simplicityfunc create_room(position, size): var room_instance = room_scene.instance() room_instance.set_room_size(size * 32) # Dynamically set the room size. room_instance.position = position * 32 # Set position appropriately. add_child(room_instance) rooms.append(room_instance)
func create_hallway(room1, room2): # Simple hallway creation logic. # For this example, we’ll just draw a straight horizontal line between the rooms. var hallway_start = room1.position + Vector2(room1.size.x / 2, room1.size.y / 2) var hallway_end = room2.position + Vector2(room2.size.x / 2, room2.size.y / 2) var hallway = Path2D.new() var curve = Curve2D.new() # Change this line to use Curve2D curve.add_point(hallway_start) # Add the start point to the curve curve.add_point(hallway_end) # Add the end point to the curve hallway.curve = curve # Assign the Curve
class Room: var position var size func init(p_position, p_size): position = p_position size = p_size # Room class represents a single room in the dungeon.
func create_platformer_view_for_room(room): var platformer_room = room_scene.instance() platformer_room.position = room.position * 32 platformer_room.size = room.size * 32 # Here you should populate the room with platforms and obstacles # Platform and obstacle creation is skipped for simplicity. add_child(platformer_room) return platformer_room
func on_room_entered(room): var platformer_view = create_platformer_view_for_room(room) # Adapt the room entrance logic to your game’s requirements. # Maybe you’ll have a fade-in effect or disable the player’s movement momentarily.
func on_room_exited(room): # Adapt the room exit logic to your game’s requirements. pass # Again, you might handle the transition effect or clean-up here.
- Assistant
- User
show me the script for the room.tsc
- Assistant
Certainly! To implement a basic script for
Room.tscnso that it integrates with the dungeon generation script, you would need a script that can create the visual representation of the room and potentially receive a size to configure its dimensions. Let's consider that contains some visual elements like a for the floor or walls and nodes to define its boundaries for collision detection.