diff --git a/source/main.cpp b/source/main.cpp index 1cd70a3b4a2f33047d7508262eb9fa68c4a97869..50020b06ae590a9c6459d5c061f1c2aa6fd3cd5b 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -318,9 +318,41 @@ bool game_over; void start_new_game() { game_over = false; // we're starting a new game // TODO: add event-handlers for button-presses + unsigned long stopwatch = UBIT.systemTime(); + unsigned long move_speed = 350; // move down one block every 350ms // this is the main game loop do { - NULL; + // XXX: for demo, keep sending random Blocks until stacked up to ceiling + Block block; + // starting position + Point origin(1, -3); + // this is the down unit-vector + Vector down(0, 1); + // if we can't send this Block down at creation, it's game over + game_over = not can_shape_move(block, origin, stacked_shapes, down); + if (not game_over) { + bool can_move = true; + do { + // 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); + { + // 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; + } + } + // delay + UBIT.sleep(50); // 50ms sleep = 20fps + } while (can_shape_move(block, origin, stacked_shapes, down)); + // the Block has now collided with the stack, copy it to the stack + stacked_shapes.paste(block.image(), origin.x, origin.y, 1); + } } while (not game_over); // TODO: remove event-handlers // TODO: add GAME OVER message