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.
Banana.h
00001 #ifndef BANANA_H 00002 #define BANANA_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 #include "Barrel.h" 00008 #include "Donkey.h" 00009 #include "Options.h" 00010 00011 /** External variables used inside and out of the class. */ 00012 extern int banana_x; 00013 extern int banana_y; 00014 extern int banana_speed; 00015 extern int banana_min; 00016 extern int banana_max; 00017 extern int banana_time; 00018 extern int score; 00019 00020 /** Banana Class 00021 *@brief This class is for spawning the banana, it will float down the screen. Collision with the player will add points. 00022 *@author Kern Fowler 00023 *@version 1.0 00024 *@date May 2019 00025 */ 00026 00027 class Banana { 00028 00029 public: 00030 /** Banana Constructor 00031 @brief Builds my default Banana contructor. 00032 @details This does not have any setup. 00033 */ 00034 Banana(); 00035 /** Banana Destructor 00036 @brief Builds my default Banana destructor. 00037 @details This does not have any setup. 00038 */ 00039 ~Banana(); 00040 // Mutators 00041 00042 /** 00043 *@brief Spawns the banana 00044 *@param pad The Gamepad class is used. 00045 *@param lcd The N5110 class is used. 00046 *@param barrel The Barrel class is used. 00047 *@param dky The Donkey class is used. 00048 *@param opt The Options class is used. 00049 *@return None. 00050 *@details Spawns a banana at a random x location, then slowly falls down screen. When reaches bottom or collected by player it restarts. 00051 *@code 00052 void Banana::banana_drop(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt) { 00053 if (((banana_x + 8) >= barrel_x) & (banana_x <= (barrel_x + 16)) & (banana_y <= 4)) { // Makes sure not in same position as barrel sprite. 00054 banana_x = rand() % (banana_max + 1 - banana_min) + banana_min; // Random x spawn coordinate. 00055 } 00056 lcd.drawSprite(banana_x,banana_y,8,8,(int *)game_banana); // Draws the banana sprite on screen with the correct coordinates. 00057 char buffer[14]; // Shows score on screen. 00058 sprintf(buffer,"%i",score); 00059 lcd.printString(buffer,60,0); 00060 lcd.refresh(); 00061 wait_ms(50); 00062 banana_y = banana_y + 1 + banana_time; // Moves banana slowly down screen. 00063 if (banana_y > 44) { // If banana reaches the bottom of screen, then resets. 00064 banana_y = 0; 00065 banana_time = banana_time + 0.1; 00066 banana_x = rand() % (banana_max + 1 - banana_min) + banana_min; 00067 } 00068 if ((banana_y >= 34) & ((banana_x + 7) >= donkeykong_x) & (banana_x <= (donkeykong_x + 15))) { // If banana collides with player sprite, then adds to score and resets. 00069 score = score + 10 + banana_time; 00070 banana_hit(pad, lcd, barrel, dky, opt); 00071 banana_y = 0; 00072 banana_x = rand() % (banana_max + 1 - banana_min) + banana_min; 00073 //printf("Banana Hit - Score: %d \n", score); // Prints running score to external computer screen. 00074 //printf("Banana x %d \n", banana_x); 00075 //printf("Barrel x %d \n", barrel_x); 00076 } 00077 } 00078 @endcode 00079 */ 00080 void banana_drop(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt); 00081 /** 00082 *@brief Plays music on hit 00083 *@param pad The Gamepad class is used. 00084 *@param lcd The N5110 class is used. 00085 *@param barrel The Barrel class is used. 00086 *@param dky The Donkey class is used. 00087 *@param opt The Options class is used. 00088 *@return None. 00089 *@details Plays a tone when banana is collected. 00090 *@code 00091 void Banana::banana_hit(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt) { 00092 if (opt_volume == 1) { 00093 pad.tone(2400, 0.2); 00094 } 00095 } 00096 @endcode 00097 */ 00098 void banana_hit(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt); 00099 }; 00100 00101 #endif
Generated on Tue Jul 12 2022 18:21:51 by
1.7.2