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.
lib/Barrel/Barrel.h@25:0ba3524ee0b7, 2019-05-09 (annotated)
- Committer:
- Kern_EL17KJTF
- Date:
- Thu May 09 00:36:51 2019 +0000
- Revision:
- 25:0ba3524ee0b7
- Parent:
- 19:8400ecdb69e9
- Child:
- 39:1d0584a152a6
Documentation - Barrel - Code Example Added.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kern_EL17KJTF | 10:28575a6eaa13 | 1 | #ifndef BARREL_H |
Kern_EL17KJTF | 10:28575a6eaa13 | 2 | #define BARREL_H |
Kern_EL17KJTF | 10:28575a6eaa13 | 3 | |
Kern_EL17KJTF | 10:28575a6eaa13 | 4 | #include "mbed.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 5 | #include "N5110.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 6 | #include "Barrel.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 7 | #include "Donkey.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 8 | |
Kern_EL17KJTF | 18:80c47cfe9802 | 9 | /** External variables used inside and out of the class. */ |
Kern_EL17KJTF | 18:80c47cfe9802 | 10 | extern int barrel_x; |
Kern_EL17KJTF | 18:80c47cfe9802 | 11 | extern int barrel_y; |
Kern_EL17KJTF | 18:80c47cfe9802 | 12 | extern int barrel_speed; |
Kern_EL17KJTF | 18:80c47cfe9802 | 13 | extern int barrel_min; |
Kern_EL17KJTF | 18:80c47cfe9802 | 14 | extern int barrel_max; |
Kern_EL17KJTF | 18:80c47cfe9802 | 15 | extern float barrel_time; |
Kern_EL17KJTF | 18:80c47cfe9802 | 16 | extern int running; |
Kern_EL17KJTF | 18:80c47cfe9802 | 17 | |
Kern_EL17KJTF | 18:80c47cfe9802 | 18 | /** Barrel Class |
Kern_EL17KJTF | 18:80c47cfe9802 | 19 | *@brief This class is for spawning the barrel, it will float down the screen. Collision with the player will cause gameover. |
Kern_EL17KJTF | 18:80c47cfe9802 | 20 | *@author Kern Fowler |
Kern_EL17KJTF | 18:80c47cfe9802 | 21 | *@version 1.0 |
Kern_EL17KJTF | 18:80c47cfe9802 | 22 | *@date May 2019 |
Kern_EL17KJTF | 18:80c47cfe9802 | 23 | */ |
Kern_EL17KJTF | 11:b288d01533cc | 24 | |
Kern_EL17KJTF | 18:80c47cfe9802 | 25 | class Barrel { |
Kern_EL17KJTF | 10:28575a6eaa13 | 26 | |
Kern_EL17KJTF | 18:80c47cfe9802 | 27 | public: |
Kern_EL17KJTF | 18:80c47cfe9802 | 28 | /** Barrel Constructor |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 29 | @brief Builds my default Barrel contructor. |
Kern_EL17KJTF | 18:80c47cfe9802 | 30 | @details This does not have any setup. |
Kern_EL17KJTF | 18:80c47cfe9802 | 31 | */ |
Kern_EL17KJTF | 18:80c47cfe9802 | 32 | Barrel(); |
Kern_EL17KJTF | 18:80c47cfe9802 | 33 | /** Barrel Destructor |
Kern_EL17KJTF | 18:80c47cfe9802 | 34 | @brief Builds my default Barrel dentructor. |
Kern_EL17KJTF | 18:80c47cfe9802 | 35 | @details This does not have any setup. |
Kern_EL17KJTF | 18:80c47cfe9802 | 36 | */ |
Kern_EL17KJTF | 18:80c47cfe9802 | 37 | ~Barrel(); |
Kern_EL17KJTF | 18:80c47cfe9802 | 38 | // Mutators |
Kern_EL17KJTF | 10:28575a6eaa13 | 39 | |
Kern_EL17KJTF | 18:80c47cfe9802 | 40 | /** |
Kern_EL17KJTF | 18:80c47cfe9802 | 41 | *@brief Spawns the barrel |
Kern_EL17KJTF | 18:80c47cfe9802 | 42 | *@param pad The Gamepad class is used. |
Kern_EL17KJTF | 18:80c47cfe9802 | 43 | *@param lcd The N5110 class is used. |
Kern_EL17KJTF | 18:80c47cfe9802 | 44 | *@param dky The Donkey class is used. |
Kern_EL17KJTF | 18:80c47cfe9802 | 45 | *@details Spawns a barrel at a random x location, then slowly falls down screen. When reaches bottom it restarts. If collision with player leads to gameover. |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 46 | *@code |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 47 | void Barrel::barrel_drop(Gamepad &pad, N5110 &lcd, Donkey &dky) { |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 48 | lcd.drawSprite(barrel_x,barrel_y,4,8,(int *)game_barrel); // Draws the barrel sprite on screen with correct coordinates. |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 49 | lcd.refresh(); |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 50 | wait_ms(50); |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 51 | barrel_y = barrel_y + 1 + barrel_time; |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 52 | if (barrel_y > 44) { // If barrel reaches bottom of the screen, the resets. |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 53 | barrel_y = 0; |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 54 | barrel_x = rand() % (barrel_max + 1 - barrel_min) + barrel_min; |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 55 | barrel_time = barrel_time + 0.1; // Moves barrel slowly down screen. |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 56 | } |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 57 | if ((barrel_y >= 34) & ((barrel_x + 7) >= donkeykong_x) & (barrel_x <= (donkeykong_x + 15))) { // If barrel collides with player then sets running to 0, causing gameover. |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 58 | running = 0; |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 59 | //printf("Barrel Hit") |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 60 | } |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 61 | } |
Kern_EL17KJTF | 25:0ba3524ee0b7 | 62 | @endcode |
Kern_EL17KJTF | 18:80c47cfe9802 | 63 | */ |
Kern_EL17KJTF | 18:80c47cfe9802 | 64 | void barrel_drop(Gamepad &pad, N5110 &lcd, Donkey &dky); |
Kern_EL17KJTF | 10:28575a6eaa13 | 65 | }; |
Kern_EL17KJTF | 10:28575a6eaa13 | 66 | |
Kern_EL17KJTF | 10:28575a6eaa13 | 67 | #endif |