-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.gd
53 lines (32 loc) · 1.54 KB
/
GameManager.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
extends Node2D
var game_started : bool = false
@onready var player : Area2D = get_parent().get_node("Player")
@onready var screen_middle : Node2D = get_parent().get_node("ScreenMiddle")
@onready var screen_bottom : Node2D = get_parent().get_node("ScreenMiddle/ScreenBottom")
@onready var screen_top : Node2D = get_parent().get_node("ScreenMiddle/ScreenTop")
@onready var screen_left : Node2D = get_parent().get_node("ScreenMiddle/ScreenLeft")
@onready var screen_right : Node2D = get_parent().get_node("ScreenMiddle/ScreenRight")
var obstacle : PackedScene = preload("res://Prefabs/obstacle_parent.tscn")
@export var obstacle_gap : float = 500
var last_generated_obstacle_pos : float
@export var min_obstacle_spawn_Y : float = 200
@export var max_obstacle_spawn_Y : float = -200
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if(Input.is_action_just_pressed("jump")):
game_started = true
if (player.position.y > screen_bottom.position.y):
game_started = false
if (screen_middle.position.x > last_generated_obstacle_pos + obstacle_gap):
generate_obstacle()
last_generated_obstacle_pos = screen_middle.position.x
screen_middle.position.x = player.position.x
pass
func generate_obstacle():
var o = obstacle.instantiate()
get_parent().add_child(o)
o.position = Vector2(screen_right.global_position.x + 100, randf_range(min_obstacle_spawn_Y, max_obstacle_spawn_Y))
pass