Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Banana Class Reference

Banana Class Reference

Banana Class. More...

#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.

Author:
Kern Fowler
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

void banana_drop ( Gamepad pad,
N5110 lcd,
Barrel barrel,
Donkey &  dky,
Options opt 
)

Spawns the banana.

Parameters:
padThe Gamepad class is used.
lcdThe N5110 class is used.
barrelThe Barrel class is used.
dkyThe Donkey class is used.
optThe 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.

void banana_hit ( Gamepad pad,
N5110 lcd,
Barrel barrel,
Donkey &  dky,
Options opt 
)

Plays music on hit.

Parameters:
padThe Gamepad class is used.
lcdThe N5110 class is used.
barrelThe Barrel class is used.
dkyThe Donkey class is used.
optThe 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.