-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrateVertical.cs
69 lines (55 loc) · 1.8 KB
/
CrateVertical.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
using Godot;
using System;
public class CrateVertical : KinematicBody2D {
[Export] public float TerminalVelocity = -80.0f;
[Export] public float Gravity = -320.0f;
public float verticalSpeed;
private Area2D area;
private Particles2D particles;
// Called when the node enters the scene tree for the first time.
public override void _Ready() {
area = GetNode<Area2D>("Swap");
area.Connect("body_entered", this, nameof(SwapEnter));
area.Connect("body_exited", this, nameof(SwapExit));
particles = GetNode<Particles2D>("Particles2D");
particles.Emitting = false;
}
public void Flip(bool flipped) {
Vector2 scale = this.Scale;
scale.y = flipped ? -1 : 1;
this.Scale = scale;
}
public bool PlayerColliding() {
return particles.Emitting;
}
public void Enable(bool enabled) {
Visible = enabled;
GetNode<CollisionShape2D>("CollisionShape2D").Disabled = !enabled;
area.GetNode<CollisionShape2D>("CollisionShape2D").Disabled = !enabled;
}
public float MoveVertical(float delta) {
if (IsOnFloor()) {
verticalSpeed = 0.0f;
}
else {
if (verticalSpeed > TerminalVelocity) {
verticalSpeed += Gravity * delta;
if (verticalSpeed < TerminalVelocity) {
verticalSpeed = TerminalVelocity;
}
}
}
return verticalSpeed;
}
private void SwapEnter(Node body) {
particles.Emitting = true;
}
private void SwapExit(Node body) {
if (area.GetOverlappingBodies().Count <= 1) {
particles.Emitting = false;
}
}
public Godot.Collections.Array GetBodies() {
return area.GetOverlappingBodies();
}
}