demo
Dependencies: mbed Gamepad N5110
Diff: the_wall/the_wall.cpp
- Revision:
- 0:ba32cfe0051e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/the_wall/the_wall.cpp Thu May 14 12:57:32 2020 +0000 @@ -0,0 +1,46 @@ +#include "the_wall.h" + +the_wall::the_wall() +{ + +} + +the_wall::~the_wall() +{ + +} + +void the_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 the_wall::draw1(N5110 &lcd) { + // draw wall in screen buffer. + lcd.drawRect(_x,0,_width,_height,FILL_BLACK); +} + +void the_wall::draw2(N5110 &lcd) { + lcd.drawRect(_x,(_gap + _height),_width,(HEIGHT - (_gap + _height)),FILL_BLACK); // draw the wall near the bottom +} + +void the_wall::update() { + _x -= _speed; // speed is arbitrary, could be changed in the future, and the wall is shifting to left +} + +void the_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 the_wall::get_x() { // get x position and wall height for collision logic function + return _x; +} +int the_wall::get_height() { + return _height; +} \ No newline at end of file