-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
137 lines (111 loc) · 3.91 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Godot;
using System;
using System.Linq;
public partial class Main : Node2D
{
PackedScene Boat;
Timer waveTimer = new Timer();
Timer adamastorTimer = new Timer();
Node2D rogueWave;
Camera2D camera;
PackedScene AdamastorScene;
Adamastor Adamastor;
Canon Cannon;
PopupPanel GameOverPopup;
PopupPanel GameWonPopup;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
waveTimer.WaitTime = 2;
waveTimer.Timeout += WaveTimer_Timeout;
AddChild(waveTimer);
waveTimer.Start();
adamastorTimer.WaitTime = 6;
adamastorTimer.Timeout += Adamastor_Timeout;
AddChild(adamastorTimer);
camera = GetNode<Camera2D>("Camera2D");
Boat = (PackedScene)ResourceLoader.Load("res://boat.tscn");
AdamastorScene = (PackedScene)ResourceLoader.Load("res://Adamastor.tscn");
AddChild(Boat.Instantiate());
AddChild(AdamastorScene.Instantiate());
GameOverPopup = GetNode<PopupPanel>("Game Over Popup");
GameWonPopup = GetNode<PopupPanel>("Game Won Popup");
GameOverPopup.GetNode<Button>("Node2D/Button").Pressed += TryAgainPressed;
GameWonPopup.GetNode<Button>("Node2D/Button").Pressed += TryAgainPressed;
Adamastor = GetNode<Adamastor>("AdamastorRoot/Adamastor");
var rogueWaveScene = (PackedScene)ResourceLoader.Load("res://roguewave.tscn");
rogueWave = (Node2D) rogueWaveScene.Instantiate();
var newWave = (RogueWave)rogueWave.Duplicate();
newWave.camera = camera;
var randomY = new Random().Next(0, (int)(camera.GetViewportRect().End.Y - newWave.GetNode<Polygon2D>("PathFollow2D/Wave/Body").Polygon.Max(x => x.Y)));
newWave.GlobalPosition = new Vector2(camera.GlobalPosition.X + 500, randomY);
AddChild(newWave);
}
private void TryAgainPressed()
{
GameOverPopup.Hide();
GetTree().ReloadCurrentScene();
}
private void Adamastor_Timeout()
{
Random random = new Random();
Adamastor.PlayAnimation(random.Next(0, Adamastor.AnimationCount - 1));
}
private void WaveTimer_Timeout()
{
var newWave = (RogueWave)rogueWave.Duplicate();
newWave.camera = camera;
var randomY = new Random().Next(0, (int)(camera.GetViewportRect().End.Y - newWave.GetNode<Polygon2D>("PathFollow2D/Wave/Body").Polygon.Max(x => x.Y)));
newWave.GlobalPosition = new Vector2(camera.GlobalPosition.X + 750, randomY);
AddChild(newWave);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void GameWon()
{
adamastorTimer.Stop();
waveTimer.Stop();
var children = GetChildren();
foreach (var child in children)
{
if (child is RogueWave wave)
{
wave.GameOver();
}
}
GameWonPopup.Show();
}
public void GameOver()
{
adamastorTimer.Stop();
waveTimer.Stop();
var children = GetChildren();
foreach (var child in children)
{
if (child is RogueWave wave)
{
wave.GameOver();
}
}
GameOverPopup.Show();
}
public void ArrivedAtEnd()
{
adamastorTimer.Start();
}
public void StopWaves()
{
waveTimer.Stop();
}
public void CreatWaveAt(Vector2 position)
{
var newWave = (RogueWave)rogueWave.Duplicate();
newWave.camera = camera;
var waveHeight = newWave.GetNode<Polygon2D>("PathFollow2D/Wave/Body").Polygon.Max(x => x.Y);
newWave.GlobalPosition = new Vector2(position.X - newWave.Curve.GetBakedLength() + newWave.GetNode<Polygon2D>("PathFollow2D/Wave/Body").Polygon.Max(x => x.X), position.Y);
AddChild(newWave);
newWave.Visible = true;
}
}