Created
July 17, 2018 14:14
-
-
Save jedStevens/a9b90b8b0a60b5f575df3b3183d2ea17 to your computer and use it in GitHub Desktop.
Generates terrain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends TileMap | |
# Declare member variables here. Examples: | |
# var a = 2 | |
# var b = "text" | |
var height = 5 | |
var width = 500 | |
var loops = 6 | |
# Called when the node enters the scene tree for the first time. | |
func _ready(): | |
generate() | |
func generate(): | |
var points = [0,0] | |
for i in range(loops): | |
points = sub_div(points,height/(i+1)) | |
var x = 0 | |
for x in width: | |
var p = (float(x) / float(width)) * (len(points)-1.0) | |
var min_point = floor(p) | |
var max_point = ceil(p) | |
var point = (p-min_point)*points[min_point] + (1-p-min_point)*points[max_point] | |
set_cell(x,point,0) | |
set_cell(x,point+1,0) | |
set_cell(x,point+2,0) | |
set_cell(x,point+3,0) | |
func sub_div(points,max_shift): | |
var out_points = [] | |
for i in range(len(points)-1): | |
out_points.append(points[i]) | |
var new_point = randf() * max_shift + (points[i] + points[i+1]) / 2 | |
out_points.append(new_point) | |
out_points.append(points[-1]) | |
return out_points |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment