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.
Diff: lib/Donkey/Donkey.cpp
- Revision:
- 20:c4e6941c98e2
- Parent:
- 15:9e8d1b6fe81e
--- a/lib/Donkey/Donkey.cpp Wed May 08 23:14:49 2019 +0000
+++ b/lib/Donkey/Donkey.cpp Wed May 08 23:46:49 2019 +0000
@@ -3,27 +3,28 @@
Donkey.cpp
Class file for Donkey Kong in Donkey Kong game.
*/
+
#include "Donkey.h"
-
-
+// Constructor - Doesn't require any setup.
Donkey::Donkey()
{
}
+
+// Deconstructor - Doesn't require any setup.
Donkey::~Donkey()
{
}
- int donkeykong_x = 0;
- int donkeykong_y = 34;
- int donkey_kong_speed = 10;
- int donkey_direction;
+// External variables to be used inside and out of the class.
+int donkeykong_x = 0; // Donkey Kong's coordinates.
+int donkeykong_y = 34;
+int donkey_kong_speed = 10; // Donkey Kong's dropspeed.
+int donkey_direction; // Joystick input.
-
-void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) {
-int game_dk_walking_right_1[14][16] = {
+int game_dk_walking_right_1[14][16] = { // Donkey Kong moving right sprite
{0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,},
{0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,},
{0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,},
@@ -40,7 +41,7 @@
{1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,},
};
-int game_dk_walking_left_1[14][16] = {
+int game_dk_walking_left_1[14][16] = { // Donkey Kong moving left sprite
{0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,},
{0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,},
{0,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,},
@@ -57,7 +58,7 @@
{1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,},
};
-int game_dk_stationary[14][16] = {
+int game_dk_stationary[14][16] = { // Donkey Kong stationary sprite
{0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,},
{0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,},
{0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,},
@@ -73,24 +74,26 @@
{1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,},
{0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,},
};
+
+// 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.
+void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) {
donkey_direction = pad.get_direction();
- if (donkey_direction == NE || donkey_direction == E || donkey_direction == SE) {
+ 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.
donkeykong_x = donkeykong_x + 3;
lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_right_1);
}
- else if (donkey_direction == NW || donkey_direction == W || donkey_direction == SW) {
+ 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.
donkeykong_x = donkeykong_x - 3;
lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_left_1);
}
- else {
- lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_stationary);
+ else { // If joystick not moved, then stationary sprite will be loaded and no movement occurs.
+ lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_stationary);
}
lcd.refresh();
- if (donkeykong_x > 68) {
+ if (donkeykong_x > 68) { // Stops donkey kong model going off screen.
donkeykong_x = 68;
}
if (donkeykong_x < 0) {
donkeykong_x = 0;
}
-}
-
+}
\ No newline at end of file