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: TanksEngine/TanksEngine.cpp
- Revision:
- 14:fe2e16cdf219
- Parent:
- 13:feadff02d3f7
- Child:
- 15:fa5282fcd134
--- a/TanksEngine/TanksEngine.cpp Wed Apr 17 14:03:14 2019 +0000
+++ b/TanksEngine/TanksEngine.cpp Wed Apr 17 17:24:02 2019 +0000
@@ -27,12 +27,14 @@
_tankl.set_health(6);
_tankr.set_health(6);
_turn = 1;
- _grav = 0.03;
+ _grav = 0.035;
+ _wind = 0.00005 * (-100 + rand() % 201);
_fire = false;
_move = 0;
_turn_timer = 10;
cooldownl = -1;
cooldownr = -1;
+
}
void TanksEngine::left_tank_turn(Graphics &graphics, Gamepad &pad)
@@ -57,8 +59,10 @@
{ // depending on current turn
graphics.draw_tank_l(_tankl.get_position_x(), _tankl.get_position_y(), lcd);
if (_turn == 1) {
- graphics.draw_turret_l(_tankl.get_position_x(), _tankl.get_position_y(), _angle, lcd);
-
+ graphics.draw_turret_l(_tankl.get_position_x(), _tankl.get_position_y(), _angle, lcd);
+ if (_mag >= 0.5) {
+ graphics.draw_reticle(_tankl.get_position_x(), _tankl.get_position_y(), _angle, lcd);
+ }
}
if (_turn == 2 || _turn == 4) {
graphics.draw_projectile(_proj.get_position_x(), _proj.get_position_y(), lcd);
@@ -66,6 +70,12 @@
graphics.draw_tank_r(_tankr.get_position_x(), _tankr.get_position_y(), lcd);
if (_turn == 3) {
graphics.draw_turret_r(_tankr.get_position_x(), _tankr.get_position_y(), _angle, lcd);
+ if (_mag >= 0.5) {
+ graphics.draw_reticle(_tankr.get_position_x(), _tankr.get_position_y(), _angle, lcd);
+ }
+ }
+ if (_turn == 1 || _turn == 3) {
+ graphics.draw_wind_bar(_wind, lcd);
}
}
@@ -111,13 +121,15 @@
{
if (_turn == 2) { _turn = 3; }
if (_turn == 4) { _turn = 1; }
- _wind = 0.005;
+ srand(time(0));
+ _wind = 0.00005 * (-100 + rand() % 201);
}
void TanksEngine::read_input(Gamepad &pad)
{
_vel = 1.15 + pad.read_pot();
_angle = pad.get_angle();
+ _mag = pad.get_mag();
if (pad.check_event(Gamepad::L_PRESSED) == true && cooldownl < 0) {
_move = -1 * !_move; // toggle movement to the left
cooldownl = 10;
@@ -156,10 +168,14 @@
bool TanksEngine::_collision_pm(N5110 &lcd, Projectile _proj) // detects projectile hitting the MAP
{
- if (_proj.get_position_x() >= 31 && _proj.get_position_x() <= 54) {
- if (lcd.getPixel(_proj.get_position_x(),48 - _proj.get_position_y()) == 1) {
+ int x = _proj.get_position_x();
+ int y = _proj.get_position_y();
+ if (x >= 31 && x <= 54) {
+ if (lcd.getPixel(x, 48 - y) == 1) {
+ // lcd.setPixel(x, y, false);
return true;
- } else if (lcd.getPixel(_proj.get_position_x() + 1,48 - _proj.get_position_y()) == 1) {
+ } else if (lcd.getPixel(x + 1,48 - y) == 1) {
+ // lcd.setPixel(x, y, false);
return true;
} else { return false ;}
}