-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cs
59 lines (49 loc) · 1.48 KB
/
Main.cs
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
using Godot;
using System;
public class Main : Node2D
{
private int _score;
[Signal]
private delegate void BeginRound();
public override void _Ready()
{
GetNode<AudioStreamPlayer>("bg_music").Play();
}
// Called when the node enters the scene tree for the first time.
public void NewGame()
{
_score = 0;
var player = GetNode<Player>("Player");
var board = GetNode<GameBoard>("GameBoard");
var playerStartPos = GetNode<Position2D>("StartPosition");
var brickStartPos = GetNode<Position2D>("BrickPosition");
board.Start(brickStartPos.Position);
player.Start(playerStartPos.Position);
GetNode<Timer>("CountdownTimer").Start();
var hud = GetNode<HUD>("HUD");
hud.NewGameSetup();
}
async public void GameOver()
{
GetNode<GameBoard>("GameBoard").Reset();
GetNode<Ball>("Ball").ClearBall();
GetNode<HUD>("HUD").Reset(_score);
await ToSignal(GetTree().CreateTimer(2), "timeout");
GetNode<Button>("HUD/StartButton").Show();
GetNode<Ball>("Ball").Start();
}
public void OnCountdownTimerTimeout()
{
EmitSignal("BeginRound");
}
public void IncrementScore()
{
_score++;
GetNode<HUD>("HUD").UpdateScore(_score);
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
// public override void _Process(float delta)
// {
//
// }
}