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 FXOS8700CQ mbed-rtos
Diff: Game_two/Insta_files/Insta.cpp
- Revision:
- 14:abe64fe0b6a5
- Child:
- 19:903d67bb0dea
diff -r 02002658e718 -r abe64fe0b6a5 Game_two/Insta_files/Insta.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Game_two/Insta_files/Insta.cpp Thu Apr 18 04:53:04 2019 +0000
@@ -0,0 +1,109 @@
+#include "Insta.h"
+
+Insta::Insta()
+{
+
+}
+
+Insta::~Insta()
+{
+
+}
+
+void Insta::init(int speed)
+{
+ int position = rand() % 8; // randomise initial direction.
+
+ // 4 possibilities. Get random modulo and set velocities accordingly
+ if (position == 0) {
+ _x = -9;
+ _y = 12;
+ _velocity.x = speed * 2;
+ _velocity.y = speed;
+ } else if (position == 1) {
+ _x = 20;
+ _y = -9;
+ _velocity.x = speed * 2;
+ _velocity.y = speed *2;
+ } else if (position == 2) {
+ _x = 60;
+ _y = -9;
+ _velocity.x = -speed * 2;
+ _velocity.y = speed *2;
+ } else if (position == 3) {
+ _x = 83;
+ _y = 14;
+ _velocity.x = -speed * 3;
+ _velocity.y = speed;
+ } else if (position == 4) {
+ _x = 83;
+ _y = 35;
+ _velocity.x = -speed * 3;
+ _velocity.y = -speed *2;
+ } else if (position == 5) {
+ _x = 60;
+ _y = 47;
+ _velocity.x = -speed * 2;
+ _velocity.y = -speed *2;
+ } else if (position == 6) {
+ _x = 20;
+ _y = 47;
+ _velocity.x = speed * 2;
+ _velocity.y = -speed *2;
+ } else if (position == 7) {
+ _x = -9;
+ _y = 30;
+ _velocity.x = speed * 3;
+ _velocity.y = -speed *2;
+ }
+}
+
+void Insta::draw(N5110 &lcd)
+{
+ int Insta_data[12][12] = {
+ {0,0,1,1,1,1,1,1,1,1,0,0},
+ {0,1,1,1,1,1,1,1,1,1,1,0},
+ {1,1,1,0,0,0,0,0,0,1,1,1},
+ {1,1,0,1,1,1,1,1,0,0,1,1},
+ {1,1,0,1,1,0,0,1,1,0,1,1},
+ {1,1,0,1,0,1,1,0,1,0,1,1},
+ {1,1,0,1,0,1,1,0,1,0,1,1},
+ {1,1,0,1,1,0,0,1,1,0,1,1},
+ {1,1,0,1,1,1,1,1,1,0,1,1},
+ {1,1,1,0,0,0,0,0,0,1,1,1},
+ {0,1,1,1,1,1,1,1,1,1,1,0},
+ {0,0,1,1,1,1,1,1,1,1,0,0},
+ };
+
+ lcd.drawSprite(_x, _y, 12, 12, (int*)Insta_data);
+}
+
+void Insta::update()
+{
+ _x += _velocity.x;
+ _y += _velocity.y;
+}
+
+void Insta::set_velocity(Vector2D v)
+{
+ _velocity.x = v.x;
+ _velocity.y = v.y;
+}
+
+Vector2D Insta::get_velocity()
+{
+ Vector2D v = {_velocity.x,_velocity.y};
+ return v;
+}
+
+Vector2D Insta::get_pos()
+{
+ Vector2D p = {_x,_y};
+ return p;
+}
+
+void Insta::set_pos(Vector2D p)
+{
+ _x = p.x;
+ _y = p.y;
+}
\ No newline at end of file