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 1:25f13b341b11, committed 2020-07-08
- Comitter:
- ahmeou
- Date:
- Wed Jul 08 17:22:58 2020 +0000
- Parent:
- 0:17bdfb0e7069
- Child:
- 2:8f1130b99681
- Commit message:
- error was unbalanced parenthesis in bullet class, ; Fixed
Changed in this revision
--- a/gameEngine/inc/Bullet.h Wed Jul 08 16:35:55 2020 +0000
+++ b/gameEngine/inc/Bullet.h Wed Jul 08 17:22:58 2020 +0000
@@ -10,6 +10,7 @@
}else{
setY(y-1);
}
+ }
};
#endif
\ No newline at end of file
--- a/gameEngine/inc/Screen.h Wed Jul 08 16:35:55 2020 +0000
+++ b/gameEngine/inc/Screen.h Wed Jul 08 17:22:58 2020 +0000
@@ -2,6 +2,7 @@
#define SCREEN_H
#include "MicroBit.h"
+#include "Sprite.h"
class Screen{
private:
@@ -19,7 +20,7 @@
buf[sprite.getX()][sprite.getY()] = 255;
}
void refresh(){
- (*m_ubit).display.clear();
+ m_ubit->display.clear();
for(int row = 0; row < 5; row++){
for(int col = 0; col < 5; col++){
m_ubit->display.image.setPixelValue(row, col, buf[row][col]);
--- a/gameEngine/inc/Spacecraft.h Wed Jul 08 16:35:55 2020 +0000
+++ b/gameEngine/inc/Spacecraft.h Wed Jul 08 17:22:58 2020 +0000
@@ -1,6 +1,6 @@
#ifndef SPACECRAFT_H
#define SPACECRAFT_H
-#include "game.h"
+#include "Sprite.h"
class Spacecraft: public Sprite{
private:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gameEngine/inc/Sprite.h Wed Jul 08 17:22:58 2020 +0000
@@ -0,0 +1,19 @@
+#ifndef SPRITE_H
+#define SPRITE_H
+
+class Sprite{
+ private:
+ int m_x;
+ int m_y;
+
+ public:
+ Sprite();
+ Sprite(int x, int y);
+ int getX();
+ int getY();
+ void setX(int x);
+ void setY(int y);
+ bool hitBy(Sprite another);
+};
+
+#endif
\ No newline at end of file
--- a/gameEngine/inc/game.h Wed Jul 08 16:35:55 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef GAME_H
-#define GAME_H
-
-class Sprite{
- private:
- int m_x;
- int m_y;
-
- public:
- Sprite();
- Sprite(int x, int y);
- int getX();
- int getY();
- void setX(int x);
- void setY(int y);
- bool hitBy(Sprite another);
-};
-
-#include "Bullet.h"
-#include "Spacecraft.h"
-
-#endif
\ No newline at end of file
--- a/gameEngine/module.json Wed Jul 08 16:35:55 2020 +0000
+++ b/gameEngine/module.json Wed Jul 08 17:22:58 2020 +0000
@@ -1,6 +1,6 @@
{
"name": "game engine",
- "version": "1.0.0",
+ "version": "2.0.0",
"description": "A simple game engine for the MicroBit",
"license": "MIT",
"extraIncludes": [
--- a/gameEngine/source/game.cpp Wed Jul 08 16:35:55 2020 +0000
+++ b/gameEngine/source/game.cpp Wed Jul 08 17:22:58 2020 +0000
@@ -1,13 +1,13 @@
-#include "game.h"
+#include "Sprite.h"
Sprite::Sprite(){
- setX(0);
- setY(0);
+ m_x = 0;
+ m_y = 0;
}
Sprite::Sprite(int x, int y){
- setX(x);
- setY(y);
+ m_x = 0;
+ m_y = 0;
}
void Sprite::setX(int x){
--- a/main.cpp Wed Jul 08 16:35:55 2020 +0000
+++ b/main.cpp Wed Jul 08 17:22:58 2020 +0000
@@ -1,10 +1,12 @@
#include "MicroBit.h"
-#include "game.h"
#include "Screen.h"
+#include "Bullet.h"
+#include "Spacecraft.h"
MicroBit ubit;
int main(){
+
Screen screen(&ubit);
Spacecraft spacecraft;
@@ -12,24 +14,23 @@
bullet.setX(spacecraft.getX());
bullet.setY(spacecraft.getY());
-// while(true){
-// screen.draw(bullet);
-// screen.draw(spacecraft);
-// screen.refresh();
-//
-// // move spacecraft
-// spacecraft.setX(spacecraft.getX() + 1 - 2 * ubit.random(1));
-//
-// // move bullet
-// for(int i = 0; i < 2; i++){
-// if(bullet.getY() == 0)
-// bullet.setX(spacecraft.getX());
-// bullet.move();
-// ubit.sleep(200);
-// }
-//
-// }
-
+ for(int i = 0; i < 100; i++){
+ screen.draw(bullet);
+ screen.draw(spacecraft);
+ screen.refresh();
+
+ // move spacecraft
+ spacecraft.setX(spacecraft.getX() + 1 - 2 * ubit.random(1));
+
+ // move bullet
+ for(int i = 0; i < 2; i++){
+ if(bullet.getY() == 0)
+ bullet.setX(spacecraft.getX());
+ bullet.move();
+ ubit.sleep(200);
+ }
+
+ }
+
release_fiber();
-}
-
\ No newline at end of file
+}
\ No newline at end of file