-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManager.cs
More file actions
46 lines (32 loc) · 939 Bytes
/
GameManager.cs
File metadata and controls
46 lines (32 loc) · 939 Bytes
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
using Godot;
using System;
using System.IO;
public partial class GameManager : Node
{
public static GameManager Instance;
[Export] PackedScene barrierScene;
[Export] float gapBetweenBarriers = 1300f;
[Export] Vector2 spawnHeightRange = new Vector2(150f, 550f);
[Export] FlappyBody player;
private float lastPlayerX = 0f;
private float playersXTally = 0f;
private int score = 0;
private int highScore = 0;
public override void _Ready()
{
Instance = this;
}
public override void _Process(double delta)
{
playersXTally += player.Position.X - lastPlayerX;
lastPlayerX = player.Position.X;
if (playersXTally >= gapBetweenBarriers)
{
playersXTally = 0f;
Node2D barrier = barrierScene.Instantiate<Node2D>();
AddChild(barrier);
float yPos = (float)GD.RandRange(spawnHeightRange.X, spawnHeightRange.Y);
barrier.Position = new Vector2(player.Position.X + gapBetweenBarriers, yPos);
}
}
}