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.
Donkey.cpp
00001 /* 00002 ELEC2645 Project 00003 Donkey.cpp 00004 Class file for Donkey Kong in Donkey Kong game. 00005 */ 00006 00007 #include "Donkey.h" 00008 00009 // Constructor - Doesn't require any setup. 00010 Donkey::Donkey() 00011 { 00012 00013 } 00014 00015 // Deconstructor - Doesn't require any setup. 00016 Donkey::~Donkey() 00017 { 00018 00019 } 00020 00021 // External variables to be used inside and out of the class. 00022 int donkeykong_x = 0; // Donkey Kong's coordinates. 00023 int donkeykong_y = 34; 00024 int donkey_kong_speed = 10; // Donkey Kong's dropspeed. 00025 int donkey_direction; // Joystick input. 00026 00027 int game_dk_walking_right_1[14][16] = { // Donkey Kong moving right sprite 00028 {0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,}, 00029 {0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,}, 00030 {0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,}, 00031 {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,}, 00032 {0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,1,}, 00033 {0,0,0,0,1,1,0,0,0,1,0,0,1,0,1,0,}, 00034 {0,0,1,1,1,0,0,0,0,0,1,1,1,1,0,0,}, 00035 {0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,}, 00036 {0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,}, 00037 {1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,1,}, 00038 {1,0,0,1,0,0,0,1,1,1,0,0,1,0,0,1,}, 00039 {1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,}, 00040 {1,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,}, 00041 {1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,}, 00042 }; 00043 00044 int game_dk_walking_left_1[14][16] = { // Donkey Kong moving left sprite 00045 {0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,}, 00046 {0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,}, 00047 {0,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,}, 00048 {1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,}, 00049 {1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,}, 00050 {0,1,0,1,0,0,1,0,0,0,1,1,0,0,0,0,}, 00051 {0,0,1,1,1,1,0,0,0,0,0,1,1,1,0,0,}, 00052 {0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,}, 00053 {0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,}, 00054 {1,0,0,0,1,1,1,0,0,1,1,1,0,0,0,1,}, 00055 {1,0,0,1,0,0,1,1,1,0,0,0,1,0,0,1,}, 00056 {1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1,}, 00057 {1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,1,}, 00058 {1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,}, 00059 }; 00060 00061 int game_dk_stationary[14][16] = { // Donkey Kong stationary sprite 00062 {0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,}, 00063 {0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,}, 00064 {0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,}, 00065 {0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,}, 00066 {0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,0,}, 00067 {0,0,1,1,0,1,1,0,1,1,0,0,1,0,0,0,}, 00068 {0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,}, 00069 {0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,0,}, 00070 {0,1,0,0,0,1,1,1,1,1,0,0,0,0,1,0,}, 00071 {0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,}, 00072 {1,0,0,1,0,1,0,0,0,0,1,0,1,0,0,1,}, 00073 {1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,}, 00074 {1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,}, 00075 {0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,}, 00076 }; 00077 00078 // 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. 00079 void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) { 00080 donkey_direction = pad.get_direction(); 00081 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. 00082 donkeykong_x = donkeykong_x + 3; 00083 lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_right_1); 00084 } 00085 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. 00086 donkeykong_x = donkeykong_x - 3; 00087 lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_walking_left_1); 00088 } 00089 else { // If joystick not moved, then stationary sprite will be loaded and no movement occurs. 00090 lcd.drawSprite(donkeykong_x,donkeykong_y,14,16,(int *)game_dk_stationary); 00091 } 00092 lcd.refresh(); 00093 if (donkeykong_x > 68) { // Stops donkey kong model going off screen. 00094 donkeykong_x = 68; 00095 } 00096 if (donkeykong_x < 0) { 00097 donkeykong_x = 0; 00098 } 00099 }
Generated on Tue Jul 12 2022 18:21:51 by
1.7.2