Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

lib/Donkey/Donkey.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
Donkey.cpp
Class file for Donkey Kong in Donkey Kong game.
*/
#include "Donkey.h"



Donkey::Donkey()
{

}
Donkey::~Donkey()
{

}

    int donkeykong_x = 0;
    int donkeykong_y = 32;
    int donkey_kong_speed = 10;
    int donkey_direction;


void Donkey::donkeykong_movement(Gamepad &pad, N5110 &lcd) {
int game_dk_walking_right_1[16][16] = {
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,},
    {1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,},
    {1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
};

int game_dk_walking_left_1[16][16] = {
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,},
    {1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,},
    {1,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
};

int game_dk_stationary[16][16] = {
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,},
};
    donkey_direction = pad.get_direction();
        if (donkey_direction == NE || donkey_direction == E || donkey_direction == SE) {
            donkeykong_x = donkeykong_x + 1;
            lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_right_1);
        } 
        else if (donkey_direction == NW || donkey_direction == W || donkey_direction == SW) {
            donkeykong_x = donkeykong_x - 1;
            lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_walking_left_1);
        } 
        else {
            lcd.drawSprite(donkeykong_x,donkeykong_y,16,16,(int *)game_dk_stationary);
        }
        wait_ms(donkey_kong_speed);
        lcd.refresh();
        if (donkeykong_x > 68) {
            donkeykong_x = 68;
        }
        if (donkeykong_x < 0) {
            donkeykong_x = 0;
        }
}