Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Committer:
Kern_EL17KJTF
Date:
Thu May 09 10:46:03 2019 +0000
Revision:
33:3894a7f846a0
Parent:
20:c4e6941c98e2
Child:
35:68c3c06d67a8
Mbed update at revision 20 caused an issue when running on board. Downgraded the mbed and now works.

Who changed what in which revision?

UserRevisionLine numberNew 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 33:3894a7f846a0 41 *@code
Kern_EL17KJTF 33:3894a7f846a0 42 void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) {
Kern_EL17KJTF 33:3894a7f846a0 43 donkey_direction = pad.get_direction();
Kern_EL17KJTF 33:3894a7f846a0 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 33:3894a7f846a0 45 donkeykong_x = donkeykong_x + 3;
Kern_EL17KJTF 33:3894a7f846a0 46 lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_right_1);
Kern_EL17KJTF 33:3894a7f846a0 47 }
Kern_EL17KJTF 33:3894a7f846a0 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 33:3894a7f846a0 49 donkeykong_x = donkeykong_x - 3;
Kern_EL17KJTF 33:3894a7f846a0 50 lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_left_1);
Kern_EL17KJTF 33:3894a7f846a0 51 }
Kern_EL17KJTF 33:3894a7f846a0 52 else { // If joystick not moved, then stationary sprite will be loaded and no movement occurs.
Kern_EL17KJTF 33:3894a7f846a0 53 lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_stationary);
Kern_EL17KJTF 33:3894a7f846a0 54 }
Kern_EL17KJTF 33:3894a7f846a0 55 lcd.refresh();
Kern_EL17KJTF 33:3894a7f846a0 56 if (donkeykong_x > 68) { // Stops donkey kong model going off screen.
Kern_EL17KJTF 33:3894a7f846a0 57 donkeykong_x = 68;
Kern_EL17KJTF 33:3894a7f846a0 58 }
Kern_EL17KJTF 33:3894a7f846a0 59 if (donkeykong_x < 0) {
Kern_EL17KJTF 33:3894a7f846a0 60 donkeykong_x = 0;
Kern_EL17KJTF 33:3894a7f846a0 61 }
Kern_EL17KJTF 33:3894a7f846a0 62 }
Kern_EL17KJTF 33:3894a7f846a0 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