-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestScript.gd
More file actions
100 lines (90 loc) · 2.5 KB
/
Copy pathTestScript.gd
File metadata and controls
100 lines (90 loc) · 2.5 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
extends Node
onready var Creature = preload("res://Creature/Creature.tscn")
onready var Food = preload("Food.tscn")
var food_frequency = 35
var food_counter = 0
var food_queue : Array = Array()
var scarcity_counter = 0
func _ready():
var _error = self.connect("tree_exiting", self, "on_quit")
randomize()
#food_timer = Timer.new()
#food_timer.connect("timeout", self, "on_food_timer")
#add_child(food_timer)
#food_timer.start(-1.0/food_frequency)
var bp = Base_Proteins.Base_Proteins
Proteins.init(bp)
print("creature 1")
creature_from_blueprint(
[
[bp.organ_mouth],
[bp.new_part, [255, 128, 128]],
[bp.organ_mouth],
[bp.to_parent],
[bp.new_part, [128, 128, 255]],
[bp.organ_mouth],
[bp.to_parent],
[bp.new_part, [0, 128, 128]],
[bp.organ_mouth],
[bp.to_parent],
[bp.new_part, [128, 128, 0]],
[bp.organ_mouth],
])
print("creature 2")
creature_from_blueprint(
[
[bp.organ_mouth],
[bp.new_part, [255, 128, 128]],
[bp.articulation, [100, 200, 300, 400, 500, 600, 700, 800, 900, 2]],
[bp.grow, [250]],
[bp.to_parent],
[bp.new_part, [0, 128, 128]],
[bp.organ_mouth],
])
print("creature 3")
creature_from_blueprint(
[
[bp.organ_mouth],
[bp.new_part, [255, 128, 128]],
[bp.articulation, [100, 200, 300, 400, 500, 600, 700, 800, 900, 2]],
])
# creature_from_string("3,1,255,128,130,3,5,1,3,5,1,128,128,255,3,5,128,128,3,128,3")
func on_quit():
print("quitting")
func creature_from_blueprint(blueprint):
var c = Creature.instance()
var t = c.get_transform()
t.origin += Vector3(randf()*20-10, 2, randf()*20-10)
c.set_transform(t)
add_child(c)
c.init_blueprint(blueprint)
func creature_from_string(genome_string):
var t = Vector3(0,0,0)
creature_from_genome(Genetics.genome_from_string(genome_string), t)
func creature_from_genome(genome, position : Vector3):
var c = Creature.instance()
var t = c.get_transform()
t.origin = Vector3(position.x + randf()*2-1, position.y + 5, position.z + randf()*2-1)
c.set_transform(t)
add_child(c)
c.genome = genome
c.init()
func _process(delta):
food_counter += delta
if(food_counter <= 1.0/food_frequency):
return
food_counter = 0
create_food(Vector3(randf()*200-100, 10, randf()*200-100))
if randf()*10000 > scarcity_counter:
create_food(Vector3(randf()*50-25, 10, randf()*50-25))
scarcity_counter += 1
func create_food(position):
var f
if food_queue.empty():
f = Food.instance()
else:
f = food_queue.pop_front()
add_child(f)
var t = f.get_transform()
t.origin = position
f.set_transform(t)