-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorld.gd
73 lines (63 loc) · 1.8 KB
/
World.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
const DIRECTION0:Vector2=Vector2(1,0)
var screensize:Vector2
var screencenter:Vector2
var radius:float=100
var roadlist=[]
func gamma_circle(p:float)->Vector2:
return Vector2(cos(2*PI*p),sin(2*PI*p))*radius+screencenter
#return Vector2(cos(2*PI*p),sin(2*PI*p))*p*radius+screencenter
#return Vector2(cos(4*PI*p),5*p)*100+screencenter-Vector2(0,250)
func frange(begin:float,end:float,discr:int):
var dx:float=(end-begin)/discr
var res=[]
for i in range(discr):
res+=[dx*i+begin]
return res
func orientate(roadobj:Sprite,grad:Vector2):
var direction:Vector2
var signe:float
var angle:float
if grad.length()==0:
direction=Vector2(1,0)
else:
direction=grad.normalized()
angle=acos(min(1,max(-1,DIRECTION0.dot(direction))))
signe=DIRECTION0.cross(direction)
if signe<0:
signe=-1
else:
signe=1
roadobj.rotation_degrees=signe*(angle/(2*PI))*360
pass
func create_road(discretisation:int):
var local_pos:Vector2
for p in frange(0,1,discretisation):
local_pos=gamma_circle(p)
var newRoad = Sprite.new()
newRoad.texture=load("res://roadV2.png")
newRoad.global_position = local_pos
newRoad.scale = Vector2(0.2,0.2)
add_child(newRoad)
orientate(newRoad,gamma_circle(p+0.0001)-gamma_circle(p))
roadlist+=[newRoad]
pass
# Called when the node enters the scene tree for the first time.
func _ready():
screensize=get_viewport().size
screencenter=screensize/2
#$Road.position=screencenter
#roadlist[0].global_position=screencenter
#print($Road)
#print(roadlist)
#roadlist[0].visible=true
#add_child(roadlist[0])
#print(DIRECTION0.cross(Vector2(0,-1)))
create_road(60)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass