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@19:5a7b0cdf013b, 2019-04-25 (annotated)
- Committer:
- el17m2h
- Date:
- Thu Apr 25 08:43:46 2019 +0000
- Revision:
- 19:5a7b0cdf013b
- Parent:
- 15:4efa04a6a376
- Child:
- 20:a359092079b0
Added a game over function to the main file so that once the doodler hits the floor the game is finalized.
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 | 19:5a7b0cdf013b | 10 | // x-coordinate initially random: 2 left, 70 right |
| el17m2h | 19:5a7b0cdf013b | 11 | int _array[] = {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70}; |
| el17m2h | 13:10851784af9a | 12 | // excluding centre so doodler falls to the floor at bottom |
| el17m2h | 14:529f798adae4 | 13 | _position.x = _array[rand()%(sizeof(_array) / sizeof *_array)]; |
| el17m2h | 14:529f798adae4 | 14 | _position.y = y; |
| el17m2h | 1:0001cb3eb053 | 15 | } |
| el17m2h | 1:0001cb3eb053 | 16 | |
| el17m2h | 1:0001cb3eb053 | 17 | void Floors::draw(N5110 &lcd){ |
| el17m2h | 14:529f798adae4 | 18 | lcd.drawRect(_position.x, _position.y, _width, _height, FILL_BLACK); |
| el17m2h | 1:0001cb3eb053 | 19 | } |
| el17m2h | 1:0001cb3eb053 | 20 | |
| el17m2h | 15:4efa04a6a376 | 21 | void Floors::update(float doodler_pos_y){ |
| el17m2h | 11:2041290b5a74 | 22 | // when they leave the screen they will re-appear in random x-coordinate so that 10 floors are always on screen |
| el17m2h | 19:5a7b0cdf013b | 23 | //rectangle (2-81 & 10 - 45) |
| el17m2h | 15:4efa04a6a376 | 24 | _doodler_pos_y = doodler_pos_y; |
| el17m2h | 19:5a7b0cdf013b | 25 | if (_position.y > 43 ){ |
| el17m2h | 19:5a7b0cdf013b | 26 | _position.y = 10; |
| el17m2h | 19:5a7b0cdf013b | 27 | _position.x = 2 + (rand()% 68); |
| el17m2h | 11:2041290b5a74 | 28 | } |
| el17m2h | 15:4efa04a6a376 | 29 | if ( _doodler_pos_y < 25){ // shift floors once doodler reaches over halfway the screen |
| el17m2h | 15:4efa04a6a376 | 30 | _position.y += 1; |
| el17m2h | 15:4efa04a6a376 | 31 | } |
| el17m2h | 9:5e53bca2a4c2 | 32 | } |
| el17m2h | 9:5e53bca2a4c2 | 33 | |
| el17m2h | 14:529f798adae4 | 34 | Vector2D Floors::get_position(){ |
| el17m2h | 14:529f798adae4 | 35 | Vector2D p = {_position.x,_position.y}; |
| el17m2h | 9:5e53bca2a4c2 | 36 | return p; |
| el17m2h | 5:8814d6de77d0 | 37 | } |
| el17m2h | 5:8814d6de77d0 | 38 | |
| el17m2h | 14:529f798adae4 | 39 | void Floors::set_position(Vector2D pos){ |
| el17m2h | 14:529f798adae4 | 40 | _position.x = pos.x; |
| el17m2h | 14:529f798adae4 | 41 | _position.y = pos.y; |
| el17m2h | 1:0001cb3eb053 | 42 | } |