From b1d985a5b87eac51ba960cef533e768a93b5b351 Mon Sep 17 00:00:00 2001
From: Joshua Saxby <joshua.a.saxby@gmail.com>
Date: Sun, 9 Feb 2020 18:18:55 +0000
Subject: [PATCH] Coded up a stacking Block demo without player movement

---
 source/main.cpp | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/source/main.cpp b/source/main.cpp
index 1cd70a3..50020b0 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
-- 
GitLab