A complex 2D-dungeon game on LPC1768 in SWJTU-Leeds Joint School XJEL2645 project. Referenced from the framework contributed by https://os.mbed.com/users/Siriagus/code/SimplePlatformGame/
Dependencies: mbed N5110 ShiftReg PinDetect
Diff: main.cpp
- Revision:
- 7:678873947b29
- Parent:
- 6:edb48de563a9
- Child:
- 8:9ac6a428fa26
--- a/main.cpp Fri May 01 09:44:38 2015 +0000 +++ b/main.cpp Fri May 01 18:10:59 2015 +0000 @@ -9,6 +9,7 @@ #include "PowerControl.h" #include "PinDetect.h" #include <string> +#include <sstream> #include <ctime> #include "Joystick.h" @@ -40,7 +41,6 @@ AnalogIn ledPot(LED_POT); // Debugging -Serial pc(USBTX, USBRX); BusOut leds(LED1, LED2, LED3, LED4); // @brief Clears the screen and fill it with the image in the argument. @@ -70,23 +70,26 @@ { init(); - time_t dt = time(NULL); + Timer timer; + timer.start(); while(true) - { - - input->joystick->update(); + { + // update lcd->setBrightness(1.0 - ledPot); // Update brightness of screen - - // update - fsm->update(dt); + fsm->update(timer.read()); + input->joystick->update(); // render lcd->clear(); - fsm->render(); + fsm->render(); lcd->refresh(); - Sleep(); + fsm->processRequest(); // Change the state if requested. + + timer.reset(); + + Sleep(); // Sleep for 50 ms until InputManager reads the } cleanUp(); @@ -94,25 +97,6 @@ return 0; } -void ledToggle() -{ - leds[0] = !leds[0]; -} - -int ctr = 0; -void ledToggle4() {leds[3] = !leds[3];} -void ledToggle2() -{ - leds[1] = !leds[1]; - - if (++ctr > 4) - input->addBtnPressInterrupt(input->btnB, ledToggle4); - -} - - -void ledToggle3() {leds[2] = !leds[2];} - void init() { // Init LCD @@ -123,12 +107,8 @@ // Input input = new InputManager(BUTTON_A, BUTTON_B, BUTTON_C, JOY_V, JOY_H, JOY_BTN); - //input->addBtnPressInterrupt(input->btnA, ledToggle); - // input->addBtnPressInterrupt(input->btnB, ledToggle2); - //input->addBtnPressInterrupt(input->btnC, ledToggle3); - fsm = new StateManager(lcd, input); - fsm->changeState(MAIN_MENU); + fsm = new StateManager(lcd, input, MAIN_MENU); } void cleanUp()