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
Floors/Floors.cpp@23:9be87557b89a, 2019-05-08 (annotated)
- Committer:
- el17m2h
- Date:
- Wed May 08 08:46:11 2019 +0000
- Revision:
- 23:9be87557b89a
- Parent:
- 22:0d2ac98a8b48
- Child:
- 24:67dc71a8f009
Added a sprite for the doodler and the enemy.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17m2h | 1:0001cb3eb053 | 1 | #include "Floors.h" |
| el17m2h | 1:0001cb3eb053 | 2 | Floors::Floors(){ |
| el17m2h | 1:0001cb3eb053 | 3 | } |
| el17m2h | 1:0001cb3eb053 | 4 | Floors::~Floors(){ |
| el17m2h | 1:0001cb3eb053 | 5 | } |
| el17m2h | 3:116913e97fd7 | 6 | |
| el17m2h | 11:2041290b5a74 | 7 | void Floors::init(int y, int width, int height){ |
| el17m2h | 1:0001cb3eb053 | 8 | _height = height; |
| el17m2h | 1:0001cb3eb053 | 9 | _width = width; |
| el17m2h | 22:0d2ac98a8b48 | 10 | // x-coordinate initially random: 2-30 or 40-71 so doodler falls to bottom floor |
| el17m2h | 22:0d2ac98a8b48 | 11 | int decide = rand() % 2; |
| el17m2h | 22:0d2ac98a8b48 | 12 | if (decide == 0){ // right |
| el17m2h | 22:0d2ac98a8b48 | 13 | _position.x = 2 + (rand()% 28); |
| el17m2h | 22:0d2ac98a8b48 | 14 | } else { // left |
| el17m2h | 22:0d2ac98a8b48 | 15 | _position.x = 40 + (rand()% 31); |
| el17m2h | 22:0d2ac98a8b48 | 16 | } |
| el17m2h | 14:529f798adae4 | 17 | _position.y = y; |
| el17m2h | 1:0001cb3eb053 | 18 | } |
| el17m2h | 1:0001cb3eb053 | 19 | |
| el17m2h | 1:0001cb3eb053 | 20 | void Floors::draw(N5110 &lcd){ |
| el17m2h | 14:529f798adae4 | 21 | lcd.drawRect(_position.x, _position.y, _width, _height, FILL_BLACK); |
| el17m2h | 1:0001cb3eb053 | 22 | } |
| el17m2h | 1:0001cb3eb053 | 23 | |
| el17m2h | 15:4efa04a6a376 | 24 | void Floors::update(float doodler_pos_y){ |
| el17m2h | 11:2041290b5a74 | 25 | // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen |
| el17m2h | 20:a359092079b0 | 26 | //rectangle (1-82 & 9 - 48 ) |
| el17m2h | 15:4efa04a6a376 | 27 | _doodler_pos_y = doodler_pos_y; |
| el17m2h | 21:6b16ca9834e6 | 28 | if (_position.y > 45 ){ |
| el17m2h | 20:a359092079b0 | 29 | _position.y = 9; |
| el17m2h | 22:0d2ac98a8b48 | 30 | _position.x = 1 + (rand()% 70); |
| el17m2h | 20:a359092079b0 | 31 | place = rand()% 8; |
| el17m2h | 20:a359092079b0 | 32 | if (place == 2){ // 1/8 chance of placing an enemy |
| el17m2h | 20:a359092079b0 | 33 | _eny.init(_position.x, _position.y); |
| el17m2h | 11:2041290b5a74 | 34 | } |
| el17m2h | 20:a359092079b0 | 35 | } |
| el17m2h | 20:a359092079b0 | 36 | if (_doodler_pos_y < 25){ // shift floors once doodler reaches over halfway the screen |
| el17m2h | 15:4efa04a6a376 | 37 | _position.y += 1; |
| el17m2h | 20:a359092079b0 | 38 | _eny.update(_position.x, _position.y); |
| el17m2h | 15:4efa04a6a376 | 39 | } |
| el17m2h | 9:5e53bca2a4c2 | 40 | } |
| el17m2h | 9:5e53bca2a4c2 | 41 | |
| el17m2h | 14:529f798adae4 | 42 | Vector2D Floors::get_position(){ |
| el17m2h | 14:529f798adae4 | 43 | Vector2D p = {_position.x,_position.y}; |
| el17m2h | 9:5e53bca2a4c2 | 44 | return p; |
| el17m2h | 5:8814d6de77d0 | 45 | } |
| el17m2h | 5:8814d6de77d0 | 46 | |
| el17m2h | 14:529f798adae4 | 47 | void Floors::set_position(Vector2D pos){ |
| el17m2h | 14:529f798adae4 | 48 | _position.x = pos.x; |
| el17m2h | 14:529f798adae4 | 49 | _position.y = pos.y; |
| el17m2h | 21:6b16ca9834e6 | 50 | } |