Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:73242667a3f0, committed 2019-02-24
- Comitter:
- muizzu1
- Date:
- Sun Feb 24 14:36:12 2019 +0000
- Commit message:
- ff
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| microbit.lib | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sun Feb 24 14:36:12 2019 +0000
@@ -0,0 +1,51 @@
+#include "MicroBit.h"
+#include <cstdlib>
+
+MicroBit uBit;
+int player_x = 2;
+int enemy_x = rand() % 4 + 0;
+int enemy_y = 0;
+
+int main()
+{
+ // Initialise the micro:bit runtime.
+ uBit.init();
+ while (true)
+ {
+ uBit.display.clear(); //Refreshes display through each loop
+
+ // Setting the player and enemies
+ uBit.display.image.setPixelValue(player_x, 4, 255);
+ uBit.display.image.setPixelValue(enemy_x, enemy_y, 255);
+
+ // If player hits an enemy, then gameover
+ if (enemy_y == 4 && enemy_x == player_x) {
+ break;
+ }
+
+ // Button events. Player moves left or right
+ if (uBit.buttonA.isPressed() && player_x > 0)
+ {
+ player_x -= 1;
+ }
+ if (uBit.buttonB.isPressed() && player_x < 4)
+ {
+ player_x += 1;
+ }
+
+ // Enemy moves down the y
+ // If enemy is all the way down, random x is given from the top
+ enemy_y += 1;
+ if (enemy_y > 4){
+ enemy_y = 0;
+ enemy_x = rand() % 4 + 0;
+ }
+ // sleep() function to slow down the enemy
+ uBit.sleep(250);
+
+ }
+ uBit.display.scroll("GAME OVER");
+
+ release_fiber();
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/microbit.lib Sun Feb 24 14:36:12 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Lancaster-University/code/microbit/#4b89e7e3494f