|
|
|
|
Reply From: |
unholy182000 |
extends Node2D
var newMoto = load("res://SCENES/Moto.tscn")
var moto; var width = 1024; var height = 600
var lines = []; var col; var grass; var road; var border; var divid_line
var pos = 0; var num; var skyline; var skln_pos = 0; var skln_h = 0
export var road_width = 2000
export var seg = 200
export var cam = 0.8
func _ready():
moto = newMoto.instance()
add_child(moto)
moto.set_position(Vector2(width/2+50, height-100))
moto.set_scale(Vector2(2, 2))
skyline = $Sprite
skyline.set_region(true)
skyline.set_z_index(-1)
for i in range(1600):
lines.push_back({x = 0, y = 0, z = 0, X = 0, Y = 0, W = 0, scale = 0, curve = 0 })
lines[i].z = i*seg
if (i>300 && i<700):
lines[i].curve = 0.5
if (i>800 && i<1200):
lines[i].curve = -0.7
if (i>750):
lines[i].y = sin(i/30.0 - 25)*1500
if (i>1200):
lines[i].curve = 0.2
num = lines.size()
set_process(true)
func line(Line,cam_x,cam_y,cam_z):
Line.scale = cam / (Line.z - cam.z)
Line.X = (1 + Line.scale*(Line.x - cam_x)) * width/2
Line.Y = (1 + Line.scale*(Line.y - cam_y)) * height/2
Line.W = Line.scale * road_width * (width/2)
return Line
func drawRoad(col,x1,y1,w1,x2,y2,w2):
var point = [Vector2(int(x1-w1), int(y1)), Vector2(int(x2-w2), int(y2)),
Vector2(int(x2+w2), int(y2)), Vector2(int(x1+w1), int(y1))]
draw_primitive(PoolVector2Array(point), PoolColorArray([col,col,col,col,col]), PoolVector2Array([]))
func _draw():
pos += 200
if pos == 320000:
pos = 0
while (pos >= num*seg):
pos -=num*seg
while (pos < 0):
pos += num*seg
var num_pos = 0
var start_point = pos/seg
var cam_h = 1500 + lines[start_point].y
var cutoff = height
var x = 0
var dx = 0
skln_pos +=lines[start_point].curve * 2.0
skln_h = -lines[start_point].y * 0.005
skyline.set_region_rect(Rect2(skln_pos, skln_h, 1920, 320))
var dir = lines[start_point].curve
if dir >= 0.5:
moto.rule = 3
# moto.img.set_hidden(false)
moto.img.show()
if dir < 0.5 and dir > -0.5:
moto.rule = 2
# moto.img.set_hidden(false)
moto.img.show()
if dir <= - 0.5:
moto.rule = 1
# moto.img.set_hidden(false)
moto.img.show()
for n in range (start_point, start_point + 300):
if n >= num:
num_pos = num * seg
else:
num_pos = 0
var l = line(lines[fmod(n,num)], -x, cam_h, pos - num_pos)
var p = lines[fmod(n-1, num)]
x += dx
dx += l.curve
if l.Y >= cutoff:
continue
cutoff = l.Y
if fmod((n/3),2):
border = Color(1,1,1)
road = Color(.42,.42,.42)
else:
border = Color(0,0,0)
road = Color(.4,.4,.4)
if fmod((n/9),2):
divid_line = Color(0,0,0)
grass = Color(.2,.2,.2)
else:
divid_line = Color(1,1,1)
grass = Color(.8,.8,.8)
drawRoad(grass, 0, p.Y, width, 0, l.Y, width)
drawRoad(border, p.X, p.Y, p.W*1.2, l.X, l.Y, l.W*1.2)
drawRoad(road, p.X, p.Y, p.W, l.X, l.Y, l.W)
drawRoad(divid_line, p.X, p.Y, p.W*0.01, l.X, l.Y, l.W*0.01)
func _process(delta):
update()