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/Donkey/Donkey.h@27:167c716e3e9f, 2019-05-09 (annotated)
- Committer:
- Kern_EL17KJTF
- Date:
- Thu May 09 00:43:40 2019 +0000
- Revision:
- 27:167c716e3e9f
- Parent:
- 20:c4e6941c98e2
- Child:
- 35:68c3c06d67a8
Documentation - Donkey Kong - Code Example Added.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kern_EL17KJTF | 10:28575a6eaa13 | 1 | #ifndef DONKEY_H |
Kern_EL17KJTF | 10:28575a6eaa13 | 2 | #define DONKEY_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 "Gamepad.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 7 | |
Kern_EL17KJTF | 20:c4e6941c98e2 | 8 | /** External variables used inside and out of the class. */ |
Kern_EL17KJTF | 20:c4e6941c98e2 | 9 | extern int donkeykong_x; |
Kern_EL17KJTF | 20:c4e6941c98e2 | 10 | extern int donkeykong_y; |
Kern_EL17KJTF | 20:c4e6941c98e2 | 11 | extern int donkey_kong_speed; |
Kern_EL17KJTF | 20:c4e6941c98e2 | 12 | extern int donkey_direction; |
Kern_EL17KJTF | 11:b288d01533cc | 13 | |
Kern_EL17KJTF | 20:c4e6941c98e2 | 14 | /** Donkey Kong Class |
Kern_EL17KJTF | 20:c4e6941c98e2 | 15 | *@brief This class is for spawning the player controlled model Donkey Kong. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 16 | *@author Kern Fowler |
Kern_EL17KJTF | 20:c4e6941c98e2 | 17 | *@version 1.0 |
Kern_EL17KJTF | 20:c4e6941c98e2 | 18 | *@date May 2019 |
Kern_EL17KJTF | 20:c4e6941c98e2 | 19 | */ |
Kern_EL17KJTF | 20:c4e6941c98e2 | 20 | |
Kern_EL17KJTF | 20:c4e6941c98e2 | 21 | class Donkey { |
Kern_EL17KJTF | 10:28575a6eaa13 | 22 | |
Kern_EL17KJTF | 20:c4e6941c98e2 | 23 | public: |
Kern_EL17KJTF | 20:c4e6941c98e2 | 24 | /** Donkey Kong Constructor |
Kern_EL17KJTF | 20:c4e6941c98e2 | 25 | @brief Builds my default Donkey Kong constructor. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 26 | @details This does not have any setup. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 27 | */ |
Kern_EL17KJTF | 20:c4e6941c98e2 | 28 | Donkey(); |
Kern_EL17KJTF | 20:c4e6941c98e2 | 29 | /** Donkey Kong Destructor |
Kern_EL17KJTF | 20:c4e6941c98e2 | 30 | @brief Builds my default Donkey Kong destructor. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 31 | @details This does not have any setup. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 32 | */ |
Kern_EL17KJTF | 20:c4e6941c98e2 | 33 | ~Donkey(); |
Kern_EL17KJTF | 20:c4e6941c98e2 | 34 | // Mutators |
Kern_EL17KJTF | 10:28575a6eaa13 | 35 | |
Kern_EL17KJTF | 20:c4e6941c98e2 | 36 | /** |
Kern_EL17KJTF | 20:c4e6941c98e2 | 37 | *@brief Spawns Donkey Kong model. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 38 | *@param pad The Gamepad class is used. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 39 | *@param lcd The N5110 class is used. |
Kern_EL17KJTF | 20:c4e6941c98e2 | 40 | *@details Creates the player controlled unit Donkey Kong, then moves it left or right based on joystick input. Points on collision with bananas. Gameover on collision with barrels. |
Kern_EL17KJTF | 27:167c716e3e9f | 41 | *@code |
Kern_EL17KJTF | 27:167c716e3e9f | 42 | void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) { |
Kern_EL17KJTF | 27:167c716e3e9f | 43 | donkey_direction = pad.get_direction(); |
Kern_EL17KJTF | 27:167c716e3e9f | 44 | if (donkey_direction == NE || donkey_direction == E || donkey_direction == SE) { // If joystick moved right, the right position sprite will be loaded and donkey kong will move right. |
Kern_EL17KJTF | 27:167c716e3e9f | 45 | donkeykong_x = donkeykong_x + 3; |
Kern_EL17KJTF | 27:167c716e3e9f | 46 | lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_right_1); |
Kern_EL17KJTF | 27:167c716e3e9f | 47 | } |
Kern_EL17KJTF | 27:167c716e3e9f | 48 | else if (donkey_direction == NW || donkey_direction == W || donkey_direction == SW) { // If joystick moved left, the left position sprite will be loaded and donkey kong will move left. |
Kern_EL17KJTF | 27:167c716e3e9f | 49 | donkeykong_x = donkeykong_x - 3; |
Kern_EL17KJTF | 27:167c716e3e9f | 50 | lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_left_1); |
Kern_EL17KJTF | 27:167c716e3e9f | 51 | } |
Kern_EL17KJTF | 27:167c716e3e9f | 52 | else { // If joystick not moved, then stationary sprite will be loaded and no movement occurs. |
Kern_EL17KJTF | 27:167c716e3e9f | 53 | lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_stationary); |
Kern_EL17KJTF | 27:167c716e3e9f | 54 | } |
Kern_EL17KJTF | 27:167c716e3e9f | 55 | lcd.refresh(); |
Kern_EL17KJTF | 27:167c716e3e9f | 56 | if (donkeykong_x > 68) { // Stops donkey kong model going off screen. |
Kern_EL17KJTF | 27:167c716e3e9f | 57 | donkeykong_x = 68; |
Kern_EL17KJTF | 27:167c716e3e9f | 58 | } |
Kern_EL17KJTF | 27:167c716e3e9f | 59 | if (donkeykong_x < 0) { |
Kern_EL17KJTF | 27:167c716e3e9f | 60 | donkeykong_x = 0; |
Kern_EL17KJTF | 27:167c716e3e9f | 61 | } |
Kern_EL17KJTF | 27:167c716e3e9f | 62 | } |
Kern_EL17KJTF | 27:167c716e3e9f | 63 | @endocde |
Kern_EL17KJTF | 20:c4e6941c98e2 | 64 | */ |
Kern_EL17KJTF | 20:c4e6941c98e2 | 65 | void donkeykong_movement(Gamepad &pad, N5110 &lcd); |
Kern_EL17KJTF | 10:28575a6eaa13 | 66 | }; |
Kern_EL17KJTF | 10:28575a6eaa13 | 67 | |
Kern_EL17KJTF | 10:28575a6eaa13 | 68 | #endif |