1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Data;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Threading.Tasks;
|
---|
9 | using System.Windows.Forms;
|
---|
10 |
|
---|
11 |
|
---|
12 | using Microsoft.Kinect;
|
---|
13 | using Newtonsoft.Json;
|
---|
14 | using NAudio.Wave;
|
---|
15 | using MicroLibrary;
|
---|
16 | using System.IO;
|
---|
17 | using System.Diagnostics;
|
---|
18 |
|
---|
19 | using System.Drawing.Drawing2D;
|
---|
20 |
|
---|
21 | namespace FFTDDR
|
---|
22 | {
|
---|
23 | public partial class Form1 : Form
|
---|
24 | {
|
---|
25 |
|
---|
26 | int debugCounter = 0;
|
---|
27 |
|
---|
28 | // UI
|
---|
29 | BeatPicturebox screen;
|
---|
30 | Label songNameLabel, difficultyLabel, scoreLabel, scoreNameLabel, multiplierLabel, multiplierNameLabel;
|
---|
31 | //0 = Choose song. 1 = choose difficulty. 2 = play game.
|
---|
32 | int menuMode;
|
---|
33 | List<Label> songOptions, difficultyOptions;
|
---|
34 | int menuCursor = 0;
|
---|
35 | bool continueAvaliable = true;
|
---|
36 | Timer continueTimer;
|
---|
37 | int circleRadius = 400;
|
---|
38 |
|
---|
39 | PictureBox beatBoxLeft, beatBoxRight;
|
---|
40 |
|
---|
41 | PictureBox footLeft, footRight;
|
---|
42 |
|
---|
43 | // Song variables
|
---|
44 |
|
---|
45 | String[] songLocations;
|
---|
46 | List<WaveFileReader> reader;
|
---|
47 | List<WaveOut> output;
|
---|
48 | List<string[]> wavInfo;
|
---|
49 | List<WavFrame> frames;
|
---|
50 |
|
---|
51 | SkeletonManager skeletonManager;
|
---|
52 |
|
---|
53 |
|
---|
54 | // Kinect
|
---|
55 | KinectSensor sensor;
|
---|
56 | Skeleton[] skeletonArray;
|
---|
57 |
|
---|
58 | // Player info
|
---|
59 | int playerQuadrentLeft, playerQuadrentRight;
|
---|
60 | List<FootStep> footstepList;
|
---|
61 | private float xCoordLeft, yCoordLeft, xCoordRight, yCoordRight;
|
---|
62 | private Vector4 centreScreen;
|
---|
63 | private float footSize = 30, defaultFootSize = 20, enlargedFootSize = 80;
|
---|
64 |
|
---|
65 | // Ingame variables
|
---|
66 | int selectedSong, selectedDifficulty;
|
---|
67 | int colourChanger = 0, quadrentRight, quadrentLeft;
|
---|
68 | long timeSinceLastBeat = 0;
|
---|
69 | long wavFrameIncrement = 0;
|
---|
70 | int scoreMultiplier = 1;
|
---|
71 | int playerScore = 0;
|
---|
72 | MicroTimer songTimer;
|
---|
73 | int colourChangeDifficulty = 80;
|
---|
74 |
|
---|
75 | public Form1()
|
---|
76 | {
|
---|
77 | InitializeComponent();
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | private void Form1_Load(object sender, EventArgs e)
|
---|
83 | {
|
---|
84 |
|
---|
85 | this.DoubleBuffered = true;
|
---|
86 | Setup();
|
---|
87 | }
|
---|
88 | private void Setup()
|
---|
89 | {
|
---|
90 | // Main screen
|
---|
91 | menuMode = 0;
|
---|
92 | screen = new BeatPicturebox();
|
---|
93 | screen.Visible = true;
|
---|
94 | screen.Paint += screen_Paint;
|
---|
95 | this.Controls.Add(screen);
|
---|
96 |
|
---|
97 | #region Info labels
|
---|
98 |
|
---|
99 | songNameLabel = new Label();
|
---|
100 | songNameLabel.Text = "Select a song to play!";
|
---|
101 | songNameLabel.Visible = true;
|
---|
102 | songNameLabel.Font = new Font("Roboto", 15);
|
---|
103 | songNameLabel.AutoSize = true;
|
---|
104 | songNameLabel.ForeColor = Color.White;
|
---|
105 | songNameLabel.BackColor = Color.Transparent;
|
---|
106 | this.Controls.Add(songNameLabel);
|
---|
107 |
|
---|
108 | difficultyLabel = new Label();
|
---|
109 | difficultyLabel.Text = "Select a difficulty to play!";
|
---|
110 | difficultyLabel.Visible = true;
|
---|
111 | difficultyLabel.Font = new Font("Roboto", 15);
|
---|
112 | difficultyLabel.AutoSize = true;
|
---|
113 | difficultyLabel.ForeColor = Color.White;
|
---|
114 | difficultyLabel.BackColor = Color.Transparent;
|
---|
115 | this.Controls.Add(difficultyLabel);
|
---|
116 |
|
---|
117 | multiplierLabel = new Label();
|
---|
118 | multiplierLabel.Text = "1";
|
---|
119 | multiplierLabel.Visible = true;
|
---|
120 | multiplierLabel.Font = new Font("Roboto", 25);
|
---|
121 | multiplierLabel.AutoSize = true;
|
---|
122 | multiplierLabel.ForeColor = Color.White;
|
---|
123 | multiplierLabel.BackColor = Color.Transparent;
|
---|
124 | this.Controls.Add(multiplierLabel);
|
---|
125 |
|
---|
126 | multiplierNameLabel = new Label();
|
---|
127 | multiplierNameLabel.Text = "Multiplier:";
|
---|
128 | multiplierNameLabel.Visible = true;
|
---|
129 | multiplierNameLabel.Font = new Font("Roboto", 25);
|
---|
130 | multiplierNameLabel.AutoSize = true;
|
---|
131 | multiplierNameLabel.ForeColor = Color.White;
|
---|
132 | multiplierNameLabel.BackColor = Color.Transparent;
|
---|
133 | this.Controls.Add(multiplierNameLabel);
|
---|
134 |
|
---|
135 | scoreLabel = new Label();
|
---|
136 | scoreLabel.Text = "0";
|
---|
137 | scoreLabel.Visible = true;
|
---|
138 | scoreLabel.Font = new Font("Roboto", 25);
|
---|
139 | scoreLabel.AutoSize = true;
|
---|
140 | scoreLabel.ForeColor = Color.White;
|
---|
141 | scoreLabel.BackColor = Color.Transparent;
|
---|
142 | this.Controls.Add(scoreLabel);
|
---|
143 |
|
---|
144 | scoreNameLabel = new Label();
|
---|
145 | scoreNameLabel.Text = "Score:";
|
---|
146 | scoreNameLabel.Visible = true;
|
---|
147 | scoreNameLabel.Font = new Font("Roboto", 25);
|
---|
148 | scoreNameLabel.AutoSize = true;
|
---|
149 | scoreNameLabel.ForeColor = Color.White;
|
---|
150 | scoreNameLabel.BackColor = Color.Transparent;
|
---|
151 | this.Controls.Add(scoreNameLabel);
|
---|
152 | #endregion
|
---|
153 |
|
---|
154 | #region Load songs
|
---|
155 |
|
---|
156 | //Note: temp is now frames. Use that for timer calculations
|
---|
157 |
|
---|
158 |
|
---|
159 | songLocations = Directory.GetFiles(Application.StartupPath + "/Songs");
|
---|
160 |
|
---|
161 | reader = new List<WaveFileReader>();
|
---|
162 | output = new List<WaveOut>();
|
---|
163 | wavInfo = new List<string[]>();
|
---|
164 | frames = new List<WavFrame>();
|
---|
165 | footstepList = new List<FootStep>();
|
---|
166 |
|
---|
167 | for (int i = 0; i < songLocations.Length; i++)
|
---|
168 | {
|
---|
169 | reader.Add(new WaveFileReader(songLocations[i]));
|
---|
170 | output.Add(new WaveOut());
|
---|
171 | output[i].Init(reader[i]);
|
---|
172 |
|
---|
173 | wavInfo.Add(WavProcessor.ReadWav(songLocations[i],1024,30));
|
---|
174 | frames.Add((WavFrame)JsonConvert.DeserializeObject<WavFrame>(wavInfo[i][0]));
|
---|
175 | }
|
---|
176 |
|
---|
177 | #endregion
|
---|
178 |
|
---|
179 | #region Initialize and start Kinect
|
---|
180 |
|
---|
181 | skeletonManager = new SkeletonManager(6);
|
---|
182 |
|
---|
183 | foreach (var potentialSensor in KinectSensor.KinectSensors)
|
---|
184 | {
|
---|
185 | if (potentialSensor.Status == KinectStatus.Connected)
|
---|
186 | {
|
---|
187 | this.sensor = potentialSensor;
|
---|
188 | break;
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | if (null != this.sensor)
|
---|
194 | {
|
---|
195 | // Turn on the skeleton stream to receive skeleton frames
|
---|
196 | this.sensor.SkeletonStream.Enable();
|
---|
197 |
|
---|
198 | // Add an event handler to be called whenever there is new color frame data
|
---|
199 | this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
|
---|
200 |
|
---|
201 | // Start the sensor!
|
---|
202 | try
|
---|
203 | {
|
---|
204 |
|
---|
205 | this.sensor.Start();
|
---|
206 | sensor.ElevationAngle = 10;
|
---|
207 | }
|
---|
208 | catch (IOException)
|
---|
209 | {
|
---|
210 | this.sensor = null;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | #endregion
|
---|
215 |
|
---|
216 | #region Fill menus
|
---|
217 |
|
---|
218 | songOptions = new List<Label>();
|
---|
219 | difficultyOptions = new List<Label>();
|
---|
220 |
|
---|
221 | for (int i = 0; i < songLocations.Length; i++)
|
---|
222 | {
|
---|
223 | string[] tempArray = songLocations[i].Split('\\');
|
---|
224 | string[] tempArray2 = tempArray[tempArray.Length - 1].Split('.');
|
---|
225 | Label tempLabel = new Label();
|
---|
226 | tempLabel.Text = tempArray2[0];
|
---|
227 | tempLabel.Left = 120;
|
---|
228 | tempLabel.Top = 200 + (i * 40);
|
---|
229 | tempLabel.Font = new Font("Roboto", 25);
|
---|
230 | tempLabel.AutoSize = true;
|
---|
231 | tempLabel.ForeColor = Color.White;
|
---|
232 | tempLabel.BackColor = Color.Transparent;
|
---|
233 | tempLabel.Visible = false;
|
---|
234 |
|
---|
235 | songOptions.Add(tempLabel);
|
---|
236 |
|
---|
237 | this.Controls.Add(songOptions[i]);
|
---|
238 |
|
---|
239 | }
|
---|
240 |
|
---|
241 | for (int i = 0; i < 3; i++)
|
---|
242 | {
|
---|
243 |
|
---|
244 | Label tempLabel = new Label();
|
---|
245 | string difficultySetting = "";
|
---|
246 | if (i == 0) difficultySetting = "Easy";
|
---|
247 | else if (i == 1) difficultySetting = "Medium";
|
---|
248 | else difficultySetting = "Hard";
|
---|
249 |
|
---|
250 | tempLabel.Text = difficultySetting;
|
---|
251 | tempLabel.Left = 120;
|
---|
252 | tempLabel.Top = 200 + (i * 40);
|
---|
253 | tempLabel.Font = new Font("Roboto", 25);
|
---|
254 | tempLabel.AutoSize = true;
|
---|
255 | tempLabel.ForeColor = Color.White;
|
---|
256 | tempLabel.BackColor = Color.Transparent;
|
---|
257 | tempLabel.Visible = false;
|
---|
258 |
|
---|
259 | difficultyOptions.Add(tempLabel);
|
---|
260 |
|
---|
261 | this.Controls.Add(difficultyOptions[i]);
|
---|
262 |
|
---|
263 | }
|
---|
264 |
|
---|
265 | // Menu timer setup
|
---|
266 |
|
---|
267 | continueTimer = new Timer();
|
---|
268 | continueTimer.Interval = 2000;
|
---|
269 | continueTimer.Enabled = true;
|
---|
270 | continueTimer.Tick += continueTimer_Tick;
|
---|
271 |
|
---|
272 | //DrawMenus();
|
---|
273 | #endregion
|
---|
274 |
|
---|
275 | #region Beatbox, Feet
|
---|
276 |
|
---|
277 | footLeft = new PictureBox();
|
---|
278 | footRight = new PictureBox();
|
---|
279 |
|
---|
280 | footLeft.Width = (int)footSize;
|
---|
281 | footLeft.Height = (int)footSize;
|
---|
282 | footLeft.BackColor = Color.Transparent;
|
---|
283 | Graphics tempLeft = footLeft.CreateGraphics();
|
---|
284 | tempLeft.FillEllipse(new SolidBrush(Color.Black), 0, 0, footSize, footSize);
|
---|
285 | this.Controls.Add(footLeft);
|
---|
286 |
|
---|
287 |
|
---|
288 |
|
---|
289 | footRight.Width = (int)footSize;
|
---|
290 | footRight.Height = (int)footSize;
|
---|
291 | footRight.BackColor = Color.Transparent;
|
---|
292 | Graphics tempRight = footLeft.CreateGraphics();
|
---|
293 | tempRight.FillEllipse(new SolidBrush(Color.Black), 0, 0, footSize, footSize);
|
---|
294 | this.Controls.Add(footRight);
|
---|
295 |
|
---|
296 | beatBoxLeft = new PictureBox();
|
---|
297 | beatBoxRight = new PictureBox();
|
---|
298 |
|
---|
299 | beatBoxLeft.BackColor = Color.Transparent;
|
---|
300 | beatBoxRight.BackColor = Color.Transparent;
|
---|
301 | beatBoxLeft.Visible = false;
|
---|
302 | beatBoxRight.Visible = false;
|
---|
303 | beatBoxLeft.Width = 100;
|
---|
304 | beatBoxRight.Width = 100;
|
---|
305 |
|
---|
306 | this.Controls.Add(beatBoxLeft);
|
---|
307 | this.Controls.Add(beatBoxRight);
|
---|
308 |
|
---|
309 |
|
---|
310 |
|
---|
311 | #endregion
|
---|
312 | }
|
---|
313 |
|
---|
314 | void continueTimer_Tick(object sender, EventArgs e)
|
---|
315 | {
|
---|
316 | continueTimer.Stop();
|
---|
317 | //multiplierNameLabel.Text = debugCounter++.ToString();
|
---|
318 | continueAvaliable = true;
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 | private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
|
---|
323 | {
|
---|
324 |
|
---|
325 | skeletonArray = new Skeleton[0];
|
---|
326 |
|
---|
327 | using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
|
---|
328 | {
|
---|
329 | if (skeletonFrame != null)
|
---|
330 | {
|
---|
331 | skeletonArray = new Skeleton[skeletonFrame.SkeletonArrayLength];
|
---|
332 | skeletonFrame.CopySkeletonDataTo(skeletonArray);
|
---|
333 | skeletonManager.Update(skeletonArray);
|
---|
334 |
|
---|
335 | }
|
---|
336 | if (skeletonArray.Length != 0)
|
---|
337 | {
|
---|
338 | //screen.Refresh();
|
---|
339 | //screen2.Refresh();
|
---|
340 |
|
---|
341 |
|
---|
342 | for (int i = 0; i < skeletonArray.Length; i++)
|
---|
343 | {
|
---|
344 |
|
---|
345 | string action = skeletonManager.Calibrate(i);
|
---|
346 |
|
---|
347 |
|
---|
348 | switch (menuMode)
|
---|
349 | {
|
---|
350 | case 0:
|
---|
351 |
|
---|
352 | if (action.Equals("continue"))
|
---|
353 | {
|
---|
354 | if (continueAvaliable == true)
|
---|
355 | {
|
---|
356 | continueTimer.Start();
|
---|
357 |
|
---|
358 | continueAvaliable = false;
|
---|
359 | songNameLabel.Text = "Song selected: " + songOptions[menuCursor].Text;
|
---|
360 | selectedSong = menuCursor;
|
---|
361 |
|
---|
362 | DrawMenus();
|
---|
363 | menuMode = 1;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | else if (action.Equals("menu"))
|
---|
367 | {
|
---|
368 |
|
---|
369 | }
|
---|
370 | else if (!action.Equals(""))
|
---|
371 | {
|
---|
372 |
|
---|
373 | float heightChange = float.Parse(action);
|
---|
374 | //multiplierTextLabel.Text = heightChange.ToString();
|
---|
375 | //scoreTextLabel.Text = heightChange.ToString();
|
---|
376 | int roundedHeightChange = (int)((heightChange * 10) + (songLocations.Length / 2));
|
---|
377 |
|
---|
378 | menuCursor = roundedHeightChange;
|
---|
379 |
|
---|
380 | if (menuCursor > (songLocations.Length - 1))
|
---|
381 | {
|
---|
382 | menuCursor = songLocations.Length - 1;
|
---|
383 | }
|
---|
384 | else if (menuCursor < 0)
|
---|
385 | {
|
---|
386 | menuCursor = 0;
|
---|
387 | }
|
---|
388 |
|
---|
389 |
|
---|
390 | songOptions[menuCursor].ForeColor = Color.Silver;
|
---|
391 |
|
---|
392 |
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 |
|
---|
397 |
|
---|
398 |
|
---|
399 |
|
---|
400 | break;
|
---|
401 |
|
---|
402 | case 1:
|
---|
403 |
|
---|
404 | if (action.Equals("continue"))
|
---|
405 | {
|
---|
406 |
|
---|
407 | if (continueAvaliable == true)
|
---|
408 | {
|
---|
409 | continueTimer.Stop();
|
---|
410 | continueTimer.Start();
|
---|
411 | continueAvaliable = false;
|
---|
412 | difficultyLabel.Text = "Difficulty selected: " + difficultyOptions[menuCursor].Text;
|
---|
413 | selectedDifficulty = menuCursor;
|
---|
414 |
|
---|
415 | if (menuCursor == 0)
|
---|
416 | {
|
---|
417 | colourChangeDifficulty = 80;
|
---|
418 | }
|
---|
419 | else if (menuCursor == 1)
|
---|
420 | {
|
---|
421 | colourChangeDifficulty = 60;
|
---|
422 | }
|
---|
423 | else
|
---|
424 | {
|
---|
425 | colourChangeDifficulty = 40;
|
---|
426 | }
|
---|
427 |
|
---|
428 |
|
---|
429 | menuMode = 2;
|
---|
430 |
|
---|
431 | DrawMenus();
|
---|
432 |
|
---|
433 |
|
---|
434 | //Play song
|
---|
435 |
|
---|
436 | songTimer = new MicroTimer();
|
---|
437 | songTimer.Interval = (int)((frames[selectedSong].songLength / wavInfo[selectedSong].Length) * 1000);
|
---|
438 |
|
---|
439 | // Have the ability to ignore late-firing timer events. Enable if drift issues exist, currently works with.
|
---|
440 | // timer.IgnoreEventIfLateBy = (int)((temp.songLength / wavInfo.Length) )/ 4;
|
---|
441 |
|
---|
442 | songTimer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(timerTick);
|
---|
443 |
|
---|
444 | output[selectedSong].Play();
|
---|
445 | songTimer.Enabled = true;
|
---|
446 |
|
---|
447 |
|
---|
448 | }
|
---|
449 | }
|
---|
450 | else if (action.Equals("menu"))
|
---|
451 | {
|
---|
452 | playerScore = 0;
|
---|
453 | scoreMultiplier = 1;
|
---|
454 |
|
---|
455 | menuMode = 0;
|
---|
456 | songNameLabel.Text = "Select a song to play";
|
---|
457 | difficultyLabel.Text = "Select a difficulty to play";
|
---|
458 | DrawMenus();
|
---|
459 | }
|
---|
460 | else if (!action.Equals(""))
|
---|
461 | {
|
---|
462 |
|
---|
463 | float heightChange = float.Parse(action);
|
---|
464 | //multiplierTextLabel.Text = heightChange.ToString();
|
---|
465 | //scoreTextLabel.Text = heightChange.ToString();
|
---|
466 | int roundedHeightChange = (int)((heightChange * 10) + (difficultyOptions.Count / 2));
|
---|
467 |
|
---|
468 | menuCursor = roundedHeightChange;
|
---|
469 |
|
---|
470 | if (menuCursor > (difficultyOptions.Count - 1))
|
---|
471 | {
|
---|
472 | menuCursor = difficultyOptions.Count - 1;
|
---|
473 | }
|
---|
474 | else if (menuCursor < 0)
|
---|
475 | {
|
---|
476 | menuCursor = 0;
|
---|
477 | }
|
---|
478 |
|
---|
479 | DrawMenus();
|
---|
480 |
|
---|
481 |
|
---|
482 | difficultyOptions[menuCursor].ForeColor = Color.Silver;
|
---|
483 | //this.Text = menuCursor.ToString();
|
---|
484 |
|
---|
485 | }
|
---|
486 |
|
---|
487 | break;
|
---|
488 |
|
---|
489 | case 2:
|
---|
490 | if (action.Equals("continue"))
|
---|
491 | {
|
---|
492 | if (continueAvaliable == true)
|
---|
493 | {
|
---|
494 |
|
---|
495 | }
|
---|
496 | }
|
---|
497 | else if (action.Equals("menu"))
|
---|
498 | {
|
---|
499 | //cancel song playing
|
---|
500 | output[selectedSong].Stop();
|
---|
501 | songTimer.Stop();
|
---|
502 |
|
---|
503 | playerScore = 0;
|
---|
504 | scoreMultiplier = 1;
|
---|
505 |
|
---|
506 | menuMode = 0;
|
---|
507 | songNameLabel.Text = "Select a song to play";
|
---|
508 | difficultyLabel.Text = "Select a difficulty to play";
|
---|
509 | DrawMenus();
|
---|
510 | }
|
---|
511 | else if (!action.Equals(""))
|
---|
512 | {
|
---|
513 |
|
---|
514 | }
|
---|
515 |
|
---|
516 | break;
|
---|
517 |
|
---|
518 |
|
---|
519 | }
|
---|
520 |
|
---|
521 | ////////////////// Calculate where player's feet/quadrent is
|
---|
522 | if (skeletonManager.skeletons[i].TrackingState == SkeletonTrackingState.Tracked && skeletonManager.calibrated[i] == true)
|
---|
523 | {
|
---|
524 | //multiplierNameLabel.Text = playerQuadrentLeft.ToString();
|
---|
525 | //scoreNameLabel.Text = playerQuadrentRight.ToString();
|
---|
526 |
|
---|
527 | playerQuadrentLeft = skeletonManager.FindQuadrant(skeletonManager.leftFoot[i].Z, skeletonManager.leftFoot[i].X, skeletonManager.centre[i]);
|
---|
528 | playerQuadrentRight = skeletonManager.FindQuadrant(skeletonManager.rightFoot[i].Z, skeletonManager.rightFoot[i].X, skeletonManager.centre[i]);
|
---|
529 |
|
---|
530 |
|
---|
531 | xCoordLeft = (centreScreen.X - footSize / 2) + (skeletonManager.leftFoot[i].X - skeletonManager.centre[i].X) * (screen.Width / 2) / 1f;
|
---|
532 | yCoordLeft = (centreScreen.Z - footSize / 2) + (skeletonManager.leftFoot[i].Z - skeletonManager.centre[i].Z) * (screen.Height / 2) / 1f;
|
---|
533 | xCoordRight = (centreScreen.X - footSize / 2) + (skeletonManager.rightFoot[i].X - skeletonManager.centre[i].X) * (screen.Width / 2) / 1f;
|
---|
534 | yCoordRight = (centreScreen.Z - footSize / 2) + (skeletonManager.rightFoot[i].Z - skeletonManager.centre[i].Z) * (screen.Height / 2) / 1f;
|
---|
535 |
|
---|
536 | Graphics graphics = screen.CreateGraphics();
|
---|
537 |
|
---|
538 |
|
---|
539 |
|
---|
540 |
|
---|
541 | screen.Invalidate();
|
---|
542 |
|
---|
543 | // Draw footsteps
|
---|
544 | }
|
---|
545 |
|
---|
546 | }
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 |
|
---|
551 |
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | private void timerTick(object sender, MicroTimerEventArgs args)
|
---|
556 | {
|
---|
557 | try
|
---|
558 | {
|
---|
559 | colourChanger++;
|
---|
560 | timeSinceLastBeat++;
|
---|
561 | wavFrameIncrement++;
|
---|
562 |
|
---|
563 |
|
---|
564 | if (colourChanger >= colourChangeDifficulty)
|
---|
565 | {
|
---|
566 |
|
---|
567 | colourChanger = 0;
|
---|
568 | Random random = new Random();
|
---|
569 | int temp = random.Next(0, 2);
|
---|
570 |
|
---|
571 | while (true)
|
---|
572 | {
|
---|
573 | if (temp == 1)
|
---|
574 | {
|
---|
575 | quadrentRight = random.Next(1, 5);
|
---|
576 |
|
---|
577 |
|
---|
578 | }
|
---|
579 | else
|
---|
580 | {
|
---|
581 | quadrentLeft = random.Next(1, 5);
|
---|
582 |
|
---|
583 | }
|
---|
584 |
|
---|
585 | if (!((quadrentRight == 1 || quadrentRight == 4) && (quadrentLeft == 2 || quadrentLeft == 3)))
|
---|
586 | {
|
---|
587 | break;
|
---|
588 | }
|
---|
589 | }
|
---|
590 | }
|
---|
591 | /*
|
---|
592 | if (footSize > defaultFootSize)
|
---|
593 | {
|
---|
594 | footSize *= 0.92f;
|
---|
595 | if (footSize < defaultFootSize) footSize = defaultFootSize;
|
---|
596 | }
|
---|
597 |
|
---|
598 | for (int i = 0; i < footstepList.Count; i++)
|
---|
599 | {
|
---|
600 | footstepList[i].radius *= 1.05f;
|
---|
601 | if (footstepList[i].radius > enlargedFootSize) footstepList.Remove(footstepList[i]);
|
---|
602 | }
|
---|
603 | */
|
---|
604 |
|
---|
605 | if (wavInfo[selectedSong].Length > wavFrameIncrement)
|
---|
606 | {
|
---|
607 | WavFrame currentFrame = (WavFrame)JsonConvert.DeserializeObject<WavFrame>(wavInfo[selectedSong][wavFrameIncrement]);
|
---|
608 |
|
---|
609 | // If a beat exists on the current frame, display it via BeatBox
|
---|
610 |
|
---|
611 | if (currentFrame.beatExists == true)
|
---|
612 | {
|
---|
613 | ChangeBeatBox();
|
---|
614 |
|
---|
615 | }
|
---|
616 |
|
---|
617 | }
|
---|
618 | else
|
---|
619 | {
|
---|
620 | menuMode = 0;
|
---|
621 | //DrawMenus();
|
---|
622 | }
|
---|
623 | }
|
---|
624 | catch (Exception e)
|
---|
625 | {
|
---|
626 |
|
---|
627 | this.Text = "~" + this.Text;
|
---|
628 | output[selectedSong].Stop();
|
---|
629 | songTimer.Stop();
|
---|
630 |
|
---|
631 | menuMode = 0;
|
---|
632 | DrawMenus();
|
---|
633 |
|
---|
634 | }
|
---|
635 | }
|
---|
636 |
|
---|
637 |
|
---|
638 |
|
---|
639 | private void ChangeBeatBox()
|
---|
640 | {
|
---|
641 | if (timeSinceLastBeat >= 30)
|
---|
642 | {
|
---|
643 | /*
|
---|
644 | footstepList.Add(new FootStep((float)defaultFootSize, xCoordLeft, yCoordLeft));
|
---|
645 | footstepList.Add(new FootStep((float)defaultFootSize, xCoordRight, yCoordRight));
|
---|
646 | */
|
---|
647 | if (playerQuadrentLeft == quadrentLeft) scoreMultiplier += 1;
|
---|
648 | if (playerQuadrentRight == quadrentRight) scoreMultiplier += 1;
|
---|
649 | else
|
---|
650 | {
|
---|
651 | if (!(playerQuadrentRight == quadrentRight)) scoreMultiplier = 1;
|
---|
652 | }
|
---|
653 |
|
---|
654 | if (scoreMultiplier > 10) scoreMultiplier = 10;
|
---|
655 |
|
---|
656 | playerScore += 100 * scoreMultiplier;
|
---|
657 |
|
---|
658 |
|
---|
659 | timeSinceLastBeat = 0;
|
---|
660 | }
|
---|
661 | }
|
---|
662 |
|
---|
663 | private void screen_Paint(object sender, PaintEventArgs e)
|
---|
664 | {
|
---|
665 | //screenCounter++;
|
---|
666 | //if (screenCounter > 2)
|
---|
667 | {
|
---|
668 |
|
---|
669 | Graphics graphics = e.Graphics;
|
---|
670 |
|
---|
671 | if (playerQuadrentLeft != 1 && playerQuadrentRight != 1) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, -180, 90, "#DE00C0", "#780068");
|
---|
672 | if (playerQuadrentLeft != 2 && playerQuadrentRight != 2) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, -90, "#000087", "#0000E8");
|
---|
673 | if (playerQuadrentLeft != 3 && playerQuadrentRight != 3) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, 90, "#008700", "#00E800");
|
---|
674 | if (playerQuadrentLeft != 4 && playerQuadrentRight != 4) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 90, 90, "#878700", "#E8A200");
|
---|
675 |
|
---|
676 |
|
---|
677 | /*
|
---|
678 | if (quadrentLeft != 1 && quadrentRight != 1) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, -180, 90, "#DE00C0", "#780068");
|
---|
679 | if (quadrentLeft != 2 && quadrentRight != 2) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, -90, "#000087", "#0000E8");
|
---|
680 | if (quadrentLeft != 3 && quadrentRight != 3) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, 90, "#008700", "#00E800");
|
---|
681 | if (quadrentLeft != 4 && quadrentRight != 4) DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 90, 90, "#878700", "#E8A200");
|
---|
682 |
|
---|
683 | */
|
---|
684 |
|
---|
685 | footRight.Left = (int)xCoordRight;
|
---|
686 | footRight.Top = (int)yCoordRight;
|
---|
687 | footLeft.Left = (int)xCoordLeft;
|
---|
688 | footLeft.Top = (int)yCoordLeft;
|
---|
689 |
|
---|
690 | DrawQuadrent(playerQuadrentLeft, graphics, 0);
|
---|
691 | DrawQuadrent(playerQuadrentRight, graphics, 1);
|
---|
692 | FillBeatbox(quadrentLeft, beatBoxLeft.CreateGraphics(), 0);
|
---|
693 | FillBeatbox(quadrentRight, beatBoxRight.CreateGraphics(), 1);
|
---|
694 |
|
---|
695 | scoreLabel.Text = playerScore.ToString();
|
---|
696 | multiplierLabel.Text = scoreMultiplier.ToString();
|
---|
697 | }
|
---|
698 | }
|
---|
699 |
|
---|
700 | private void Form1_Paint(object sender, PaintEventArgs e)
|
---|
701 | {
|
---|
702 | screen.Left = 0;
|
---|
703 | screen.Top = 0;
|
---|
704 | screen.Width = this.Width;
|
---|
705 | screen.Height = this.Height;
|
---|
706 | screen.BackColor = this.BackColor;
|
---|
707 | screen.BackgroundImage = this.BackgroundImage;
|
---|
708 | screen.BackgroundImageLayout = ImageLayout.Stretch;
|
---|
709 | centreScreen.X = screen.Width / 2;
|
---|
710 | centreScreen.Z = screen.Height / 2;
|
---|
711 |
|
---|
712 | Graphics graphics = e.Graphics;
|
---|
713 | Graphics screenGraphics = screen.CreateGraphics();
|
---|
714 |
|
---|
715 |
|
---|
716 | #region Draw Background
|
---|
717 | /*
|
---|
718 | GraphicsPath path = new GraphicsPath();
|
---|
719 | int offset = 0;
|
---|
720 | path.AddEllipse(offset, (-((screen.Width - screen.Height) / 2) )+ offset, (screen.Width - 20) + offset, (screen.Width - 20) + offset);
|
---|
721 |
|
---|
722 | // Create a path gradient brush based on the elliptical path.
|
---|
723 | PathGradientBrush pthGrBrush = new PathGradientBrush(path);
|
---|
724 |
|
---|
725 | // Set the color along the entire boundary to
|
---|
726 | Color[] color = { (Color)ColorTranslator.FromHtml("#353535") };
|
---|
727 | pthGrBrush.SurroundColors = color;
|
---|
728 | //Centre color
|
---|
729 | pthGrBrush.CenterColor = (Color)ColorTranslator.FromHtml("#E8E8E8"); ;
|
---|
730 | this.BackColor = (Color)ColorTranslator.FromHtml("#353535"); ;
|
---|
731 | // Set the focus scales for the path gradient brush.
|
---|
732 | pthGrBrush.FocusScales = new PointF(0.1f, 0.1f);
|
---|
733 |
|
---|
734 | //graphics.FillPath(pthGrBrush, path);
|
---|
735 | */
|
---|
736 | #endregion
|
---|
737 |
|
---|
738 | #region Draw Mat
|
---|
739 |
|
---|
740 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, -180, 90, "#DE00C0", "#780068");
|
---|
741 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, -90, "#000087", "#0000E8");
|
---|
742 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, 90, "#008700", "#00E800");
|
---|
743 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 90, 90, "#878700", "#E8A200");
|
---|
744 |
|
---|
745 |
|
---|
746 |
|
---|
747 |
|
---|
748 |
|
---|
749 |
|
---|
750 |
|
---|
751 |
|
---|
752 |
|
---|
753 | #endregion
|
---|
754 |
|
---|
755 | #region Align UI
|
---|
756 |
|
---|
757 | // Labels
|
---|
758 | songNameLabel.Left = 120;
|
---|
759 | songNameLabel.Top = 50;
|
---|
760 |
|
---|
761 |
|
---|
762 | difficultyLabel.Left = songNameLabel.Left;
|
---|
763 | difficultyLabel.Top = 120;
|
---|
764 |
|
---|
765 |
|
---|
766 | scoreLabel.Left = this.Width -200;
|
---|
767 | scoreLabel.Top = songNameLabel.Top ;
|
---|
768 |
|
---|
769 |
|
---|
770 | scoreNameLabel.Left = scoreLabel.Left - 200;
|
---|
771 | scoreNameLabel.Top = scoreLabel.Top;
|
---|
772 |
|
---|
773 | multiplierLabel.Top = difficultyLabel.Top;
|
---|
774 | multiplierLabel.Left = scoreLabel.Left;
|
---|
775 |
|
---|
776 | multiplierNameLabel.Left = scoreNameLabel.Left;
|
---|
777 | multiplierNameLabel.Top = multiplierLabel.Top;
|
---|
778 |
|
---|
779 | beatBoxLeft.Height = screen.Height;
|
---|
780 | beatBoxRight.Height = screen.Height;
|
---|
781 | beatBoxLeft.Left = 0;
|
---|
782 | beatBoxLeft.Top = 0;
|
---|
783 | beatBoxRight.Left = screen.Right - 100;
|
---|
784 | beatBoxRight.Top = screen.Top;
|
---|
785 |
|
---|
786 |
|
---|
787 | screen.SendToBack();
|
---|
788 |
|
---|
789 | #endregion
|
---|
790 |
|
---|
791 | #region Draw menus
|
---|
792 | DrawMenus();
|
---|
793 |
|
---|
794 |
|
---|
795 | #endregion
|
---|
796 |
|
---|
797 |
|
---|
798 |
|
---|
799 | //DrawQuadrent(playerQuadrentLeft, graphics, 0);
|
---|
800 | //DrawQuadrent(playerQuadrentRight, graphics, 1);
|
---|
801 | /*
|
---|
802 | for (int n = 0; n < footstepList.Count; n++)
|
---|
803 | {
|
---|
804 | if (n < footstepList.Count)
|
---|
805 | {
|
---|
806 | graphics.DrawEllipse(new Pen(Color.Black, 4f), footstepList[n].xPos - (footstepList[n].radius / 2),
|
---|
807 | footstepList[n].yPos - (footstepList[n].radius / 2), footstepList[n].radius, footstepList[n].radius);
|
---|
808 | }
|
---|
809 | }
|
---|
810 |
|
---|
811 | graphics.FillEllipse(new SolidBrush(Color.Black),
|
---|
812 | (int)(xCoordLeft),
|
---|
813 | (int)(yCoordLeft),
|
---|
814 | footSize, footSize);
|
---|
815 |
|
---|
816 | graphics.FillEllipse(new SolidBrush(Color.Black),
|
---|
817 | (int)(xCoordRight),
|
---|
818 | (int)(yCoordRight),
|
---|
819 | footSize, footSize);
|
---|
820 | */
|
---|
821 | }
|
---|
822 |
|
---|
823 | private void DrawQuadrent(int num, Graphics graphics, int foot)
|
---|
824 | {
|
---|
825 | PictureBox picturebox = new PictureBox();
|
---|
826 | if (foot == 0) picturebox = beatBoxLeft;
|
---|
827 | else picturebox = beatBoxRight;
|
---|
828 |
|
---|
829 | if (num == 1)
|
---|
830 | {
|
---|
831 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 180, 90, "#FFFFFF", "#DE00C0");
|
---|
832 | // picturebox.BackColor = (Color)ColorTranslator.FromHtml("#DE00C0");
|
---|
833 |
|
---|
834 | //graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, screen.Width / 2, screen.Height / 2);
|
---|
835 | }
|
---|
836 | else if (num == 2)
|
---|
837 | {
|
---|
838 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, -90, "#FFFFFF", "#00DCE8");
|
---|
839 | // picturebox.BackColor = (Color)ColorTranslator.FromHtml("#00DCE8");
|
---|
840 | //graphics.FillRectangle(new SolidBrush(Color.Blue), screen.Width / 2, 0, screen.Width / 2, screen.Height / 2);
|
---|
841 | }
|
---|
842 | else if (num == 3)
|
---|
843 | {
|
---|
844 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, 90, "#FFFFFF", "#00E800");
|
---|
845 | // picturebox.BackColor = (Color)ColorTranslator.FromHtml("#00E800");
|
---|
846 | //graphics.FillRectangle(new SolidBrush(Color.Green), screen.Height / 2, screen.Width / 2, screen.Width / 2, screen.Height / 2);
|
---|
847 | }
|
---|
848 | else if (num == 4)
|
---|
849 | {
|
---|
850 | DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 90, 90, "#FFFFFF", "#E8E800");
|
---|
851 | // picturebox.BackColor = (Color)ColorTranslator.FromHtml("#E8E800");
|
---|
852 | //graphics.FillRectangle(new SolidBrush(Color.Yellow), 0, screen.Height / 2, screen.Width / 2, screen.Height / 2);
|
---|
853 | }
|
---|
854 |
|
---|
855 | //graphics.FillEllipse(new SolidBrush(Color.Black), screen.Width / 2 - (deadspotSize / 2), screen.Height / 2 - (deadspotSize / 2), deadspotSize, deadspotSize);
|
---|
856 |
|
---|
857 |
|
---|
858 |
|
---|
859 | }
|
---|
860 | private void FillBeatbox(int num, Graphics graphics, int foot)
|
---|
861 | {
|
---|
862 | PictureBox picturebox = new PictureBox();
|
---|
863 | if (foot == 0) picturebox = beatBoxLeft;
|
---|
864 | else picturebox = beatBoxRight;
|
---|
865 |
|
---|
866 | if (num == 1)
|
---|
867 | {
|
---|
868 | // DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 180, 90, "#FFFFFF", "#DE00C0");
|
---|
869 | picturebox.BackColor = (Color)ColorTranslator.FromHtml("#DE00C0");
|
---|
870 |
|
---|
871 | //graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, screen.Width / 2, screen.Height / 2);
|
---|
872 | }
|
---|
873 | else if (num == 2)
|
---|
874 | {
|
---|
875 | //DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, -90, "#FFFFFF", "#00DCE8");
|
---|
876 | picturebox.BackColor = (Color)ColorTranslator.FromHtml("#00DCE8");
|
---|
877 | //graphics.FillRectangle(new SolidBrush(Color.Blue), screen.Width / 2, 0, screen.Width / 2, screen.Height / 2);
|
---|
878 | }
|
---|
879 | else if (num == 3)
|
---|
880 | {
|
---|
881 | // DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 0, 90, "#FFFFFF", "#00E800");
|
---|
882 | picturebox.BackColor = (Color)ColorTranslator.FromHtml("#00E800");
|
---|
883 | //graphics.FillRectangle(new SolidBrush(Color.Green), screen.Height / 2, screen.Width / 2, screen.Width / 2, screen.Height / 2);
|
---|
884 | }
|
---|
885 | else if (num == 4)
|
---|
886 | {
|
---|
887 | // DrawSegment(graphics, screen.Width, screen.Height, circleRadius, 90, 90, "#FFFFFF", "#E8E800");
|
---|
888 | picturebox.BackColor = (Color)ColorTranslator.FromHtml("#E8E800");
|
---|
889 | //graphics.FillRectangle(new SolidBrush(Color.Yellow), 0, screen.Height / 2, screen.Width / 2, screen.Height / 2);
|
---|
890 | }
|
---|
891 |
|
---|
892 | //graphics.FillEllipse(new SolidBrush(Color.Black), screen.Width / 2 - (deadspotSize / 2), screen.Height / 2 - (deadspotSize / 2), deadspotSize, deadspotSize);
|
---|
893 |
|
---|
894 |
|
---|
895 |
|
---|
896 | }
|
---|
897 |
|
---|
898 |
|
---|
899 |
|
---|
900 |
|
---|
901 | private void DrawMenus()
|
---|
902 | {
|
---|
903 | switch (menuMode)
|
---|
904 | {
|
---|
905 | case 0:
|
---|
906 | for (int i = 0; i < difficultyOptions.Count; i++)
|
---|
907 | {
|
---|
908 | difficultyOptions[i].Visible = false;
|
---|
909 | }
|
---|
910 | for (int i = 0; i < songOptions.Count; i++)
|
---|
911 | {
|
---|
912 | songOptions[i].Visible = true;
|
---|
913 | if (i != menuCursor)
|
---|
914 | {
|
---|
915 | songOptions[i].ForeColor = Color.White;
|
---|
916 | }
|
---|
917 | }
|
---|
918 |
|
---|
919 | beatBoxLeft.Visible = false;
|
---|
920 | beatBoxRight.Visible = false;
|
---|
921 |
|
---|
922 | break;
|
---|
923 |
|
---|
924 |
|
---|
925 | case 1:
|
---|
926 | for (int i = 0; i < songOptions.Count; i++)
|
---|
927 | {
|
---|
928 | songOptions[i].Visible = false;
|
---|
929 | }
|
---|
930 | for (int i = 0; i < difficultyOptions.Count; i++)
|
---|
931 | {
|
---|
932 | difficultyOptions[i].Visible = true;
|
---|
933 | if (i != menuCursor)
|
---|
934 | {
|
---|
935 | difficultyOptions[i].ForeColor = Color.White;
|
---|
936 | }
|
---|
937 | }
|
---|
938 | beatBoxLeft.Visible = false;
|
---|
939 | beatBoxRight.Visible = false;
|
---|
940 |
|
---|
941 |
|
---|
942 | break;
|
---|
943 |
|
---|
944 | case 2:
|
---|
945 | for (int i = 0; i < songOptions.Count; i++)
|
---|
946 | {
|
---|
947 | songOptions[i].Visible = false;
|
---|
948 | }
|
---|
949 | for (int i = 0; i < difficultyOptions.Count; i++)
|
---|
950 | {
|
---|
951 | difficultyOptions[i].Visible = false;
|
---|
952 | }
|
---|
953 |
|
---|
954 | beatBoxLeft.Visible = true;
|
---|
955 | beatBoxRight.Visible = true;
|
---|
956 |
|
---|
957 |
|
---|
958 |
|
---|
959 | break;
|
---|
960 | }
|
---|
961 | }
|
---|
962 |
|
---|
963 |
|
---|
964 | private void DrawSegment(Graphics graphics, float width, float height, int radius, int startAngle, int finAngle, string innerColour, string outerColour)
|
---|
965 | {
|
---|
966 |
|
---|
967 | // Create a path that consists of a single ellipse.
|
---|
968 | GraphicsPath path = new GraphicsPath();
|
---|
969 | path.AddEllipse((width / 2) - (radius / 2), (height / 2) - (radius / 2), 140, 70);
|
---|
970 | path.AddPie((width / 2) - (radius / 2), (height / 2) - (radius / 2), radius, radius, startAngle, finAngle);
|
---|
971 |
|
---|
972 | // Use the path to construct a brush.
|
---|
973 | PathGradientBrush pthGrBrush = new PathGradientBrush(path);
|
---|
974 |
|
---|
975 | // Set the center point to a location that is not
|
---|
976 | // the centroid of the path.
|
---|
977 | pthGrBrush.CenterPoint = new PointF((width / 2), (height / 2));
|
---|
978 |
|
---|
979 | //orange
|
---|
980 |
|
---|
981 | // Set the color at the center of the path to blue.
|
---|
982 |
|
---|
983 | pthGrBrush.CenterColor = (Color)ColorTranslator.FromHtml(innerColour);
|
---|
984 |
|
---|
985 | // Set the color along the entire boundary
|
---|
986 | // of the path to aqua.
|
---|
987 | Color[] colors = { (Color)ColorTranslator.FromHtml(outerColour) };
|
---|
988 | pthGrBrush.SurroundColors = colors;
|
---|
989 |
|
---|
990 | //graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
|
---|
991 | graphics.FillPie(pthGrBrush, (width / 2) - (radius / 2), (height / 2) - (radius / 2), radius, radius, startAngle, finAngle);
|
---|
992 |
|
---|
993 | }
|
---|
994 |
|
---|
995 | public class FootStep
|
---|
996 | {
|
---|
997 | public float radius;
|
---|
998 | public float xPos, yPos;
|
---|
999 |
|
---|
1000 | public FootStep(float Radius, float XPos, float YPos)
|
---|
1001 | {
|
---|
1002 | radius = Radius;
|
---|
1003 | xPos = XPos;
|
---|
1004 | yPos = YPos;
|
---|
1005 | }
|
---|
1006 | }
|
---|
1007 | }
|
---|
1008 | }
|
---|