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
Wall/Wall.cpp
- Committer:
- davidwst421
- Date:
- 2019-05-09
- Revision:
- 16:a5f5bc55d1bb
- Parent:
- 14:13e82f720bea
File content as of revision 16:a5f5bc55d1bb:
#include "Wall.h"
Wall::Wall()
{
}
Wall::~Wall()
{
}
void Wall::init(int x,int gap,int width,int speed) {
_x = x; // wall x starting postion and updating position
_gap = gap; // gap represents the distance between the wall
int uncertainty = rand() % (47 - _gap);
_height = uncertainty; // get random height for the wall
_width = width; // fixed width
_speed = speed; // adjuctable speed
}
void Wall::draw1(N5110 &lcd) {
// draw wall in screen buffer.
lcd.drawRect(_x,0,_width,_height,FILL_BLACK);
}
void Wall::draw2(N5110 &lcd) {
lcd.drawRect(_x,(_gap + _height),_width,(HEIGHT - (_gap + _height)),FILL_BLACK); // draw the wall near the bottom
}
void Wall::update() {
_x -= _speed; // speed is arbitrary, could be changed in the future, and the wall is shifting to left
}
void Wall::reset() { // when the wall is off from the left screen, replace it back to the right side and continue the game
_x = 149;
int uncertainty = rand() % (47 - _gap);
_height = uncertainty;
}
int Wall::get_x() { // get x position and wall height for collision logic function
return _x;
}
int Wall::get_height() {
return _height;
}