Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Barrel Class Reference

Barrel Class Reference

Barrel Class. More...

#include <Barrel.h>

Public Member Functions

 Barrel ()
 Barrel Constructor.
 ~Barrel ()
 Barrel Destructor.
void barrel_drop (Gamepad &pad, N5110 &lcd, Donkey &dky)
 Spawns the barrel.

Detailed Description

Barrel Class.

This class is for spawning the barrel, it will float down the screen. Collision with the player will cause gameover.

Author:
Kern Fowler
Version:
1.0
Date:
May 2019

Definition at line 25 of file Barrel.h.


Constructor & Destructor Documentation

Barrel (  )

Barrel Constructor.

Builds my default Barrel contructor.

This does not have any setup.

Definition at line 10 of file Barrel.cpp.

~Barrel (  )

Barrel Destructor.

Builds my default Barrel dentructor.

This does not have any setup.

Definition at line 16 of file Barrel.cpp.


Member Function Documentation

void barrel_drop ( Gamepad pad,
N5110 lcd,
Donkey &  dky 
)

Spawns the barrel.

Parameters:
padThe Gamepad class is used.
lcdThe N5110 class is used.
dkyThe Donkey class is used.
Returns:
None.

Spawns a barrel at a random x location, then slowly falls down screen. When reaches bottom it restarts. If collision with player leads to gameover.

void Barrel::barrel_drop(Gamepad &pad, N5110 &lcd, Donkey &dky) {
    lcd.drawSprite(barrel_x,barrel_y,4,8,(int *)game_barrel); // Draws the barrel sprite on screen with correct coordinates.
    lcd.refresh();
    wait_ms(50);
    barrel_y = barrel_y + 1 + barrel_time;
    if (barrel_y > 44) { // If barrel reaches bottom of the screen, the resets.
        barrel_y = 0;
        barrel_x = rand() % (barrel_max + 1 - barrel_min) + barrel_min;
        barrel_time = barrel_time + 0.1; // Moves barrel slowly down screen.
    }
    if ((barrel_y >= 34) & ((barrel_x + 7) >= donkeykong_x) & (barrel_x <= (donkeykong_x + 15))) { // If barrel collides with player then sets running to 0, causing gameover.
        running = 0;
        //printf("Barrel Hit")
    }
}

Definition at line 38 of file Barrel.cpp.