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
Fork of el17zl by
Ppl/Ppl.cpp
- Committer:
- franklzw
- Date:
- 2019-04-11
- Revision:
- 7:6f8aeadc4370
- Parent:
- 6:6b083e22cb53
- Child:
- 8:83891ea9a5d9
File content as of revision 7:6f8aeadc4370:
#include "Ppl.h"
const int ppl[8][8]= {
{0,0,0,0,1,1,1,0},
{0,0,0,0,1,0,1,0},
{0,0,0,0,1,1,1,0},
{1,0,0,0,0,1,0,0},
{0,1,1,0,0,1,0,0},
{0,0,0,1,1,1,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,1,1,0,1,1},
};
Ppl::Ppl()
{
}
Ppl::~Ppl()
{
}
void Ppl::init(int x0, int y0)
{
_x = x0;
_y = y0;
}
void Ppl::draw(N5110 &lcd)
{
lcd.drawSprite(_x,_y,8,8,(int *)ppl);
}
void Ppl::update(int bb,int ba,int bx,int by,int temp,
int barrier_x,int barrier_y)
{
int temp_x = _x;
int temp_y = _y;
move_ppl(bb,ba,bx,by);
if (hold_beside_barrier(barrier_x,barrier_y)) {
_x = temp_x;
_y = temp_y;
} else {
_x = _x;
_y = _y;
}
hold_ppl_against_wall();
hold_ppl_box_touching(temp);
}
Vector2D Ppl::get_pos()
{
Vector2D p = {_x,_y};
return p;
}
void Ppl::set_pos(Vector2D p)
{
_x = p.x;
_y = p.y;
}
bool Ppl::hold_beside_barrier(int barrier_x,int barrier_y) // check after moving if ppl pos match the barrier
{
// if matched return ture
if (_x == barrier_x &&_y == barrier_y) {
return true;
} else {
return false;
}
}
void Ppl::move_ppl(int bb,int ba,int bx,int by) //move the ppl with respect to the bottom read
{
if (bx ==0 && bb == 0 && by == 0 && ba == 0) {
_x = _x;
_y = _y;
}
if (bx == 1) {
_x = _x-8;
_y = _y;
}
if (bb == 1) {
_x = _x+8;
_y = _y;
}
if (by == 1) {
_y = _y-8;
_x = _x;
}
if (ba == 1) {
_y = _y+8;
_x = _x;
}
}
void Ppl::hold_ppl_box_touching(int temp) //check for box facing wall and hold pos of ppl
{
if (temp == 0 ) {
_y = _y;
_x = _x;
} else if (temp == 1) {
_x = 10;
} else if (temp == 2) {
_x = 66;
} else if (temp == 3) {
_y = 12;
} else if (temp == 4) {
_y = 28;
}
}
void Ppl::hold_ppl_against_wall() // check the y origin to ensure that the paddle doesn't go off screen
{
if (_y < 4) {
_y = 4;
}
if (_y > 36) {
_y = 36;
}
if (_x > 74) {
_x = 74;
}
if (_x < 2) {
_x = 2;
}
}
