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.
Dependencies: mbed
Revision 3:489437d4ebd7, committed 2018-04-18
- Comitter:
- RehamFaqehi
- Date:
- Wed Apr 18 18:05:14 2018 +0000
- Parent:
- 2:3fd0d3d69556
- Child:
- 4:8c6723798227
- Commit message:
- Rocket now is moving with the joystick
Changed in this revision
--- a/GameEngine/GameEngine.cpp Wed Apr 18 17:45:07 2018 +0000
+++ b/GameEngine/GameEngine.cpp Wed Apr 18 18:05:14 2018 +0000
@@ -28,3 +28,7 @@
}
+void GameEngine::update(Gamepad &pad, N5110 &lcd)
+{
+ _rocket.update(_d,_mag, lcd);
+}
--- a/GameEngine/GameEngine.h Wed Apr 18 17:45:07 2018 +0000
+++ b/GameEngine/GameEngine.h Wed Apr 18 18:05:14 2018 +0000
@@ -16,6 +16,7 @@
void init();
void read_input(Gamepad &g_pad);
void draw(N5110 &lcd);
+ void update(Gamepad &pad, N5110 &lcd);
private:
--- a/Rocket/Rocket.cpp Wed Apr 18 17:45:07 2018 +0000
+++ b/Rocket/Rocket.cpp Wed Apr 18 18:05:14 2018 +0000
@@ -32,3 +32,33 @@
};
lcd.drawSprite(_x,_y,7,10,(int *)sprite);
}
+
+void Rocket::update(Direction d,float mag, N5110 &lcd)
+{
+ _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
+
+ // update y and x values depending on direction of movement
+ if (d == N) {
+ _y-=_speed;
+ } else if (d == S) {
+ _y+=_speed;
+ }else if (d == W) {
+ _x-=_speed;
+ } else if (d == E) {
+ _x+=_speed;
+ }
+
+ // check the rocket coordinates so it doesn't go off screen
+ if (_y < 1) {
+ _y = 1;
+ }
+ if (_y > HEIGHT - 5) {
+ _y = HEIGHT - 5;
+ }
+ if (_x < 1) {
+ _x = 1;
+ }
+ if (_x > WIDTH - 7) {
+ _x = WIDTH - 7;
+ }
+}
\ No newline at end of file
--- a/Rocket/Rocket.h Wed Apr 18 17:45:07 2018 +0000
+++ b/Rocket/Rocket.h Wed Apr 18 18:05:14 2018 +0000
@@ -13,22 +13,14 @@
~Rocket();
void init();
void draw(N5110 &lcd);
- void drawFullHearts(N5110 &lcd);
- void drawTwoHearts(N5110 &lcd);
- void drawOneHearts(N5110 &lcd);
- void update(Direction d,float mag, N5110 &lcd);
- Vector2D get_pos();
- void add_score();
- int get_score();
+ void update(Direction d,float mag, N5110 &lcd);
-
private:
int _x;
int _y;
int _speed;
- Vector2D p;
- int _score;
+
};
#endif
\ No newline at end of file
--- a/main.cpp Wed Apr 18 17:45:07 2018 +0000
+++ b/main.cpp Wed Apr 18 18:05:14 2018 +0000
@@ -38,6 +38,8 @@
// game loop
while (1) {
+ game.read_input(g_pad);
+ game.update(g_pad,lcd);
render();
wait(1.0f/fps);
}