QuickClick, a reaction timing game which allows single and multiplayer mode.
Dependencies: Controller Display N5110 Operator mbed
main.cpp
- Committer:
- domkay97
- Date:
- 2017-05-01
- Revision:
- 12:c0f1f6d007dc
- Parent:
- 10:7f5a9ec5fb26
- Child:
- 13:a8c86ae9ca1b
File content as of revision 12:c0f1f6d007dc:
#include "mbed.h" #include "N5110.h" #include "Display.h" #include "Controller.h" #include "Operator.h" N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Display display; Controller ctrl; Operator Opp; int num_players; int instruction_val; int next_player; bool multi_player; void starter(); /** Polar coordinate struct */ int main() { lcd.init(); //their default states the lcd and controller are configured display.init(); // ctrl.init(); // starter(); //Methord describing starting screen when the controller is first booted up while(1) { next_player = Opp.check_next_player(next_player, lcd, ctrl, display); // find the next player after 10 goes or failure if (Opp.test_player(next_player, ctrl, display, lcd)) { //next player returns true or flase depending on success Opp.correct(next_player, ctrl); // process correct response } else { Opp.inCorrect(next_player, ctrl); // process incorrect response if (!multi_player || (multi_player && Opp.check_dead()) ) { //set game over staus Opp.gameOver(ctrl, lcd); //display score and level display.init(); //reset waiting time starter(); } //go back to starter screen } } } void starter() { num_players = 1; lcd.clear(); lcd.printString("Quick Click",10,0); lcd.refresh(); while (ctrl.check_event(Controller::JOY_PRESSED) == false) { // set single or multiplayer float flicked = ctrl.get_joy(); // pressing Joystick completes selection if (flicked > 1) { // flicking lest or right selects no of players num_players--; } if (flicked < -0.5) { num_players++; } if (num_players < 1) { // lowest value is 1 num_players = 1; } if (num_players > 2) { //highest value is 2 num_players = 2; } if (num_players == 1) { lcd.printString("<Single>Player",0,2); // display message multi_player = false; next_player = 0; } else { lcd.printString("<Multi >Player",0,2); // display message multi_player = true; next_player = 1; } Opp.setup_players(num_players); lcd.printString("<JOYSTICK>",10,5); lcd.refresh(); wait(0.2); } lcd.clear(); lcd.printString("Quick Click",10,0); //text to be displayed when on starter screen lcd.printString("Start >",24,5); lcd.refresh(); while (ctrl.check_event(Controller::START_PRESSED) == false) { //whilst the start button hasn't been pressed just flash the leds and nothing else ctrl.ledsON(); wait(0.1); ctrl.ledsOFF(); wait(0.1); } }