-
Notifications
You must be signed in to change notification settings - Fork 0
/
AirGateNarrow.cs
130 lines (117 loc) · 3.69 KB
/
AirGateNarrow.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
using Godot;
using System;
public partial class AirGateNarrow : Node2D
{
enum F {Front, Back, None};
F lastEnteredFrom = F.None;
/*
* If the plane touches the pylon any apparent valid pass
* should not be counted.
*/
private bool hasExplodedJustBefore = false;
private void _on_front_area_entered(Area2D area)
{
if (hasExplodedJustBefore) {
hasExplodedJustBefore = false;
return;
}
if (area is Plane)
{
if (lastEnteredFrom == F.Back)
{
lastEnteredFrom = F.None;
GetNode<Game>("/root/Game").Health -= Levels.getLevelInfo(Levels.Info.LoseHealthSpeed);
var b = GetNode<Banner>("/root/Banner");
b.showUpperBanner("Sentido errado!", bad: true);
}
else
{
lastEnteredFrom = F.Front;
}
}
}
private void _on_back_area_entered(Area2D area)
{
if (area is Plane)
{
if (hasExplodedJustBefore) {
hasExplodedJustBefore = false;
return;
}
Plane plane = (Plane)area;
if (lastEnteredFrom == F.Front)
{
lastEnteredFrom = F.None;
if (Math.Abs(plane.HeadingSpeed) > 1.0f)
{
float distanceF = GetNode<Path2D>("/root/RootScene/GameScene/AirPath").Curve.GetClosestPoint(area.Position).DistanceSquaredTo(area.Position);
int distance = (int)Math.Round(distanceF) / 10;
int speed = GetNode<Game>("/root/Game").Speed;
int points = 3 * ((int)speed - distance);
GetNode<Game>("/root/Game").Score += points;
// GetNode<AudioStreamPlayer>("/root/RootScene/GameScene/Audio/AirGatePassSFX").Play();
GetNode<Label>("/root/RootScene/GameScene/HUD/AquiredPoints").Text = $"(Veloc:{speed} - Dist:{distance}) x 3 = {points} pontos";
GetNode<Label>("/root/RootScene/GameScene/HUD/AquiredPoints").Visible = true;
GetNode<AnimationPlayer>("/root/RootScene/GameScene/HUD/AquiredPoints/AnimationPlayer").Play("AppearAndDisappear");
GetNode<AudioStreamPlayer>("/root/RootScene/GameScene/Audio/AirGateNarrowPassSFX").Play();
var b = GetNode<Banner>("/root/Banner");
b.showUpperBanner("Perfeito!");
}
else
{
GetNode<Game>("/root/Game").Health -= 1;
GetNode<Game>("/root/Game").Score -= 100;
var b = GetNode<Banner>("/root/Banner");
b.showUpperBanner("Passe com a asa inclinada!", bad: true, AudioName: "passe com a asa inclinada", audioDelay: 0);
}
}
else
{
lastEnteredFrom = F.Back;
}
}
}
private void _on_gate_area_entered(Area2D area)
{
if (area is Plane)
{
GetNode<Game>("/root/Game").Score -= 100;
}
}
private void Explode(Area2D area, String leftOrRight) {
if (area is Plane)
{
hasExplodedJustBefore = true;
GetNode<Game>("/root/Game").Score -= 100 * Levels.getLevelInfo(Levels.Info.LoseHealthSpeed);
GetNode<Game>("/root/Game").Health -= Levels.getLevelInfo(Levels.Info.LoseHealthSpeed);
GetNode<AnimatedSprite2D>("Gate" + leftOrRight + "/Explosion").Visible = true;
GetNode<AnimatedSprite2D>("Gate" + leftOrRight + "/Explosion").Play();
GetNode<Godot.Timer>("Gate" + leftOrRight + "/ExplosionTimer").Start();
GetNode<AudioStreamPlayer>("/root/RootScene/GameScene/Audio/FireSFX").Play();
var b = GetNode<Banner>("/root/Banner");
b.showUpperBanner("Atingiu o pylon!", bad: true, "opa você atingiu o pylon", 0.5);
}
}
private void _on_right_area_entered(Area2D area)
{
if (hasExplodedJustBefore) {
return;
}
Explode(area, "Right");
}
private void _on_left_gate_area_entered(Area2D area)
{
if (hasExplodedJustBefore) {
return;
}
Explode(area, "Left");
}
private void _on_explosion_left_timer_timeout()
{
GetNode<AnimatedSprite2D>("GateLeft/Explosion").Visible = false;
}
private void _on_explosion_right_timer_timeout()
{
GetNode<AnimatedSprite2D>("GateRight/Explosion").Visible = false;
}
}