Level generation

Using your high level description at the beginning of the video, I usually work out my own solution. That way I have to search and that’s how I learn better. So, of course I come with a different result :

func generate_level():
	# the ground
	var loc_x = 0
	var platform_size_x = 136
	for i in range(4):
		create_platform(Vector2(loc_x, viewport_size.y - 64))
		loc_x += platform_size_x

	# the level
	var random = RandomNumberGenerator.new()
	random.randomize()
	var loc_y = viewport_size.y - randi_range(min_distance_jumps, max_distance_jumps)
	for i in range(level_size):
		loc_x = randi() % int(viewport_size.x - platform_size_x)
		create_platform(Vector2(loc_x, loc_y))
		loc_y -= randi_range(min_distance_jumps, max_distance_jumps)
3 Likes

Privacy & Terms