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
TankL/TankL.cpp
- Committer:
- el17mcd
- Date:
- 2019-04-12
- Revision:
- 10:d4fb12e9e7cd
- Parent:
- 8:d4e419dad90f
- Child:
- 11:4e2eb64031a0
File content as of revision 10:d4fb12e9e7cd:
/* TankL.cpp
Produces tank on the left side of the
lcd and dictates it's movement
1.4.19
*/
#include "TankL.h"
/*
TankL::TankL()
{
}
TankL::~TankL()
{
}
*/
int TankL::get_position_x()
{
return _position_x;
}
int TankL::get_position_y()
{
return _position_y;
}
int TankL::get_hitbox(int i)
{
return _hitbox[i];
}
void TankL::set_position(int x, int y)
{
_position_x = x;
_position_y = y;
}
void TankL::set_health(int h)
{
_health = h;
}
void TankL::set_speed(int s)
{
_speed = s;
}
void TankL::set_angle(float angle)
{
_angle = angle;
}
void TankL::move_position(int d)
{
int slowness = 24 / _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 TankL::lose_health()
{
_health--;
/* if (_health <= 0) right player wins
{} */
}
void TankL::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++;
}
}
}
void TankL::draw(N5110 &lcd)
{
const int tank_l_spr[6][10] = {
{ 0,0,0,1,1,1,0,0,0,0 },
{ 0,0,1,1,1,1,1,0,0,0 },
{ 0,0,1,1,1,1,1,1,1,0 },
{ 1,1,1,1,1,1,1,1,1,1 },
{ 1,0,1,0,1,0,1,0,1,0 },
{ 0,1,0,1,0,1,0,1,0,0 },
};
lcd.drawSprite(_position_x,42 - _position_y,6,10,(int *)tank_l_spr);
if (_angle < 18) {
const int turret_spr1[3][7] = {
{ 0,0,1,0,0,0,0 },
{ 0,1,1,1,1,1,1 },
{ 1,1,1,1,1,1,0 },
};
lcd.drawSprite(2 + _position_x,42 - _position_y,3,7,(int *)turret_spr1);
}
else if (_angle >= 18 && _angle < 36) {
const int turret_spr2[3][7] = {
{ 0,0,1,1,1,1,1 },
{ 0,1,1,1,1,0,0 },
{ 1,1,1,1,1,1,0 },
};
lcd.drawSprite(2 + _position_x,42 - _position_y,3,7,(int *)turret_spr2);
}
else if (_angle >= 36 && _angle < 54) {
const int turret_spr3[4][7] = {
{ 0,0,0,0,1,0,0 },
{ 0,0,1,1,0,0,0 },
{ 0,1,1,1,0,0,0 },
{ 1,1,1,1,1,1,0 },
};
lcd.drawSprite(2 + _position_x,41 - _position_y,4,7,(int *)turret_spr3);
}
else if (_angle >= 54 && _angle < 72) {
const int turret_spr4[4][7] = {
{ 0,0,0,1,0,0,0 },
{ 0,0,1,1,0,0,0 },
{ 0,1,1,1,0,0,0 },
{ 1,1,1,1,1,1,0 },
};
lcd.drawSprite(2 + _position_x,41 - _position_y,4,7,(int *)turret_spr4);
}
else {
const int turret_spr5[5][7] = {
{ 0,0,1,0,0,0,0 },
{ 0,0,1,0,0,0,0 },
{ 0,0,1,0,0,0,0 },
{ 0,1,1,1,0,0,0 },
{ 1,1,1,1,1,1,0 },
};
lcd.drawSprite(2 + _position_x,40 - _position_y,5,7,(int *)turret_spr5);
}
}