-
Notifications
You must be signed in to change notification settings - Fork 0
/
AirGate.cs
151 lines (138 loc) · 4.08 KB
/
AirGate.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
138
139
140
141
142
143
144
145
146
147
148
149
using Godot;
using System;
public partial class AirGate : Node2D
{
[Export]
public bool isMovable = false;
private enum F {Front, Back, None};
private F lastEnteredFrom = F.None;
private enum D{Left, Right};
private D currentDirection = D.Left;
private float startX, startY;
private int moveRange;
private int moveSpeed;
/*
* If the plane touches the pylon any apparent valid pass
* should not be counted.
*/
private bool hasExplodedJustBefore = false;
public override void _Ready()
{
if (isMovable) {
startX = Position.X;
startY = Position.Y;
moveRange = Levels.getLevelInfo(Levels.Info.ArrowInterval);
moveSpeed = 50;
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (isMovable) {
if (Position.X <= (startX - moveRange) && currentDirection == D.Right)
{
currentDirection = D.Left;
}
else if (Position.X >= (startX + moveRange) && currentDirection == D.Left)
{
currentDirection = D.Right;
}
if (currentDirection == D.Left)
{
Vector2 v = new Vector2((float)(moveSpeed * delta), 0);
v = v.Rotated(this.Rotation);
Position += v;
}
else if (currentDirection == D.Right)
{
Vector2 v = new Vector2((float)(-moveSpeed * delta), 0);
v = v.Rotated(this.Rotation);
Position += v;
}
}
}
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 (hasExplodedJustBefore) {
hasExplodedJustBefore = false;
return;
}
if (area is Plane)
{
if (lastEnteredFrom == F.Front)
{
lastEnteredFrom = F.None;
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 = ((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} = {points} pontos";
GetNode<Label>("/root/RootScene/GameScene/HUD/AquiredPoints").Visible = true;
GetNode<AnimationPlayer>("/root/RootScene/GameScene/HUD/AquiredPoints/AnimationPlayer").Play("AppearAndDisappear");
}
else
{
lastEnteredFrom = F.Back;
}
}
}
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, 3);
}
}
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;
}
}