Heartbeast procgen tutorial Godot3

Godot 3.x

I’m trying to add enemies in heartbeast’s random walker generator tutorial, but I don’t know how to do it. Any suggestions? Thanks in advance

well, what part are you struggling with?
I haven’t followed said tutorial, but describing the problem more will enable more people to help you.

If you’d like, you can even link the tutorial if its on youtube or something, so other people can compare your code to theirs, if they so desire.

https://www.youtube.com/playlist?list=PL9FzW-m48fn1te9MJgxmmaiKtOytFIRo3
Here’s the complete tutorial. The problem is that he doesn’t show the code for adding the enemies in each room and I don’t know the way to do it since this is my very first Godot project.

sorry for late reply
so it looks like (From clicking on third video and seeing what he was showing the end will look like) that he indeed didnt add enemies in his.

One way to add enemies is with instance()

It looks like you’re using godot 3 atm. My gut says this tutorial may be able to help you (in ‘spawning mobs’ section) but I’m reading through to see if i can find hwat is most relevant : link : The main game scene — Godot Engine (3.5) documentation in English

you’ll for certain want to instance the enemy, as well as add it as a child to something in the scene tree (perhaps just hte scene you are in)

I’m not sure what sort of movement you want, or what sort of behavior you want, so I can’t much help more without more information (and, honestly, behavior of enemies in randomly generated scenes is not somehting i’m very familiar with)

Sorry i can’t be much more help.

The same creator HeartBeast has a great action RPG tutorial as well.
In this episode he adds an enemy.

Here’s the code I used for the generation of the level
extends Node2D

const Player = preload (“res://Player/Player.tscn”)
const Exit = preload (“res://World/ExitDoor.tscn”)
const Enemy = preload (“res://Enemies/Bat.tscn”)

var borders = Rect2(1, 1, 38, 21)

onready var tileMap = $TileMap
onready var timeLabel = $CanvasLayer/CenterContainer/TimeLabel
onready var timer = $CanvasLayer/CenterContainer/Timer

func _ready():
randomize()
generate_level()
timer.start()

func generate_level():
var walker = Walker.new(Vector2(19, 11), borders)
var map = walker.walk(200)

var player = Player.instance()
var enemy = Enemy.instance()
add_child(player)
player.position = map.front() * 32
add_child(enemy)
enemy.position = map.front() * 32
var exit = Exit.instance()
add_child(exit)
exit.position = walker.get_end_room().position * 32
exit.connect("leaving_level", self, "reload_level")


walker.queue_free()
for location in map:
	tileMap.set_cellv(location, -1)
tileMap.update_bitmask_region(borders.position, borders.end)

func reload_level():
get_tree().reload_current_scene()

func time_to_live():
var time_left = timer.time_left
var minute = floor (time_left / 60)
var second = int(time_left) % 60
return [minute, second]

func _process(delta):
timeLabel.text = “TIME LEFT %02d:%02d” % time_to_live()

func _on_Timer_timeout():
get_tree().change_scene(“res://Menu/GameOver.tscn”)

This is the walker.gd file
extends Node
class_name Walker

const DIRECTIONS = [Vector2.RIGHT, Vector2.UP, Vector2.LEFT, Vector2.DOWN]

var position = Vector2.ZERO
var direction = Vector2.RIGHT
var borders = Rect2()
var step_history =
var steps_since_turn = 0
var rooms =

func _init(starting_position, new_borders):
assert(new_borders.has_point(starting_position))
position = starting_position
step_history.append(position)
borders = new_borders

func walk(steps):
place_room(position)
for step in steps:
if steps_since_turn >= 6:
change_direction()
if step():
step_history.append(position)
else:
change_direction()
return step_history

func step():
var target_position = position + direction
if borders.has_point(target_position):
steps_since_turn += 1
position = target_position
return true
else:
return false

func change_direction():
place_room(position)
steps_since_turn = 0
var directions = DIRECTIONS.duplicate()
directions.erase(direction)
directions.shuffle()
direction = directions.pop_front()
while not borders.has_point(position + direction):
direction = directions.pop_front()

func create_room(position, size):
return {position = position, size = size}

func place_room(position):
var size = Vector2(randi() % 4 + 2, randi() % 4 + 2)
var top_left_corner = (position - size/2).ceil()
rooms.append(create_room(position, size))
for y in size.y:
for x in size.x:
var new_step = top_left_corner + Vector2(x, y)
if borders.has_point(new_step):
step_history.append(new_step)

func get_end_room():
var end_room = rooms.pop_front()
var starting_position = step_history.front()
for room in rooms:
if starting_position.distance_to(room.position) > starting_position.distance_to(end_room.position):
end_room = room
return end_room