Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

lib/Banana/Banana.cpp

Committer:
Kern_EL17KJTF
Date:
2019-05-07
Revision:
11:b288d01533cc
Parent:
10:28575a6eaa13
Child:
12:50a7abf21f18

File content as of revision 11:b288d01533cc:

/*
ELEC2645 Project
Banana.cpp
Class file for Banana in Donkey Kong game.
*/

#include "Banana.h"

Banana::Banana()
{

}

Banana::~Banana()
{

}

int banana_x = 30;
int banana_y = 0;
int banana_speed = 0;
int banana_min = 0;
int banana_max = 76;
int banana_time = 0;
int score = 0;


void Banana::banana_drop(Gamepad &pad, N5110 &lcd, Barrel &barrel, Donkey &dky) {
    int game_banana[8][8] = {
    {0,0,0,0,0,0,1,0,},
    {0,0,0,0,0,1,1,1,},
    {0,0,0,0,0,1,1,1,},
    {0,0,0,0,1,1,1,1,},
    {0,0,0,1,1,1,1,0,},
    {0,1,1,1,1,1,1,0,},
    {1,1,1,1,1,1,0,0,},
    {0,1,1,1,0,0,0,0,},
};
    while (((banana_x + 8) >= barrel_x) & (banana_x <= (barrel_x + 8))) {
        banana_x = rand() % (banana_max + 1 - banana_min) + banana_min;
    }
    lcd.drawSprite(banana_x,banana_y,8,8,(int *)game_banana);
    lcd.refresh();
    wait_ms(50);
    banana_y = banana_y + 1 + banana_time;
    if (banana_y > 40) {
        banana_y = 0;
        banana_time = banana_time + 0.1;
    }
    if ((banana_y >= 34) & ((banana_x + 7) >= donkeykong_x) & (banana_x <= (donkeykong_x + 15))) {
        score = score + 10 + banana_time;
    }
}