![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo
Dependencies: mbed Gamepad N5110
the_wall/the_wall.cpp
- Committer:
- Ting12138
- Date:
- 2020-05-14
- Revision:
- 1:7b5a843acc05
- Parent:
- 0:ba32cfe0051e
File content as of revision 1:7b5a843acc05:
#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; }