-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
195 lines (159 loc) · 4.5 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
using System;
using SplashKitSDK;
public class Player
{
public int Score { get; set; } = 0;
public string Name { get; set; }
public double X { get; private set; }
public double Y { get; private set; }
public double Radius { get; set; } = 10;
public Circle c;
private Color PlayerColor;
private int Boost = 0;
private int Speed = 5;
private bool PlayerWrapAroundTheWindow = false;
private int _NameWidth;
private SoundEffect GoodSound = new SoundEffect("pop", "pop.wav");
private SoundEffect BadSound = new SoundEffect("beep", "beep.wav");
public Player(Window gameWindow, string name)
{
X = gameWindow.Width / 2;
Y = gameWindow.Height / 2;
Name = name;
PlayerColor = SplashKit.RandomRGBColor(200);
_NameWidth = SplashKit.TextWidth(name, "Arial", 10);
}
public void Draw()
{
SplashKit.FillCircle(PlayerColor, X, Y, Radius);
c = SplashKit.CircleAt(X, Y, Radius);
SplashKit.DrawText(Name, Color.Black, X - _NameWidth / 2, Y - Radius - 8);
SplashKit.DrawText(Convert.ToString(Score), Color.Black, X - 3, Y + Radius);
//SplashKit.DrawText($"X:{X}, Y:{Y}", Color.Black, 5, 20);
}
public bool Quit { get; private set; }
public void HandleInput()
{
if (SplashKit.KeyReleased(SplashKitSDK.KeyCode.IKey))
{
if (Boost <= 5)
{
Boost++;
if (Boost >= 6)
{
Boost = 1;
}
}
switch (Boost)
{
case 1:
Speed = 5;
break;
case 2:
Speed = 10;
break;
case 3:
Speed = 15;
break;
case 4:
Speed = 20;
break;
case 5:
Speed = 50;
break;
}
}
if (SplashKit.KeyDown(SplashKitSDK.KeyCode.EscapeKey))
{
Quit = true;
}
if (SplashKit.QuitRequested())
{
Quit = true;
}
if (SplashKit.KeyDown(SplashKitSDK.KeyCode.LeftKey) || SplashKit.KeyDown(SplashKitSDK.KeyCode.AKey))
{
X -= Speed;
}
if (SplashKit.KeyDown(SplashKitSDK.KeyCode.RightKey) || SplashKit.KeyDown(SplashKitSDK.KeyCode.DKey))
{
X += Speed;
}
if (SplashKit.KeyDown(SplashKitSDK.KeyCode.UpKey) || SplashKit.KeyDown(SplashKitSDK.KeyCode.WKey))
{
Y -= Speed;
}
if (SplashKit.KeyDown(SplashKitSDK.KeyCode.DownKey) || SplashKit.KeyDown(SplashKitSDK.KeyCode.SKey))
{
Y += Speed;
}
}
public void StayOnWindow(Window gameWindow)
{
int windowWidth = gameWindow.Width;
int windowHeight = gameWindow.Height;
if (!PlayerWrapAroundTheWindow)
{
//Player stops at Boundary
if (X - Radius <= 0)
{
X = Radius;
}
if (X + Radius >= (windowWidth))
{
X = windowWidth - Radius;
}
if (Y - Radius <= 0)
{
Y = Radius;
}
if (Y + Radius >= windowHeight)
{
Y = windowHeight - Radius;
}
//Player stops at Boundary
}
else
{
//Player wrap around the screen
if (X + Radius < 0)
{
X = windowWidth;
}
if (X > windowWidth)
{
X = -Radius;
}
if (Y + Radius < 0)
{
Y = windowHeight;
}
if (Y > windowHeight)
{
Y = -Radius;
}
//Player wrap around the screen
}
}
public bool CollidedWithRandomDots(RandomDots randomDots)
{
return SplashKit.CirclesIntersect(c, randomDots.CollisionCircle);
}
public bool CollidedWithPlayer(Player player)
{
//TODO: chang it, make it work
return false;
}
public bool CollidedWithPlayer(OtherPlayer op)
{
return SplashKit.CirclesIntersect(c, op.CollisionCircle);
}
public void PlayGoodSound()
{
GoodSound.Play();
}
public void PlayBadSound()
{
BadSound.Play();
}
}