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: TankL/Tank.cpp
- Revision:
- 12:9e6d5d0a0c82
- Parent:
- 11:4e2eb64031a0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TankL/Tank.cpp Sun Apr 14 15:58:12 2019 +0000
@@ -0,0 +1,89 @@
+/* Tank.cpp
+Produces tank on the left side of the
+lcd and dictates it's movement
+1.4.19
+*/
+#include "Tank.h"
+
+Tank::Tank()
+{
+
+}
+
+Tank::~Tank()
+{
+
+}
+
+int Tank::get_position_x()
+{
+ return _position_x;
+}
+
+int Tank::get_position_y()
+{
+ return _position_y;
+}
+
+int Tank::get_hitbox(int i)
+{
+ return _hitbox[i];
+}
+
+int Tank::get_health()
+{
+ return _health;
+}
+
+void Tank::set_position(int x, int y)
+{
+ _position_x = x;
+ _position_y = y;
+}
+
+void Tank::set_health(int h)
+{
+ _health = h;
+}
+
+void Tank::set_speed(int s)
+{
+ _speed = s;
+}
+
+void Tank::set_angle(float angle)
+{
+ _angle = angle;
+}
+
+void Tank::move_position(int d)
+{
+ int slowness = 9 - _speed;
+ int i = _move_counter % slowness;
+ if (d > 0) {
+ if (i == 0) {_position_x++;}
+ _move_counter++;
+ }
+ else if (d < 0) {
+ if (i == 0) {_position_x--;}
+ _move_counter--;
+ }
+}
+
+void Tank::lose_health()
+{
+ _health--;
+/* if (_health <= 0) right player wins
+{} */
+}
+
+void Tank::generate_hitbox()
+{
+ int i = 0;
+ for (int i0 = 0; i0 < 4; i0++) {
+ for (int i1 = 1; i1 < 11; i1++) {
+ _hitbox[i] = (i0 + _position_y) * 84 + _position_x + i1;
+ i++;
+ }
+ }
+}
\ No newline at end of file