-
Notifications
You must be signed in to change notification settings - Fork 0
/
Canon.cs
71 lines (62 loc) · 1.62 KB
/
Canon.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
using Godot;
using System;
using System.Diagnostics.Contracts;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
public partial class Canon : Path2D
{
Godot.Timer timer;
PathFollow2D path;
GpuParticles2D particles;
Polygon2D ball;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
path = GetNode<PathFollow2D>("PathFollow2D");
ball = path.GetNode<Polygon2D>("CanonArea/Polygon2D");
ball.Visible = false;
particles = path.GetNode<GpuParticles2D>("CanonArea/Crash Particles");
timer = new Godot.Timer();
timer.WaitTime = 1;
timer.Autostart = false;
timer.Timeout += Timer_Timeout;
AddChild(timer);
}
private void Timer_Timeout()
{
CanShoot = true;
path.ProgressRatio = 0;
timer.Stop();
}
public bool CanShoot { get; private set; } = true;
private bool isShooting;
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if(isShooting)
{
path.Progress = (float)(path.Progress + delta * 1000);
if(path.ProgressRatio >= 0.95f)
{
isShooting = false;
particles.Emitting = true;
ball.Visible = false;
timer.Start();
}
}
}
public void Crashed()
{
particles.Emitting = true;
ball.Visible = false;
timer.Start();
}
public void Shoot()
{
ball.Visible = true;
isShooting = true;
CanShoot = false;
}
}