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
Rocket/Rocket.cpp
- Committer:
- RehamFaqehi
- Date:
- 2018-04-24
- Revision:
- 7:06c86ec1f19d
- Parent:
- 6:7b733b2a6cf6
- Child:
- 9:e70179ff61c5
File content as of revision 7:06c86ec1f19d:
#include "Rocket.h"
// nothing doing in the constructor and destructor
Rocket::Rocket()
{
}
Rocket::~Rocket()
{
}
void Rocket::init()
{
_x = WIDTH/2 ;
_y = HEIGHT/2 ;
_speed = 1;
}
void Rocket::draw(N5110 &lcd)
{
int sprite[7][10] = {
{ 0,1,1,1,1,0,0,0,0,0, },
{ 0,0,1,0,0,1,1,0,0,0, },
{ 0,0,0,1,0,0,0,1,1,0, },
{ 0,0,0,1,1,1,1,1,1,1, },
{ 0,0,0,1,0,0,0,1,1,0, },
{ 0,0,1,0,0,1,1,0,0,0, },
{ 0,1,1,1,1,0,0,0,0,0, },
};
lcd.drawSprite(_x,_y,7,10,(int *)sprite);
}
void Rocket::update(Direction d,float mag, N5110 &lcd)
{
_speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
// update y and x values depending on direction of movement
if (d == N) {
_y-=_speed;
} else if (d == S) {
_y+=_speed;
}else if (d == W) {
_x-=_speed;
} else if (d == E) {
_x+=_speed;
}
// check the rocket coordinates so it doesn't go off screen
if (_y < 1) {
_y = 1;
}
if (_y > HEIGHT - 5) {
_y = HEIGHT - 5;
}
if (_x < 1) {
_x = 1;
}
if (_x > WIDTH - 7) {
_x = WIDTH - 7;
}
}
Vector2D Rocket::get_pos() {
Vector2D p = {_x,_y};
return p;
}
void Rocket::add_score()
{
_score++;
}
int Rocket::get_score()
{
return _score;
}
void Rocket::drawFullHearts(N5110 &lcd)
{
int sprite[5][17] = {
{ 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
{ 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, },
{ 1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1, },
{ 0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0, },
{ 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
};
lcd.drawSprite(0,0,5,17,(int *)sprite);
}
void Rocket::drawTwoHearts(N5110 &lcd)
{
int sprite[5][17] = {
{ 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
{ 1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1, },
{ 1,1,1,1,1,0,1,1,1,1,1,0,1,0,0,0,1, },
{ 0,1,1,1,0,0,0,1,1,1,0,0,0,1,0,1,0, },
{ 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
};
lcd.drawSprite(0,0,5,17,(int *)sprite);
}
void Rocket::drawOneHeart(N5110 &lcd)
{
int sprite[5][17] = {
{ 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1, },
{ 1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1, },
{ 1,1,1,1,1,0,1,0,0,0,1,0,1,0,0,0,1, },
{ 0,1,1,1,0,0,0,1,0,1,0,0,0,1,0,1,0, },
{ 0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0, },
};
lcd.drawSprite(1,1,5,17,(int *)sprite);
}