Skip to content
Snippets Groups Projects
Commit 90b1d6bb authored by ja3-saxby's avatar ja3-saxby
Browse files

Interactive button-pressing demo for shape-shifting without collision-detection

parent 7cf2a48d
No related branches found
No related tags found
No related merge requests found
......@@ -162,17 +162,32 @@ MicroBitImage Block::image() const {
}
}
int x = 1;
void a_button_pressed(MicroBitEvent) {
x--;
}
void b_button_pressed(MicroBitEvent) {
x++;
}
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 move_speed = 350; // move down one block every 350ms
unsigned long move_speed = 1000; // move down one block every 350ms
// set up event handlers
UBIT.messageBus.listen(
MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, a_button_pressed
);
UBIT.messageBus.listen(
MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, b_button_pressed
);
while (true) {
// scroll random blocks down the screen
Block block; // make a new random Block
// starting positions:
int x = 1;
int y = -3;
// print image until scrolled down off the screen
while (y < 6) {
......@@ -183,10 +198,10 @@ void debug_test() {
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
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment