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.
Spaceship/Spaceship.cpp
- Committer:
- evanso
- Date:
- 2020-04-14
- Revision:
- 4:0df2b85e47f1
- Parent:
- 3:dee187b8b30c
- Child:
- 5:acd809cc824c
File content as of revision 4:0df2b85e47f1:
#include "Spaceship.h"
const int k_spaceship_sprite[4][13] = {
{ 1,1,1,1,1,1,0,0,0,0,0,0,0 },
{ 0,1,1,1,1,1,1,1,1,0,0,0,0 },
{ 1,1,1,1,1,1,1,1,1,1,1,1,1 },
{ 0,0,1,1,1,1,1,0,0,0,0,0,0 },
};
Spaceship::Spaceship() {
}
Spaceship::~Spaceship() {
}
void Spaceship::init() {
position_x_spaceship_ = 40;
position_y_spaceship_ = 20;
}
void Spaceship::draw(N5110 &lcd) {
// Draws spaceships at defined x and y positions
lcd.drawSprite(position_x_spaceship_, position_y_spaceship_, 4, 13, (int*)k_spaceship_sprite);
}
void Spaceship::clear_spaceship(N5110 &lcd){
// Clears spaceship from LCD by drawing a white sprite
lcd.drawRect(position_x_spaceship_, position_y_spaceship_, 13, 4, FILL_WHITE);
}
void Spaceship::movement(Gamepad &pad){
Direction joystick_direction = pad.get_direction();
// Changes x and y postion values depending on joystick input
if(joystick_direction == N){
position_y_spaceship_+= -1;
}else if(joystick_direction == S){
position_y_spaceship_+= 1;
}else if(joystick_direction == E){
position_x_spaceship_+= 2;
}else if(joystick_direction == W){
position_x_spaceship_-= 2;
}
}