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
Diff: Bullet/Bullet.cpp
- Revision:
- 100:b0e9c067d80a
- Child:
- 126:c63c5ad39f73
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Bullet/Bullet.cpp Sun May 05 13:05:57 2019 +0000
@@ -0,0 +1,82 @@
+#include "Bullet.h"
+
+
+bullet::bullet()
+{
+
+}
+
+bullet::~bullet()
+{
+
+}
+
+
+
+const int bullet[4][10] = {
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,1,1,1,1,0,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+};
+
+
+
+
+void bullet::init(int size,int speed)
+{
+
+
+ srand(time(NULL));
+ int direction = rand() % 4; // randomise initial direction.
+
+ // 4 possibilities. Get random modulo and set velocities accordingly
+ if (direction == 0) {
+ _velocity.x = speed;
+ _velocity.y = speed;
+ } else if (direction == 1) {
+ _velocity.x = speed;
+ _velocity.y = -speed;
+ } else if (direction == 2) {
+ _velocity.x = speed;
+ _velocity.y = speed;
+ } else {
+ _velocity.x = -speed;
+ _velocity.y = -speed;
+ }
+
+
+
+}
+
+
+void bullet::draw(N5110 &lcd)
+{
+ lcd.drawSprite(x_bullet,y_bullet,4,10,(int *)bullet);
+
+}
+
+void bullet::update()
+{
+ _x += _velocity.x;
+ _y += _velocity.y;
+}
+
+
+void bullet::set_velocity(Vector2D v)
+{
+ _velocity.x = v.x;
+ _velocity.y = v.y;
+}
+
+Vector2D bullet::get_velocity()
+{
+ Vector2D v = {_velocity.x,_velocity.y};
+ return v;
+}
+
+Vector2D bullet::get_pos()
+{
+ Vector2D p = {_x,_y};
+ return p;
+}