-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.gd
71 lines (56 loc) · 2.14 KB
/
Level.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
extends Node2D
var n_lights
var chance_bugs
var chance_butterfly
var winning_score
# Called when the node enters the scene tree for the first time.
var rng = RandomNumberGenerator.new()
func _ready():
n_lights = get_node("/root/GLOBAL").n_lights
chance_bugs = get_node("/root/GLOBAL").chance_bugs
chance_butterfly = get_node("/root/GLOBAL").chance_butterfly
winning_score = get_node("/root/GLOBAL").winning_score
for i in range(n_lights):
var x = load("res://Lamp.tscn").instance()
rng.randomize()
x.position.x = rng.randi_range(30, 226)
rng.randomize()
x.position.y = rng.randi_range(30,120)
get_node("Lamps").add_child(x)
func spawn_bug(position):
rng.randomize()
var bug_pos = Vector2(rng.randi_range(position.x -15, position.x+15), rng.randi_range(position.y -15, position.y+15))
var bug = load("res://Bug.tscn").instance()
bug.global_position = bug_pos
bug.points = rng.randi_range(1,4)
get_node("Bugs").add_child(bug)
func spawn_butterfly(position):
rng.randomize()
var bug_pos = Vector2(rng.randi_range(position.x -15, position.x+15), rng.randi_range(position.y -15, position.y+15))
var bug = load("res://Butterfly.tscn").instance()
bug.global_position = bug_pos
bug.points = rng.randi_range(1,4)
get_node("Bugs").add_child(bug)
var space_pressed = false
func _process(delta):
if Input.is_action_just_pressed("ui_accept"):
space_pressed = true
if space_pressed:
get_tree().get_root().get_node("World/Data").lights_on = not get_tree().get_root().get_node("World/Data").lights_on
space_pressed = false
if get_tree().get_root().get_node("World/Data").game_state == get_tree().get_root().get_node("World/Data").win_state.PLAYING:
var roll : float
for child in get_node("Lamps").get_children():
if get_tree().get_root().get_node("World/Data").lights_on:
rng.randomize()
if chance_bugs > 0:
roll = rng.randf_range(0.0,1.0)
if roll <= 1.0/chance_bugs:
spawn_bug(child.position)
rng.randomize()
if chance_butterfly > 0:
roll = rng.randf_range(0.0,1.0)
if roll <= 1.0/chance_butterfly:
spawn_butterfly(child.position)
func _on_TextureButton_pressed():
space_pressed = true