-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectController.gd
51 lines (38 loc) · 1.31 KB
/
ObjectController.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
extends Node2D
export (PackedScene) var Object1
export (PackedScene) var Object2
export (PackedScene) var Object3
export (PackedScene) var Object4
var velocidad_por_nivel = 70
func _ready():
velocidad_por_nivel = 70
func _on_ObjectTimer_timeout():
var random_num = randi() % 100
var obj
if random_num < 40:
obj = Object1.instance()
elif random_num >= 40 and random_num < 80:
obj = Object2.instance()
elif random_num >=80 and random_num < 85:
obj = Object3.instance()
# Choose a random location on ObjPath
var obj_spawn_location = get_node("ObjPath/ObjSpawnLocation")
obj_spawn_location.offset = randi()
# Set the objects's direction perpendicular to the path direction.
var direction = obj_spawn_location.rotation + PI / 2
# Set the object's position to a random location.
obj.position = obj_spawn_location.position
# Choose the velocity for the object
var velocity = Vector2(velocidad_por_nivel, 0.0)
obj.linear_velocity = velocity.rotated(direction)
# Spawn the object by adding it to the Main scene.
add_child(obj)
# Objects dissappear when leaving the screen
func _on_VisibilityNotifier2D_screen_exited():
queue_free()
# Hide objects when collide with player
func on_hide_obj():
queue_free()
#cambio de velocidad por nivel
func _on_personaje_cambio_velocidad_objetos():
velocidad_por_nivel += 60