diff --git a/source/main.cpp b/source/main.cpp index ed542f54a89f396766d5dd952425fc531bcc7574..3b46381e605bfc42794f63f6f97a568c3ce78733 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -33,7 +33,7 @@ * interact with it from my classes via a reference or a pointer to it, however * this does not appear to work, for some unknown reason... */ -MicroBit UBIT; +MicroBit ubit; /** @@ -334,8 +334,8 @@ private: }; Block::Block() - : facing((RotationDirection)UBIT.random(4)) // choose a random direction - , shape((Shape)UBIT.random(SHAPE_TYPES_COUNT)) // choose a random shape + : facing((RotationDirection)ubit.random(4)) // choose a random direction + , shape((Shape)ubit.random(SHAPE_TYPES_COUNT)) // choose a random shape {} MicroBitImage Block::image() const { @@ -359,13 +359,13 @@ MicroBitImage Block::image() const { void debug_test() { // XXX: simple debug test to check my FLASH images were stored correctly // for accurately-timed animations irrespective of framerate, track time - unsigned long stopwatch = UBIT.systemTime(); + unsigned long stopwatch = ubit.systemTime(); unsigned long move_speed = 1000; // move down one block every 350ms // set up event handlers - // UBIT.messageBus.listen( + // ubit.messageBus.listen( // MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, a_button_pressed // ); - // UBIT.messageBus.listen( + // ubit.messageBus.listen( // MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, b_button_pressed // ); while (true) { @@ -376,18 +376,18 @@ void debug_test() { int y = -3; // print image until scrolled down off the screen while (y < 6) { - UBIT.display.clear(); - UBIT.display.print(block.image(), x, y); + ubit.display.clear(); + ubit.display.print(block.image(), x, y); { // check if enough time has elapsed to move the block - unsigned long stopwatch_now = UBIT.systemTime(); + unsigned long stopwatch_now = ubit.systemTime(); if ((stopwatch_now - stopwatch) >= move_speed) { y++; // update the "stopwatch" stopwatch = stopwatch_now; } } - UBIT.sleep(50); // 50ms sleep for 20 FPS + ubit.sleep(50); // 50ms sleep for 20 FPS } } } @@ -572,13 +572,13 @@ void start_new_game() { // clear the stacked shapes image stacked_shapes.clear(); // // set up event handlers - UBIT.messageBus.listen( + ubit.messageBus.listen( MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, rotate_acw ); - UBIT.messageBus.listen( + ubit.messageBus.listen( MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, rotate_cw ); - unsigned long stopwatch = UBIT.systemTime(); + unsigned long stopwatch = ubit.systemTime(); unsigned long move_speed = 750; // move down one block every 750ms // this is the main game loop while (not game_over) { @@ -627,10 +627,10 @@ void start_new_game() { * read accelerometer manually for more controlled movement * than what is available from gesture events */ - if (UBIT.accelerometer.getX() <= -300) { + if (ubit.accelerometer.getX() <= -300) { move_command = -1; } - if (UBIT.accelerometer.getX() >= +300) { + if (ubit.accelerometer.getX() >= +300) { move_command = +1; } // take note of any move requests from the player @@ -646,7 +646,7 @@ void start_new_game() { // shift the Block down at a constant rate { // check if enough time has elapsed to move the block - unsigned long stopwatch_now = UBIT.systemTime(); + unsigned long stopwatch_now = ubit.systemTime(); if ((stopwatch_now - stopwatch) >= move_speed) { // shift the shape down if it can if (can_shape_move(block, origin, stacked_shapes, down)) { @@ -660,11 +660,11 @@ void start_new_game() { } } // draw the scene - UBIT.display.print(stacked_shapes); + ubit.display.print(stacked_shapes); // draw Block with transparency enabled on clear image pixels - UBIT.display.print(block.image(), origin.x, origin.y, 1); + ubit.display.print(block.image(), origin.x, origin.y, 1); // delay - UBIT.sleep(10); // 10ms sleep = 100ticks/second + ubit.sleep(10); // 10ms sleep = 100ticks/second } } // if Block Y origin is less than 0 upon not being able to go down @@ -683,33 +683,33 @@ void start_new_game() { } // TODO: clean up game state // remove event-handlers - UBIT.messageBus.ignore( + ubit.messageBus.ignore( MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, rotate_acw ); - UBIT.messageBus.ignore( + ubit.messageBus.ignore( MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, rotate_cw ); // display score - UBIT.display.scroll("SCORE:"); - UBIT.display.scroll(score); + ubit.display.scroll("SCORE:"); + ubit.display.scroll(score); } int main() { // Initialise the micro:bit runtime. - UBIT.init(); + ubit.init(); // draw first dot to indicate runtime system is initialised - UBIT.display.image.setPixelValue(0, 2, 255); + ubit.display.image.setPixelValue(0, 2, 255); // seed the PRNG with the HWRNG - UBIT.seedRandom(); + ubit.seedRandom(); // draw second dot to indicate PRNG has been seeded - UBIT.display.image.setPixelValue(2, 2, 255); + ubit.display.image.setPixelValue(2, 2, 255); // ensure display is set to black and white mode - UBIT.display.setDisplayMode(DISPLAY_MODE_BLACK_AND_WHITE); + ubit.display.setDisplayMode(DISPLAY_MODE_BLACK_AND_WHITE); // draw third and final dot to indicate screen has been set up - UBIT.display.image.setPixelValue(4, 2, 1); + ubit.display.image.setPixelValue(4, 2, 1); // introduce the game with a greeting message - UBIT.display.scroll("BLOCKS!"); + ubit.display.scroll("BLOCKS!"); // indefinitely start new games while (true) {