diff --git a/source/main.cpp b/source/main.cpp index f4b769accf60f0f5ec02f91318e16f79dbe8e037..cc011df37178ab9a74c058e3de3d466fe5d42af9 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -59,6 +59,7 @@ public: /* end event handler methods */ private: + bool on; // whether flasher should be on or off /** * @brief Draws whatever's in the screen buffer to display */ @@ -72,8 +73,18 @@ Game::Game() : screen_buffer(5, 5) // our screen buffer mirrors the display dimensions {} +void Game::press_button_a(MicroBitEvent e) { + // XXX: debug + this->on = true; +} + +void Game::press_button_b(MicroBitEvent e) { + // XXX: debug + this->on = false; +} + void Game::run() { - UBIT.display.scroll("NEW GAME!"); + // UBIT.display.scroll("NEW GAME!"); // init screen display mode, to be sure it is in a known-state // TODO: consider changing to greyscale to allow "mutli-coloured" blocks UBIT.display.setDisplayMode(DISPLAY_MODE_BLACK_AND_WHITE); @@ -93,7 +104,6 @@ void Game::run() { while (true) { // TODO: change to use game-over condition // sleep to conserve CPU cycles and allow other fibers a chance to run UBIT.sleep(10); // 10ms sleep, or 100Hz tick rate - this->draw(); // render screen buffer } // TODO: add the rest of the game logic UBIT.display.scroll("GAME OVER!"); @@ -116,18 +126,11 @@ void Game::run() { void Game::draw() { // XXX: debug drawing, fill the screen buffer with black this->screen_buffer.clear(); + if (this->on) { + this->screen_buffer.setPixelValue(2, 2, 255); + } // render our screen buffer - UBIT.display.image.paste(this->screen_buffer); -} - -void Game::press_button_a(MicroBitEvent e) { - // XXX: debug - this->screen_buffer.setPixelValue(0, 2, 255); -} - -void Game::press_button_b(MicroBitEvent e) { - // XXX: debug - this->screen_buffer.setPixelValue(4, 2, 255); + UBIT.display.print(this->screen_buffer); } int main() { @@ -136,8 +139,11 @@ int main() { UBIT.display.scroll("BLOCKS!"); + Game game; + + create_fiber(game.draw); + while (true) { // indefinitely start new games - Game game; game.run(); }