diff --git a/source/main.cpp b/source/main.cpp index 75ef1a7b3091a1f94e44f32315f755862892e015..10355d1485d208d1b10629c7b70d93aaa69c1797 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -276,18 +276,19 @@ bool can_shape_move( if (shape_image.getPixelValue(x, y) != 0) { // calculate the translated position, including origin Point destination = origin + Point(x, y); - // if Y is negative, skip this pixel as a special case - if (destination.y < 0) { - continue; // we allow Blocks to be out of the top frame - } // if out-of-bounds, of course it can't move if ( destination.x < 0 or destination.x > 4 or destination.y > 4 + // NOTE: there is no check for negative Y since we allow it ) { return false; } + // if Y is negative, we don't need to check this row + if (destination.y < 0) { + break; // no point checking this row, out of screen + } // check if the translated position of this pixel is not free if (stacked.getPixelValue(destination.x, destination.y) != 0) { return false; @@ -388,46 +389,56 @@ void start_new_game() { Point origin(1, -3); // this is the down unit-vector Vector down(0, 1); + // draw the scene + UBIT.display.print(stacked_shapes); + // draw Block with transparency enabled on clear image pixels + UBIT.display.print(block.image(), origin.x, origin.y, 1); // while Block can go down - while (can_shape_move(block, origin, stacked_shapes, down)) { - // allow player to shift the Block left or right - /* - * read accelerometer manually for more controlled movement - * than what is available from gesture events - */ - if (UBIT.accelerometer.getX() <= -200) { - move_command = -1; - } - if (UBIT.accelerometer.getX() >= +200) { - move_command = +1; - } - // take note of any move requests from the player - if (move_command != 0) { - // create unit vector from move command - Vector move(move_command, 0); - if (can_shape_move(block, origin, stacked_shapes, move)) { - origin = origin + move; + if (can_shape_move(block, origin, stacked_shapes, down)) { + while (true) { + // allow player to shift the Block left or right + /* + * read accelerometer manually for more controlled movement + * than what is available from gesture events + */ + if (UBIT.accelerometer.getX() <= -200) { + move_command = -1; } - // reset move command to prevent it sticking - move_command = 0; - } - // shift the Block down at a constant rate - { - // check if enough time has elapsed to move the block - unsigned long stopwatch_now = UBIT.systemTime(); - if ((stopwatch_now - stopwatch) >= move_speed) { - // shift the shape down - origin = origin + down; - // update the "stopwatch" - stopwatch = stopwatch_now; + if (UBIT.accelerometer.getX() >= +200) { + move_command = +1; + } + // take note of any move requests from the player + if (move_command != 0) { + // create unit vector from move command + Vector move(move_command, 0); + if (can_shape_move(block, origin, stacked_shapes, move)) { + origin = origin + move; + } + // reset move command to prevent it sticking + move_command = 0; + } + // shift the Block down at a constant rate + { + // check if enough time has elapsed to move the block + 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)) { + origin = origin + down; + } else { + break; + } + // update the "stopwatch" + stopwatch = stopwatch_now; + } } + // draw the scene + UBIT.display.print(stacked_shapes); + // draw Block with transparency enabled on clear image pixels + UBIT.display.print(block.image(), origin.x, origin.y, 1); + // delay + UBIT.sleep(10); // 10ms sleep = 100ticks/second } - // draw the scene - UBIT.display.print(stacked_shapes); - // draw Block with transparency enabled on clear image pixels - UBIT.display.print(block.image(), origin.x, origin.y, 1); - // delay - UBIT.sleep(10); // 10ms sleep = 100ticks/second } // if Block Y origin is less than 0 upon not being able to go down if (origin.y < 0) {