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
Fighter/Fighter.cpp
- Committer:
- ChenZirui
- Date:
- 2020-05-23
- Revision:
- 4:e46c295d4baf
- Parent:
- 3:20bd321071ef
File content as of revision 4:e46c295d4baf:
#include "Fighter.h"
// nothing doing in the constructor and destructor
fighter::fighter()
{
}
fighter::~fighter()
{
}
void fighter::init(int x,int y,int height,int width)
{
_x=WIDTH/2-width/2 ; // horizontal coordinate of fighter
_y=HEIGHT/2-height/2 ; // vertical coordinate of fighte
_height =height;
_width = width;
_speed = 1; // default speed
_score = 0;
}
void fighter::draw(N5110 &lcd);
{
lcd.drawRect(_x+(_height/2)-(_width/2),_y,_width,_height,FILL_BLACK);
lcd.drawRect(_x,_y,_height,_width,FILL_BLACK);
}
void fighter::update(Direction d,float mag)
{
speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
// update y value depending on direction of movement
// North is decrement as origin is at the top-left so decreasing moves up
if (d == N)
{
_y-=_speed;
}else if (d == S)
{
_y+=_speed;
}else if(d == W)
{
_x-=_speed;
}else if(d == E)
{
_x+=_speed;
}else if(d == NE)
{
_y+=_speed;
_x+=_speed;
}else if(d == NW)
{
_y+=_speed;
_x-=_speed;
}else if(d == SE)
{
_y-=_speed;
_x+=_speed;
}else if(d == SW)
{
_y-=_speed;
_x-=_speed;
}
if (_y < 1)
{
_y = 1;
}
if (_y > HEIGHT - _height - 1)
{
_y = HEIGHT - _height - 1;
}
if (_x < 1)
{
_x = 1;
}
if (_x > WIDTH - _width - 1)
{
_x = WIDTH - _width - 1;
}
}
void fighter::add_score()
{
_score++;
}
int fighter::get_score()
{
return _score;
}
Vector2D fighter::get_pos()
{
Vector2D p = {_x,_y};
return p;
}