-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoScreen.cs
227 lines (216 loc) · 7.65 KB
/
DemoScreen.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Slip
{
//WARNING: Absolutely horrible programming
public class DemoScreen : Screen
{
private int level;
private bool dead = false;
private Vector2 playerPos;
private Vector2[] turretPos;
private IList<Vector2> bulletPos = new List<Vector2>();
private IList<Vector2> bulletSpeed = new List<Vector2>();
private Vector2[] switchPos;
private bool[] switchPressed;
private bool win = false;
private long time = 0;
private float rainbow;
private Vector2 circleCenter;
private float circleAngle;
private float circleRadius;
private int numCircles;
public DemoScreen(int level = 2)
{
this.level = level;
}
public override void Initialize(Main main)
{
base.Initialize(main);
Reset();
}
public override void UpdateScreen(Main main)
{
if (dead)
{
Reset();
}
Vector2 velocity = Vector2.Zero;
if (Main.IsControlHeld(KeyControl.Up))
{
velocity.Y -= 1f;
}
if (Main.IsControlHeld(KeyControl.Down))
{
velocity.Y += 1f;
}
if (Main.IsControlHeld(KeyControl.Left))
{
velocity.X -= 1f;
}
if (Main.IsControlHeld(KeyControl.Right))
{
velocity.X += 1f;
}
if (velocity != Vector2.Zero)
{
velocity.Normalize();
velocity *= 4f;
playerPos += velocity;
}
foreach (Vector2 pos in turretPos)
{
if (Vector2.Distance(playerPos, pos) <= 20f)
{
dead = true;
}
if (!win && time > 0 && (time % (level > 2 ? 40 : 60) == 0))
{
bulletPos.Add(pos);
Vector2 speed = playerPos - pos;
if (speed == Vector2.Zero)
{
speed = new Vector2(0f, 1f);
}
else
{
speed.Normalize();
}
speed *= 4f;
bulletSpeed.Add(speed);
if (bulletPos.Count > 60)
{
bulletPos.RemoveAt(0);
bulletSpeed.RemoveAt(0);
}
}
}
for (int k = 0; k < bulletPos.Count; k++)
{
bulletPos[k] += bulletSpeed[k];
if (Vector2.Distance(playerPos, bulletPos[k]) <= 15f)
{
dead = true;
}
}
for (int k = 0; k < switchPos.Length; k++)
{
if (Vector2.Distance(playerPos, switchPos[k]) <= 20f)
{
switchPressed[k] = true;
win = true;
foreach (bool pressed in switchPressed)
{
if (!pressed)
{
win = false;
break;
}
}
if (win)
{
bulletPos.Clear();
bulletSpeed.Clear();
}
}
}
if (level > 1 && !win)
{
circleRadius -= 1f;
if (circleRadius < 0f)
{
circleAngle = 0f;
circleRadius = 150f;
circleCenter = playerPos;
}
circleAngle += 0.03f;
for (int k = 0; k < numCircles; k++)
{
float angle = circleAngle + k * 2f * (float)Math.PI / numCircles;
Vector2 pos = circleCenter + circleRadius * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
if (Vector2.Distance(playerPos, pos) <= 15f)
{
dead = true;
}
}
}
rainbow += 0.001f;
rainbow %= 1f;
time++;
}
private void Reset()
{
dead = false;
time = 0;
playerPos = Vector2.Zero;
turretPos = new Vector2[] { new Vector2(-250f, -250f), new Vector2(250f, -250f), new Vector2(-250f, 250f), new Vector2(250f, 250f) };
bulletPos.Clear();
bulletSpeed.Clear();
switchPos = new Vector2[] { new Vector2(0f, -400f), new Vector2(-400f, 0f), new Vector2(400f, 0f), new Vector2(0f, 400f) };
switchPressed = new bool[] { false, false, false, false };
win = false;
if (level > 1)
{
circleCenter = Vector2.Zero;
circleAngle = 0f;
circleRadius = 150f;
numCircles = 5;
if (level > 2)
{
numCircles++;
}
}
}
public override void DrawScreen(Main main)
{
main.spriteBatch.Draw(playerTexture, main.Center(), null, Color.White, playerTexture.Center());
foreach (Vector2 pos in turretPos)
{
main.spriteBatch.Draw(turretTexture, DrawPos(main, pos), null, Color.White, turretTexture.Center());
}
foreach (Vector2 pos in bulletPos)
{
main.spriteBatch.Draw(bulletTexture, DrawPos(main, pos), null, Color.White, bulletTexture.Center());
}
for (int k = 0; k < switchPressed.Length; k++)
{
Texture2D texture = switchPressed[k] ? switchPressedTexture : switchTexture;
main.spriteBatch.Draw(texture, DrawPos(main, switchPos[k]), null, Color.White, texture.Center());
}
if (level > 1 && !win)
{
for (int k = 0; k < numCircles; k++)
{
float angle = circleAngle + k * 2f * (float)Math.PI / numCircles;
Vector2 pos = circleCenter + circleRadius * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
main.spriteBatch.Draw(bulletTexture, DrawPos(main, pos), null, Color.White, bulletTexture.Center());
}
}
}
public Vector2 DrawPos(Main main, Vector2 pos)
{
return size / 2f + pos - playerPos;
}
public override Color BackgroundColor()
{
return win ? Helper.FromHSB(rainbow, 1f, 1f) : Color.Black;
}
private Texture2D playerTexture;
private Texture2D turretTexture;
private Texture2D bulletTexture;
private Texture2D switchTexture;
private Texture2D switchPressedTexture;
public override void LoadContent(ContentManager loader)
{
playerTexture = loader.Load<Texture2D>("Demo/Player");
turretTexture = loader.Load<Texture2D>("Demo/Turret");
bulletTexture = loader.Load<Texture2D>("Demo/Bullet");
switchTexture = loader.Load<Texture2D>("Demo/Switch");
switchPressedTexture = loader.Load<Texture2D>("Demo/SwitchPressed");
}
}
}