-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
205 lines (168 loc) · 3.66 KB
/
Player.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using Godot;
using ld47;
public class Player : RigidBody2D
{
private Vector2 velocity = Vector2.Zero;
private bool canMoveForward = true;
[Export] private float speed = 100;
private bool run = false;
private Sprite warning;
private AnimatedSprite animater;
private bool canMoveBackWards = true;
private bool canMove = true;
private void _blockMovement()
{
this.canMove = false;
animater.Animation = "idle";
}
private void _unBlockMovement()
{
this.canMove = true;
}
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
warning = GetNode<Sprite>("warning");
animater = GetNode<AnimatedSprite>("PAnimlayer");
GetNode<SignalManager>("/root/SignalManager").Connect("BlockMovement", this, "_blockMovement");
GetNode<SignalManager>("/root/SignalManager").Connect("UnBlockMovement", this, "_unBlockMovement");
GetNode<SignalManager>("/root/SignalManager").Connect("HideWarning", this, "_hideWarning");
GetNode<SignalManager>("/root/SignalManager").Connect("ShowWarning", this, "_showWarning");
GetNode<SignalManager>("/root/SignalManager").Connect("HidePlayer", this, "_hidePlayer");
GetNode<SignalManager>("/root/SignalManager").Connect("UnhidePlayer", this, "_showPlayer");
}
private void _hidePlayer()
{
Visible = false;
}
private void _showPlayer()
{
Visible = true;
}
private void _hideWarning()
{
warning.Visible = false;
}
private void _showWarning()
{
warning.Visible = true;
}
public override void _Input(InputEvent inputEvent)
{
if (inputEvent.IsActionPressed("run"))
{
run = true;
}
if (inputEvent.IsActionReleased("run"))
{
run = false;
}
}
public override void _PhysicsProcess(float delta)
{
if (canMove == false)
{
return;
}
velocity = new Vector2();
if (Input.IsActionPressed("ui_right"))
{
velocity.x += 1;
}
if (Input.IsActionPressed("ui_left"))
{
velocity.x -= 1;
}
velocity = velocity.Normalized() * speed;
animater.SpeedScale = 1f;
if (run)
{
velocity *= 3f;
animater.SpeedScale = 2f;
}
if (canMoveForward == false && velocity.x < 0)
{
animater.Animation = "idle";
}
else if (canMoveBackWards == false && velocity.x > 0)
{
animater.Animation = "idle";
}
else
{
if (velocity == Vector2.Zero)
{
animater.Animation = "idle";
}
else
{
animater.Animation = "walking";
}
}
if (velocity.x > 0)
{
animater.FlipH = true;
}
else if (velocity.x != 0)
{
animater.FlipH = false;
}
}
private void _on_Area2D_body_exited(object body)
{
if (GetNode<State>("/root/State").HasState(Statetype.PHONE_DONE) == false)
{
canMoveForward = true;
}
else
{
canMoveForward = true;
warning.Visible = false;
}
}
private void _on_Area2D_body_entered(object body)
{
if (GetNode<State>("/root/State").HasState(Statetype.PHONE_DONE) == false)
{
canMoveForward = false;
}
else
{
canMoveForward = false;
warning.Visible = true;
}
}
private void _on_Phone_body_entered(object body)
{
warning.Visible = true;
}
private void _on_Phone_body_exited(object body)
{
warning.Visible = false;
}
private void _on_Blocker_body_entered(object body)
{
if (GetNode<State>("/root/State").HasState(Statetype.SLEEP_TALK) == false)
{
canMoveBackWards = false;
}
}
private void _on_Blocker_body_exited(object body)
{
canMoveBackWards = true;
}
private void _on_Phone_PhoneAwnserd(int test)
{
warning.Visible = false;
animater.Animation = "Phone";
this.canMove = false;
}
private void _on_Area2D_body_entered_alt()
{
canMoveBackWards = false;
}
private void _on_Area2D_body_exited_alt()
{
canMoveBackWards = true;
}
}