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 Class Reference
#include <Banana.h>
| Public Member Functions | |
| Banana () | |
| Banana Constructor. | |
| ~Banana () | |
| Banana Destructor. | |
| void | banana_drop (Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt) | 
| Spawns the banana. | |
| void | banana_hit (Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt) | 
| Plays music on hit. | |
Detailed Description
Banana Class.
This class is for spawning the banana, it will float down the screen. Collision with the player will add points.
- Version:
- 1.0
- Date:
- May 2019
Definition at line 27 of file Banana.h.
Constructor & Destructor Documentation
| Banana | ( | ) | 
Banana Constructor.
Builds my default Banana contructor.
This does not have any setup.
Definition at line 10 of file Banana.cpp.
| ~Banana | ( | ) | 
Banana Destructor.
Builds my default Banana destructor.
This does not have any setup.
Definition at line 16 of file Banana.cpp.
Member Function Documentation
Spawns the banana.
- Parameters:
- 
  pad The Gamepad class is used. lcd The N5110 class is used. barrel The Barrel class is used. dky The Donkey class is used. opt The Options class is used. 
- Returns:
- None.
Spawns a banana at a random x location, then slowly falls down screen. When reaches bottom or collected by player it restarts.
void Banana::banana_drop(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt) { if (((banana_x + 8) >= barrel_x) & (banana_x <= (barrel_x + 16)) & (banana_y <= 4)) { // Makes sure not in same position as barrel sprite. banana_x = rand() % (banana_max + 1 - banana_min) + banana_min; // Random x spawn coordinate. } lcd.drawSprite(banana_x,banana_y,8,8,(int *)game_banana); // Draws the banana sprite on screen with the correct coordinates. char buffer[14]; // Shows score on screen. sprintf(buffer,"%i",score); lcd.printString(buffer,60,0); lcd.refresh(); wait_ms(50); banana_y = banana_y + 1 + banana_time; // Moves banana slowly down screen. if (banana_y > 44) { // If banana reaches the bottom of screen, then resets. banana_y = 0; banana_time = banana_time + 0.1; banana_x = rand() % (banana_max + 1 - banana_min) + banana_min; } 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. score = score + 10 + banana_time; banana_hit(pad, lcd, barrel, dky, opt); banana_y = 0; banana_x = rand() % (banana_max + 1 - banana_min) + banana_min; //printf("Banana Hit - Score: %d \n", score); // Prints running score to external computer screen. //printf("Banana x %d \n", banana_x); //printf("Barrel x %d \n", barrel_x); } }
Definition at line 42 of file Banana.cpp.
Plays music on hit.
- Parameters:
- 
  pad The Gamepad class is used. lcd The N5110 class is used. barrel The Barrel class is used. dky The Donkey class is used. opt The Options class is used. 
- Returns:
- None.
Plays a tone when banana is collected.
void Banana::banana_hit(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky, Options &opt) { if (opt_volume == 1) { pad.tone(2400, 0.2); } }
Definition at line 69 of file Banana.cpp.
Generated on Tue Jul 12 2022 18:21:51 by
 1.7.2
 1.7.2