dynamicklion.blogg.se

Tinykeep dungeon generation
Tinykeep dungeon generation








tinykeep dungeon generation

Since this is a simple dungeon generator which places rooms and corridors using a TileMap node, we can store Vector2 points into a dictionary as keys representing the location in TileMap coordinates where we’d like to dig. The first step in deciding what to do is to pick a data structure to hold our information. See the picture below for a visual representation. Zooms out by that factor since Godot enlarges the camera boundaries by We then calculate the camera zoom factor by dividing the maximum between level_size.x and level_size.y with an arbitrary value that seems to work in this case. We place the camera at a position using TileMap.map_to_world() which converts a 2D vector from tile map coordinates to pixel coordinates. We also calculate a suitable zoom factor: func _setup_camera() -> void:Ĭamera. We use _setup_camera() to position the camera in the middle of the level, based on level_size.

tinykeep dungeon generation

We’re using a 2D vector to store information about an interval, in this case.Ĭreate the _ready() function with the following content: func _ready() -> void: And we use rooms_size.y to mean the maximum instead. It’s not the X and Y size of a room, but instead we’ll use rooms_size.x to mean the minimum value of tiles a room can take on either of the axes.

tinykeep dungeon generation

We create level_size, rooms_size and rooms_max as export variables so that we can get easy access to them in the Inspector. Onready var camera: Camera2D = $ Camera2D You should have the following now: The scriptĪttach a new script to the BasicDungeon node and define the following variables: extends Node2D export var level_size : = Vector2( 100, 80)Įxport var rooms_size : = Vector2( 10, 14)Įxport var rooms_max : = 15 onready var level: TileMap = $Level Camera2D: turn on Current in the Inspector docker as it isn’t by default.Also note that we changed Size to Vector2(60, 60). TileMap: rename to Level and follow the instructions in the image below to assign es to the Tile Set property in the Inspector.Rename the root node to BasicDungeon node and add the following new nodes: We’re using the bright cream color from the Pear36 palette: #ffffeb. You can do so by going to Project > Project Settings… > Rendering > Environment and changing the Default Clear Color option. Remember we have to preserve the file structure so copy the entire directory, not olny the files inside of it.īefore moving on you might want to change the default backgroundĬolor to something lighter because our tile set has a dark purple color. It contains a tile set resource that we’ll be using through this project. From our Procedural Generation demos project copy the Common folder over to your local project. Randomly placing them will ensure that the total number of roomsįirst, create a new Godot project if you haven’t done so. Rooms, we don’t have to generate a random number of rooms to iterate Given that we skip rooms if they intersect with previously placed until the iterator is equal to the maximum allowed number of rooms. If we have more than one room saved create a corridor between the current room and the previous room (#5-9).Else, if the intersection fails then save the current room into the data structure.If intersection is confirmed skip the current room.Check for intersections with previous rooms if any (#4-6).Create a rectangular room and place it randomly in the allowed level size (#2).Based on the room size parameters (#1).Let’s go over the algorithm conceptually: Since we’ll create rectangular rooms it sounds like a good use of the Rect2 class. minimum and maximum room sizes for both vertical and horizontal directions.level/map size in tiles because we’ll be using the TileMap node.To create the dungeon we first need to figure out what are the parameters for driving the procedural content.










Tinykeep dungeon generation