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@14:13e82f720bea, 2019-05-09 (annotated)
- Committer:
- davidwst421
- Date:
- Thu May 09 06:19:58 2019 +0000
- Revision:
- 14:13e82f720bea
- Parent:
- 8:97576c8761a8
final version with full comment on most functions/variables
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| davidwst421 | 0:fd8eda608206 | 1 | #include "Wall.h" |
| davidwst421 | 0:fd8eda608206 | 2 | |
| davidwst421 | 0:fd8eda608206 | 3 | Wall::Wall() |
| davidwst421 | 0:fd8eda608206 | 4 | { |
| davidwst421 | 0:fd8eda608206 | 5 | |
| davidwst421 | 0:fd8eda608206 | 6 | } |
| davidwst421 | 0:fd8eda608206 | 7 | |
| davidwst421 | 0:fd8eda608206 | 8 | Wall::~Wall() |
| davidwst421 | 0:fd8eda608206 | 9 | { |
| davidwst421 | 0:fd8eda608206 | 10 | |
| davidwst421 | 0:fd8eda608206 | 11 | } |
| davidwst421 | 0:fd8eda608206 | 12 | |
| davidwst421 | 0:fd8eda608206 | 13 | void Wall::init(int x,int gap,int width,int speed) { |
| davidwst421 | 0:fd8eda608206 | 14 | |
| davidwst421 | 14:13e82f720bea | 15 | _x = x; // wall x starting postion and updating position |
| davidwst421 | 14:13e82f720bea | 16 | _gap = gap; // gap represents the distance between the wall |
| davidwst421 | 8:97576c8761a8 | 17 | int uncertainty = rand() % (47 - _gap); |
| davidwst421 | 14:13e82f720bea | 18 | _height = uncertainty; // get random height for the wall |
| davidwst421 | 14:13e82f720bea | 19 | _width = width; // fixed width |
| davidwst421 | 14:13e82f720bea | 20 | _speed = speed; // adjuctable speed |
| davidwst421 | 0:fd8eda608206 | 21 | } |
| davidwst421 | 0:fd8eda608206 | 22 | |
| davidwst421 | 0:fd8eda608206 | 23 | void Wall::draw1(N5110 &lcd) { |
| davidwst421 | 0:fd8eda608206 | 24 | // draw wall in screen buffer. |
| davidwst421 | 0:fd8eda608206 | 25 | lcd.drawRect(_x,0,_width,_height,FILL_BLACK); |
| davidwst421 | 0:fd8eda608206 | 26 | } |
| davidwst421 | 0:fd8eda608206 | 27 | |
| davidwst421 | 0:fd8eda608206 | 28 | void Wall::draw2(N5110 &lcd) { |
| davidwst421 | 14:13e82f720bea | 29 | lcd.drawRect(_x,(_gap + _height),_width,(HEIGHT - (_gap + _height)),FILL_BLACK); // draw the wall near the bottom |
| davidwst421 | 0:fd8eda608206 | 30 | } |
| davidwst421 | 0:fd8eda608206 | 31 | |
| davidwst421 | 0:fd8eda608206 | 32 | void Wall::update() { |
| davidwst421 | 14:13e82f720bea | 33 | _x -= _speed; // speed is arbitrary, could be changed in the future, and the wall is shifting to left |
| davidwst421 | 0:fd8eda608206 | 34 | } |
| davidwst421 | 0:fd8eda608206 | 35 | |
| davidwst421 | 14:13e82f720bea | 36 | void Wall::reset() { // when the wall is off from the left screen, replace it back to the right side and continue the game |
| davidwst421 | 7:193c0fd7afdd | 37 | _x = 149; |
| davidwst421 | 8:97576c8761a8 | 38 | int uncertainty = rand() % (47 - _gap); |
| davidwst421 | 1:f09ff0ed98fd | 39 | _height = uncertainty; |
| davidwst421 | 0:fd8eda608206 | 40 | } |
| davidwst421 | 0:fd8eda608206 | 41 | |
| davidwst421 | 14:13e82f720bea | 42 | int Wall::get_x() { // get x position and wall height for collision logic function |
| davidwst421 | 1:f09ff0ed98fd | 43 | return _x; |
| davidwst421 | 1:f09ff0ed98fd | 44 | } |
| davidwst421 | 1:f09ff0ed98fd | 45 | int Wall::get_height() { |
| davidwst421 | 0:fd8eda608206 | 46 | return _height; |
| davidwst421 | 0:fd8eda608206 | 47 | } |