help me write a map generator in godot for 2d that generates a dungeon crawler but it…
- User
help me write a map generator in godot for 2d that generates a dungeon crawler but it also generates a platform view of each room, so both an over view and a platform view of each room
- Assistant
- User
help me fletch this out so it works:
extends Node
var map_size = Vector2(100, 100) var rooms = []
func _ready(): generate_dungeon()
func generate_dungeon(): # Your generation algorithms go here. # For example, you could use a binary space partitioning (BSP) tree, # cellular automata, or drunken walk algorithm to create rooms # and connect them with hallways. pass
func create_room(position, size): var new_room = Room.new() new_room.init(position, size) rooms.append(new_room) # Create visual representations for the top-down view. pass
func create_hallway(room1, room2): # Create a hallway connecting two rooms. pass
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): # Depending on the size and shape of the room, you create platforms, # obstacles, and perhaps enemies within a new scene which represents # the platformer view of that room. var platformer_room = preload("res://scenes/platformer_room.tscn").instance() for i in range(room.size.y / platform_height): # Place a platform sprite or tilemap along the bottom of the room, etc. pass # Adjust the logic to account for obstacles, enemies, ladders, etc. add_child(platformer_room)
- Assistant
- User
how do I use the script and test so it works?
- Assistant
- User
- Assistant
- User
func create_room(position, size): var new_room = Room.new() # This will use our Room class below new_room.init(position, size) rooms.append(new_room) # Instantiating the visual room representation. 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) # Add it as a child of our Node2D.
- Assistant