This is the Mexican Standoff prototype made by Francisco Martin and Andrew Smith. Please refer to the following link for instructions on hardware hookup: https://developer.mbed.org/users/fomartin/notebook/mexican-standoff-reaction-game/
Dependencies: SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect
Revision 0:75716bd37804, committed 2016-03-14
- Comitter:
- fomartin
- Date:
- Mon Mar 14 03:04:08 2016 +0000
- Child:
- 1:4976bbb3376f
- Commit message:
- Mexican Standoff Prototype;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Audio/music.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,53 @@
+#include "music.h"
+
+//NOTE:
+//starting a thread inside of a class is apparently really hard to do in RTOS
+//since the function you pass to the thread should be static...
+//As a workaround I simply create a static thread_helper method
+//that launches the thread on behalf of the calling class.
+//
+//More info here: https://developer.mbed.org/forum/mbed/topic/4388/
+
+
+Music::Music(wave_player &speaker_arg)
+{
+ speaker = &speaker_arg;
+}
+
+void Music::playMainMusic()
+{
+ main_music_thread = new Thread(thread_helper, this);
+}
+
+void Music::stopMainMusic()
+{
+ main_music_thread->terminate();
+}
+
+void Music::main_music()
+{
+ while(true)
+ {
+ FILE *main_music_file = fopen("/sd/titlemusic.wav", "r");
+
+ if(main_music_file == NULL)
+ {
+ while(true)
+ {
+ //display error somehow. I'm having trouble definring LED
+ //digital out's here, but that'd be the easiest way to display it
+ }
+ }
+ speaker->play(main_music_file);
+ fclose(main_music_file);
+ }
+}
+
+void Music::thread_helper(const void *arg)
+{
+ //Cast the argument to a Music instance pointer
+ Music* instancePtr = (Music*)arg;
+
+ //Call the thread method for the Music instance
+ instancePtr->main_music();
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Audio/music.h Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,27 @@
+#include "PinDetect.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
+#include "rtos.h"
+
+class Music
+{
+ private:
+ wave_player *speaker;
+ Thread *main_music_thread;
+
+ public:
+ Music(wave_player &speaker_arg);
+
+ void playMainMusic(); //starts thread to play main music
+ void stopMainMusic(); //ends thread to play main music
+
+ //add other audio clip methods here
+ /*
+ *
+ *
+ */
+
+ protected:
+ static void thread_helper(const void *args);
+ void main_music(); //actually plays the main music on loop
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CPU.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,40 @@
+#include "States.h"
+#include <stdlib.h>
+#include <time.h>
+#include <float.h>
+
+
+
+CPU::CPU()
+{
+ difficulty = 1;
+ srand(time(NULL));
+}
+
+CPU::CPU(int cpu_difficulty)
+{
+ difficulty = cpu_difficulty;
+ srand(time(NULL));
+}
+
+float CPU::shootTime()
+{
+
+ int randNumber = rand() % 10;
+
+ float answer = (rand() % 10 + 1) / 10.0f;
+ return answer / (float) difficulty;
+}
+
+bool CPU::shootAnswer(Prompt correctAnswer)
+{
+ if(correctAnswer == Down || correctAnswer == Up)
+ {
+ int randNumber = rand() % 10;
+
+ if(randNumber == 9)
+ return false;
+ }
+
+ return true;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware/4DGL-uLCD-SE.lib Mon Mar 14 03:04:08 2016 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware/PinDetect.lib Mon Mar 14 03:04:08 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Hardware/Speaker.h Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,19 @@
+//#include "mbed.h"
+//// new class to play a note on Speaker based on PwmOut class
+//class Speaker
+//{
+//public:
+// Speaker(PinName pin) : _pin(pin) {
+//// _pin(pin) means pass pin to the Speaker Constructor
+// }
+//// class method to play a note based on PwmOut class
+// void PlayNote(float frequency, float duration, float volume) {
+// _pin.period(1.0/frequency);
+// _pin = volume/2.0;
+// wait(duration);
+// _pin = 0.0;
+// }
+//
+//private:
+// PwmOut _pin;
+//};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Mon Mar 14 03:04:08 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/mbed/code/SDFileSystem/#7b35d1709458
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/States/GameOver.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,33 @@
+#include "States.h"
+
+GameOver::GameOver(uLCD_4DGL &uLCD, PinDetect &Button0, PinDetect &Button1,
+ PinDetect &Button2, PinDetect &Button3,
+ int winningPlayer)
+{
+
+ uLCD.background_color(BLACK);
+
+
+ uLCD.cls();
+ uLCD.textbackground_color(BLACK);
+ uLCD.color(WHITE);
+ uLCD.printf("\n Game Over \n");
+
+ if(winningPlayer == 1)
+ {
+ uLCD.locate(0, 5);
+ uLCD.printf("\n");
+ uLCD.printf(" PLAYER 1 WINS!! \n");
+ uLCD.printf("\n");
+ uLCD.printf(" PLAYER 2 SUCKS... \n");
+ }
+ else
+ {
+ uLCD.printf("\n");
+ uLCD.printf(" PLAYER 2 WINS!! \n");
+ uLCD.printf("\n");
+ uLCD.printf(" PLAYER 1 SUCKS... \n");
+ }
+
+ while(Button0 && Button1 && Button2 && Button3) {}
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/States/Gameplay.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,381 @@
+#include "States.h"
+#include "mbed.h"
+
+////////////////////////////////////////////////////////////////
+// CONSTRUCTORS
+////////////////////////////////////////////////////////////////
+Gameplay::Gameplay(uLCD_4DGL &uLCD, int numberOfPlayers, PinDetect &P1_Left, PinDetect &P1_Right, PinDetect &P2_Left, PinDetect &P2_Right)
+{
+ uLCD.background_color(LGREY);
+ uLCD.cls();
+ //random seed setup
+ srand(time(NULL));
+
+ numPlayers = numberOfPlayers;
+ points = new int[2];
+ CPU cpu;
+
+ DigitalOut led1(LED1);
+ DigitalOut led4(LED4);
+
+ //LCD setup
+ uLCD.color(BLACK);
+ uLCD.textbackground_color(LGREY);
+ uLCD.set_font(FONT_7X8);
+
+ //points setup
+ resetPoints(uLCD);
+
+ //it takes 5-6 seconds for guns to get drawn, but we only draw
+ //them once at the beginning of the game
+ drawGun(uLCD, 10, 30, true);
+ drawGun(uLCD, 10, 92, true);
+
+ drawGun(uLCD, 127 - 10 - 42, 30, false);
+ drawGun(uLCD, 127 - 10 - 42, 92, false);
+
+ while(getPoints(1) != 0 && getPoints(2) != 0)
+ {
+ //gameplay here
+ //basic structure should be this:
+ Prompt prompt = (Prompt)(rand() % 4);
+
+ countdown(uLCD);
+ clearCountdown(uLCD);
+
+ if(prompt == HoldFire)
+ {
+ //hold fire
+ displayXs(uLCD);
+
+ Timer timer;
+ timer.start();
+
+ //hold fire for 2 seconds
+ while(timer.read_ms() < 2000)
+ {
+ if(!P1_Left || !P1_Right)
+ {
+ setPoints(1, getPoints(1) - 1, uLCD);
+ led4 = 1;
+ break;
+ }
+
+ //AI will never mis-fire
+ if(numPlayers == 1 && (!P2_Left || !P2_Right))
+ {
+ setPoints(2, getPoints(2) - 1, uLCD);
+ led1 = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ if(prompt == Either)
+ {
+ displayCircle(uLCD);
+ }
+ else if(prompt == Down)
+ {
+ displayDownArrow(uLCD);
+ }
+ else if(prompt == Up)
+ {
+ displayUpArrow(uLCD);
+ }
+
+ int aiShootTime = 0;
+
+ if(numPlayers == 1)
+ aiShootTime = (int)(cpu.shootTime() * 1000);
+
+ Timer timer;
+ timer.start();
+ bool p1l = false, p1r = false, p2l = false, p2r = false;
+
+ //wait for button to be pressed
+ while(true)
+ {
+ if(numPlayers == 1 && timer.read_ms() > aiShootTime)
+ {
+ bool aiCorrect = cpu.shootAnswer(prompt);
+
+ if(prompt == Up)
+ {
+ if(aiCorrect)
+ {
+ p2r = true;
+ p2l = false;
+ }
+ else
+ {
+ p2l = true;
+ p2r = false;
+ }
+ }
+ else if (prompt == Down)
+ {
+ if(aiCorrect)
+ {
+ p2l = true;
+ p2r = false;
+ }
+ else
+ {
+ p2r = true;
+ p2l = false;
+ }
+ }
+ else
+ {
+ //prompt = either, just press left
+ p2l = true;
+ p2r = false;
+ }
+
+ break;
+ }
+
+ if(!P1_Left)
+ {
+ p1l = true;
+ p1r = false;
+ p2l = false;
+ p2r = false;
+ break;
+ }
+
+ if(!P1_Right)
+ {
+ p1l = false;
+ p1r = true;
+ p2l = false;
+ p2r = false;
+ break;
+ }
+
+ if(numPlayers == 2 && !P2_Left)
+ {
+ p1l = false;
+ p1r = false;
+ p2l = true;
+ p2r = false;
+ break;
+ }
+
+ if(numPlayers == 2 && !P2_Right)
+ {
+ p1l = false;
+ p1r = false;
+ p2l = false;
+ p2r = true;
+ break;
+ }
+ }
+
+ if(p1l)
+ {
+ if(prompt == Either || prompt == Up)
+ {
+ setPoints(2, getPoints(2) - 1, uLCD);
+ led1 = 1;
+ }
+ else
+ {
+ setPoints(1, getPoints(1) - 1, uLCD);
+ led4 = 1;
+ }
+ }
+ else if(p1r)
+ {
+ if(prompt == Either || prompt == Down)
+ {
+ setPoints(2, getPoints(2) - 1, uLCD);
+ led1 = 1;
+ }
+ else
+ {
+ setPoints(1, getPoints(1) - 1, uLCD);
+ led4 = 1;
+ }
+ }
+ else if(p2l)
+ {
+ if(prompt == Either || prompt == Down)
+ {
+ setPoints(1, getPoints(1) - 1, uLCD);
+ led4 = 1;
+ }
+ else
+ {
+ setPoints(2, getPoints(2) - 1, uLCD);
+ led1 = 1;
+ }
+ }
+ else if(p2r)
+ {
+ if(prompt == Either || prompt == Up)
+ {
+ setPoints(1, getPoints(1) - 1, uLCD);
+ led4 = 1;
+ }
+ else
+ {
+ setPoints(2, getPoints(2) - 1, uLCD);
+ led1 = 1;
+ }
+ }
+ }
+
+ clearPrompt(uLCD);
+ Thread::wait(2000);
+ led1 = 0;
+ led4 = 0;
+ }
+
+ if(getPoints(1) == 0)
+ winningPlayer = 2;
+ else
+ winningPlayer = 1;
+}
+
+////////////////////////////////////////////////////////////////
+// GET FUNCTIONS
+////////////////////////////////////////////////////////////////
+int Gameplay::getPoints(int player)
+{
+ return points[player - 1];
+}
+
+int Gameplay::getWinningPlayer()
+{
+ return winningPlayer;
+}
+
+////////////////////////////////////////////////////////////////
+// SET FUNCTIONS
+////////////////////////////////////////////////////////////////
+void Gameplay::resetPoints(uLCD_4DGL &uLCD)
+{
+ points[0] = 5;
+ points[1] = 5;
+ renderScore(uLCD);
+}
+
+void Gameplay::setPoints(int player, int value, uLCD_4DGL &uLCD)
+{
+ points[player - 1] = value;
+ renderScore(uLCD);
+}
+
+////////////////////////////////////////////////////////////////
+// PROTECTED FUNCTIONS
+////////////////////////////////////////////////////////////////
+
+void Gameplay::drawGun(uLCD_4DGL &uLCD, int x, int y, bool facingRight)
+{
+ if(facingRight)
+ {
+ int colors[] = {12566463, 12566463, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -5023488, -5023488, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -5023488, -5023488, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -11382190, -11382190, -11382190, -11382190, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -11382190, -11382190, -11382190, -11382190, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463};
+ uLCD.BLIT(x, y, 42, 20, colors);
+ }
+ else
+ {
+ int colors[] = {12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -11382190, -11382190, -11382190, -11382190, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -11382190, -11382190, -11382190, -11382190, -11382190, -11382190, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -13158601, -13158601, -13158601, -13158601, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -8372224, -8372224, -8372224, -8372224, -8372224, -8372224, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -5023488, -5023488, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -5023488, -5023488, -5023488, -5023488, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, -16777216, -16777216, -16777216, -16777216, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463, 12566463};
+ uLCD.BLIT(x, y, 42, 20, colors);
+ }
+}
+
+void Gameplay::displayUpArrow(uLCD_4DGL &uLCD)
+{
+ uLCD.line(64, 64, 64, 30, GREEN);
+ uLCD.line(54, 40, 64, 30, GREEN);
+ uLCD.line(74, 40, 64, 30, GREEN);
+}
+
+void Gameplay::displayDownArrow(uLCD_4DGL &uLCD)
+{
+ uLCD.line(64, 64, 64, 98, GREEN);
+ uLCD.line(54, 88, 64, 98, GREEN);
+ uLCD.line(74, 88, 64, 98, GREEN);
+}
+
+void Gameplay::displayCircle(uLCD_4DGL &uLCD)
+{
+ uLCD.circle(64, 64, 15, GREEN);
+}
+
+void Gameplay::displayXs(uLCD_4DGL &uLCD)
+{
+ //top X
+ uLCD.line(54, 40, 74, 20, RED);
+ uLCD.line(54, 20, 74, 40, RED);
+
+ //bottom X
+ uLCD.line(54, 88, 74, 108, RED);
+ uLCD.line(54, 108, 74, 88, RED);
+}
+
+//clears the arrow/circle/x currently on the screen
+void Gameplay::clearPrompt(uLCD_4DGL &uLCD)
+{
+ //up arrow
+ uLCD.line(64, 64, 64, 30, LGREY);
+ uLCD.line(54, 40, 64, 30, LGREY);
+ uLCD.line(74, 40, 64, 30, LGREY);
+
+ //down arrow
+ uLCD.line(64, 64, 64, 98, LGREY);
+ uLCD.line(54, 88, 64, 98, LGREY);
+ uLCD.line(74, 88, 64, 98, LGREY);
+
+ //circle
+ uLCD.circle(64, 64, 15, LGREY);
+
+ //top X
+ uLCD.line(54, 40, 74, 20, LGREY);
+ uLCD.line(54, 20, 74, 40, LGREY);
+
+ //bottom X
+ uLCD.line(54, 88, 74, 108, LGREY);
+ uLCD.line(54, 108, 74, 88, LGREY);
+}
+
+
+void Gameplay::countdown(uLCD_4DGL &uLCD)
+{
+ uLCD.locate(5, 8);
+ uLCD.printf("3");
+ Thread::wait(333);
+ uLCD.printf(".");
+ Thread::wait(333);
+ uLCD.printf(".");
+ Thread::wait(333);
+ uLCD.printf("2");
+ Thread::wait(333);
+ uLCD.printf(".");
+ Thread::wait(333);
+ uLCD.printf(".");
+ Thread::wait(333);
+ uLCD.printf("1");
+ Thread::wait(333);
+ uLCD.printf(".");
+ Thread::wait(333);
+ uLCD.printf(".");
+ Thread::wait(333);
+}
+
+void Gameplay::clearCountdown(uLCD_4DGL &uLCD)
+{
+ uLCD.filled_rectangle(30, 50, 98, 78, LGREY);
+}
+
+void Gameplay::renderScore(uLCD_4DGL &uLCD)
+{
+ uLCD.locate(3, 0);
+ uLCD.printf("P1: %d", getPoints(1));
+
+ uLCD.locate(10, 0);
+ uLCD.printf("P2: %d", getPoints(2));
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/States/Rules.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,69 @@
+#include "States.h"
+#include <algorithm>
+
+Rules::Rules(uLCD_4DGL &uLCD, PinDetect &button0, PinDetect &button1, PinDetect &button2, PinDetect &button3)
+{
+ uLCD.color(LGREY);
+ uLCD.set_font_size(5, 9);
+
+ int page = 0;
+ bool updateText = true;
+
+
+ do
+ {
+ if(updateText)
+ {
+ updateText = false;
+
+ switch(page)
+ {
+ case 0:
+ {
+ uLCD.cls();
+ uLCD.printf(" Mexican Standoff \n");
+ uLCD.printf(" First player to \n");
+ uLCD.printf(" fire the correct \n");
+ uLCD.printf(" gun wins! \n");
+ uLCD.printf("\n");
+ uLCD.printf(" Learn the visual \n");
+ uLCD.printf(" cues! \n");
+ uLCD.printf("\n");
+ uLCD.printf("\n");
+ uLCD.printf(" (Page 1/2) ");
+ } break;
+
+ case 1:
+ {
+ uLCD.cls();
+ uLCD.printf(" Video: \n");
+ uLCD.printf(" Shoot on green. \n");
+ uLCD.printf(" Hold fire on red.\n");
+ uLCD.printf(" Arrow tells which\n");
+ uLCD.printf("gun to use. Circle\n");
+ uLCD.printf(" means use either!\n");
+ uLCD.printf("\n");
+ uLCD.printf("\n");
+ uLCD.printf("\n");
+ uLCD.printf(" (Page 2/2) ");
+ } break;
+ }
+ }
+
+ if(!button3)
+ {
+ if(page != 0)
+ updateText = true;
+
+ page = max(0, page - 1);
+ }
+ if(!button2)
+ {
+ if(page != 2)
+ updateText = true;
+
+ page = min(2, page + 1);
+ }
+
+ } while(button0 && button1); //evaluate this after rendering text so it doesn't immediately exit menu if button is down
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/States/Startup.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,103 @@
+#include "States.h"
+
+Startup::Startup(uLCD_4DGL &uLCD, PinDetect &upButton, PinDetect &downButton, PinDetect &leftButton, PinDetect &rightButton)
+{
+ uLCD.cls();
+
+ int image[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -3101112, -6512280, -9341134, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -6512280, -1, -7762349, -7038369, -4407394, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -527127, -6578073, -9341134, -7630766, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2368312, -2705590, -1, -5131122, -1, -1, -1, -1, -1, -11720171, -12704232, -11844801, -1, -1, -1, -1, -1, -1, -1, -1, -1, -6709403, -7433129, -1, -1, -1, -131589, -1, -1, -1, -1, -1, -10997993, -11720171, -7387616, -9615565, -1, -1, -1, -1, -1, -1, -1, -6512280, -9341134, -1, -3092529, -957317, -1497033, -11720171, -2565928, -11982570, -14343648, -5460820, -7387616, -11720171, -6530769, -11720171, -6135757, -1, -1, -1, -1, -1, -1721791, -1, -1, -1, -15956855, -15956855, -1, -11720171, -1, -1, -657931, -12244970, -7387616, -11720171, -7321567, -12507368, -7387616, -2972313, -1, -1, -1, -6512280, -9275340, -1, -1, -1, -12497842, -14127767, -4605511, -11720171, -7842271, -1, -6974059, -1, -6333403, -12769767, -3103898, -11456224, -11851242, -7387616, -2972313, -1, -1, -6775454, -6512280, -10049336, -1, -65794, -7685188, -14671328, -1, -9357029, -8437987, -11720171, -1, -1, -4554175, -6069707, -3762853, -11457514, -14277855, -5995691, -6267085, -9027033, -1, -6709403, -9341134, -10902329, -13581604, -1, -15956855, -7684674, -2969262, -723724, -11654634, -12572904, -13360101, -657931, -7387359, -10800096, -6069707, -12900838, -14671840, -14671840, -13360101, -4092844, -1, -8683456, -1, -5353428, -415151, -5022658, -14259346, -8013639, -473028, -12502989, -7650273, -11720171, -14671840, -3829159, -13883870, -7387616, -13884385, -7387616, -7387616, -7387616, -7387616, -7387616, -1, -6512280, -1, -415151, -1271222, -14323345, -7553345, -6783441, -3163517, -14671840, -8437729, -14671840, -2972313, -7452895, -11720171, -11194089, -14540255, -9091298, -5542615, -5542615, -9683173, -2972313, -16684984, -1, -1, -415151, -415151, -7242934, -10119532, -7553345, -1, -1, -10855846, -14671840, -10144487, -11720171, -10275040, -14606048, -7845593, -13359844, -7387616, -10733534, -7119061, -7387616, -1, -7236004, -1, -415151, -415151, -1468855, -15956855, -15956855, -14475488, -1, -7058143, -6069456, -11720171, -11720171, -2972313, -5938121, -7387616, -3629983, -2380436, -5542615, -1, -2972313, -1, -2697022, -1, -2851521, -415151, -415151, -16023163, -15956855, -11432050, -1, -6926300, -197638, -7781601, -7387616, -2972313, -7057883, -2380436, -2378882, -8699108, -11391465, -6596301, -1, -1, -6512280, -6183561, -14315334, -13581604, -1248008, -1, -15628661, -1052946, -1, -2834776, -9413339, -210371, -1, -9154260, -5542615, -1, -1, -407494, -13028309, -1, -1, -1, -1315616, -7104413, -202059, -1, -13581604, -16223577, -15956855, -685156, -535033, -1, -473028, -4280704, -723986, -1, -1, -8883410, -210371, -341179, -2380436, -1, -1, -1, -591886, -8617663, -1, -1, -13581604, -1, -15956855, -10058362, -1, -8817874, -473028, -6127546, -197638, -1, -5723023, -1, -199720, -2644400, -1, -1, -1, -1, -1, -604610, -1384775, -1, -1, -998080, -3418154, -14192789, -9928577, -6646174, -8883410, -1, -4867962, -5723023, -66052, -1, -5263998, -1, -2828616, -1, -1, -1, -1, -1120824, -8157112, -9341134, -1, -269412, -1, -15697799, -15956855, -13480372, -1, -131588, -5921678, -5723023, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -6512280, -6512280, -1, -1, -1, -1, -15956855, -683358, -543558, -1, -1, -1, -473028, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -7564715, -2307436, -1, -1, -1, -1, -1361079, -210370, -1, -1, -131588, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -210370, -8025524, -9078218, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -7038626, -5393789, -723474, -6512280, -9341134, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2771881, -460299, -9209548, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+
+ //title
+ uLCD.locate(3,0);
+ uLCD.text_italic(ON);
+ uLCD.text_string("Mexican Standoff", 1, 1, FONT_12X16, WHITE);
+ uLCD.filled_rectangle(14, 20, 47, 77, 0xCE1126);
+ uLCD.filled_rectangle(47, 20, 80, 77, 0xFFFFFF);
+ uLCD.filled_rectangle(80, 20, 113, 77, 0x006847);
+ uLCD.BLIT(14 + 37, 20 + 17, 25, 22, image);
+ uLCD.text_italic(OFF);
+ uLCD.text_string("One Player", 4, 10, FONT_12X16, WHITE);
+ uLCD.text_string("Two Player", 4, 12, FONT_12X16, WHITE);
+ uLCD.text_string("How To Play", 4, 14, FONT_12X16, WHITE);
+}
+
+int Startup::select(uLCD_4DGL &uLCD, PinDetect &Button0, PinDetect &Button1, PinDetect &Button2, PinDetect &Button3, Music &music)
+{
+ DigitalOut led2(LED2);
+
+ option = 0;
+ uLCD.filled_circle(15, 83, 5, WHITE);
+
+ do
+ {
+ if(!Button2)
+ option += 1;
+
+ if(!Button3)
+ option -= 1;
+
+ option = (option + 3) % 3; //wrap around... add 4 to avoid negative modulus
+
+ if(option == 0)
+ {
+ uLCD.filled_circle(15, 83, 5, WHITE);
+ uLCD.filled_circle(15, 99, 5, BLACK);
+ uLCD.filled_circle(15, 115, 5, BLACK);
+ wait(0.2);
+ }
+ else if(option == 1)
+ {
+ uLCD.filled_circle(15, 83, 5, BLACK);
+ uLCD.filled_circle(15, 99, 5, WHITE);
+ uLCD.filled_circle(15, 115, 5, BLACK);
+ wait(0.2);
+ }
+ else if(option == 2)
+ {
+ uLCD.filled_circle(15, 83, 5, BLACK);
+ uLCD.filled_circle(15, 99, 5, BLACK);
+ uLCD.filled_circle(15, 115, 5, WHITE);
+ wait(0.2);
+ }
+ } while(Button0 && Button1);
+
+ return option;
+}
+
+void Startup::scores(uLCD_4DGL &uLCD, SDFileSystem &sd)
+{
+ mkdir("/sd/mydir", 0777);
+ FILE *fp = fopen("/sd/mydir/highscores.txt", "r");
+ if(fp == NULL) {
+ error("Could not open file for read.\n");
+ }
+ uLCD.set_font(FONT_5X7);
+ uLCD.locate(0, 3);
+ uLCD.color(BLUE);
+ uLCD.printf("One Player");
+ uLCD.color(RED);
+ uLCD.printf(" Two Player \n");
+
+ int currentScore;
+
+ uLCD.color(BLUE);
+ for(int i = 0; i < 5; ++i)
+ {
+ fscanf(fp,"%d", ¤tScore);
+ fgetc(fp);
+ uLCD.locate(0, i+4);
+ uLCD.printf(" %d: %d", i+1, currentScore);
+ }
+
+ uLCD.color(RED);
+ for(int i = 5; i < 10; ++i)
+ {
+ fscanf(fp,"%d", ¤tScore);
+ fgetc(fp);
+ uLCD.locate(11, i-1);
+ uLCD.printf(" %d: %d", i-4, currentScore);
+ }
+
+ uLCD.filled_rectangle(52, 24, 72, 71, WHITE);
+
+ fclose(fp);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/States/States.h Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,84 @@
+#include "uLCD_4DGL.h"
+#include "PinDetect.h"
+#include <stdlib.h>
+#include <time.h>
+#include "music.h"
+#include "SDFileSystem.h"
+
+class Startup
+{
+ public:
+ //CONSTRUCTOR
+ Startup(uLCD_4DGL &uLCD, PinDetect &upButton, PinDetect &downButton, PinDetect &leftButton, PinDetect &rightButton);
+
+ //MEMBER FUNCTIONS
+ int select(uLCD_4DGL &uLCD, PinDetect &upButton, PinDetect &downButton, PinDetect &leftButton, PinDetect &rightButton,
+ Music &music);
+ void scores(uLCD_4DGL &uLCD, SDFileSystem &sd);
+
+ private:
+ int option;
+};
+
+class Rules
+{
+ public:
+ Rules(uLCD_4DGL &uLCD, PinDetect &upButton, PinDetect &downButton, PinDetect &leftButton, PinDetect &rightButton);
+};
+
+enum Prompt{HoldFire, Either, Down, Up};
+
+//
+class Gameplay
+{
+ public:
+ // CONSTRUCTOR
+ Gameplay(uLCD_4DGL &uLCD, int numberOfPlayers,
+ PinDetect &Button0, PinDetect &Button1,
+ PinDetect &Button2, PinDetect &Button3);
+
+ // GET FUNCTIONS
+ int getPoints(int player);
+ int getWinningPlayer();
+
+ // SET FUNCTIONS
+ void setPoints(int player, int points, uLCD_4DGL &uLCD);
+
+ private:
+ int *points;
+ int numPlayers;
+ int winningPlayer;
+
+ void drawGun(uLCD_4DGL &uLCD, int x, int y, bool facingRight);
+ void displayUpArrow(uLCD_4DGL &uLCD);
+ void displayDownArrow(uLCD_4DGL &uLCD);
+ void displayCircle(uLCD_4DGL &uLCD);
+ void displayXs(uLCD_4DGL &uLCD);
+ void clearPrompt(uLCD_4DGL &uLCD);
+
+ void countdown(uLCD_4DGL &uLCD);
+ void clearCountdown(uLCD_4DGL &uLCD);
+
+ void renderScore(uLCD_4DGL &uLCD);
+ void resetPoints(uLCD_4DGL &uLCD);
+};
+
+class GameOver
+{
+ public:
+ GameOver(uLCD_4DGL &uLCD, PinDetect &Button0, PinDetect &Button1,
+ PinDetect &Button2, PinDetect &Button3,
+ int winningPlayer);
+};
+
+class CPU
+{
+ private:
+ int difficulty;
+ public:
+ CPU();
+ CPU(int difficulty);
+
+ float shootTime();
+ bool shootAnswer(Prompt correctAnswer);
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,84 @@
+#include "States.h"
+#include "mbed.h"
+
+//button setup using PinDetect
+// button is pushed -> false
+// button is not pushed -> true
+PinDetect P1_LeftButton(p15, PullUp);
+PinDetect P1_RightButton(p16, PullUp);
+PinDetect P2_LeftButton(p26, PullUp);
+PinDetect P2_RightButton(p29, PullUp);
+
+//LCD setup
+uLCD_4DGL uLCD(p28, p27, p21); // serial tx, serial rx, reset pin;
+
+//speaker setup
+AnalogOut speaker(p18);
+wave_player waver(&speaker);
+
+//states enum
+enum StateType{MainMenu, HowTo, SinglePlayerGame, TwoPlayerGame, EndScreen};
+StateType state = MainMenu;
+
+
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+
+//member variables
+int option;
+int points;
+
+DigitalOut led1(LED1);
+
+main()
+{
+ Music music(waver);
+
+ //LCD setup
+ uLCD.display_control(PORTRAIT_R);
+ uLCD.baudrate(BAUD_3000000); //jack up baud rate to max for fast display
+ uLCD.background_color(BLACK);
+ uLCD.cls();
+
+ music.playMainMusic();
+
+ while(true)
+ {
+ switch(state)
+ {
+ case(MainMenu):
+ {
+ // Set-Up Main Menu
+ Startup startup(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton);
+ //startup.scores(uLCD, sd);
+ option = startup.select(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton, music);
+ if(option == 0)
+ state = SinglePlayerGame;
+ if(option == 1)
+ state = TwoPlayerGame;
+ if(option == 2)
+ state = HowTo;
+ break;
+ }
+ case(HowTo):
+ {
+ Rules rules(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton);
+ state = MainMenu;
+ break;
+ }
+ case(SinglePlayerGame):
+ {
+ Gameplay gameplay(uLCD, 1, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton);
+ GameOver gameover(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton, gameplay.getWinningPlayer());
+ state = MainMenu;
+ break;
+ }
+ case(TwoPlayerGame):
+ {
+ Gameplay gameplay(uLCD, 2, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton);
+ GameOver gameover(uLCD, P1_LeftButton, P1_RightButton, P2_LeftButton, P2_RightButton, gameplay.getWinningPlayer());
+ state = MainMenu;
+ break;
+ }
+ }//end switch
+ }//end while
+}//end main
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Mar 14 03:04:08 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#dfc27975e193
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 14 03:04:08 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Mon Mar 14 03:04:08 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad