Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Barrel.h Source File

Barrel.h

00001 #ifndef BARREL_H
00002 #define BARREL_H
00003 
00004 #include "mbed.h"
00005 #include "N5110.h"
00006 #include "Barrel.h"
00007 #include "Donkey.h"
00008 
00009 /** External variables used inside and out of the class. */
00010 extern int barrel_x;
00011 extern int barrel_y;
00012 extern int barrel_speed;
00013 extern int barrel_min;
00014 extern int barrel_max;
00015 extern float barrel_time;
00016 extern int running;
00017 
00018 /** Barrel Class
00019 *@brief This class is for spawning the barrel, it will float down the screen. Collision with the player will cause gameover.
00020 *@author Kern Fowler
00021 *@version 1.0
00022 *@date May 2019
00023 */
00024     
00025 class Barrel { 
00026 
00027 public:
00028 /** Barrel Constructor 
00029 @brief Builds my default Barrel contructor.
00030 @details This does not have any setup. 
00031 */
00032 Barrel();
00033 /** Barrel Destructor 
00034 @brief Builds my default Barrel dentructor.
00035 @details This does not have any setup. 
00036 */
00037 ~Barrel();
00038 // Mutators
00039 
00040 /** 
00041 *@brief Spawns the barrel
00042 *@param pad The Gamepad class is used.
00043 *@param lcd The N5110 class is used.
00044 *@param dky The Donkey class is used.
00045 *@return None.
00046 *@details 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.
00047 *@code
00048 void Barrel::barrel_drop(Gamepad &pad, N5110 &lcd, Donkey &dky) {
00049     lcd.drawSprite(barrel_x,barrel_y,4,8,(int *)game_barrel); // Draws the barrel sprite on screen with correct coordinates.
00050     lcd.refresh();
00051     wait_ms(50);
00052     barrel_y = barrel_y + 1 + barrel_time;
00053     if (barrel_y > 44) { // If barrel reaches bottom of the screen, the resets.
00054         barrel_y = 0;
00055         barrel_x = rand() % (barrel_max + 1 - barrel_min) + barrel_min;
00056         barrel_time = barrel_time + 0.1; // Moves barrel slowly down screen.
00057     }
00058     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.
00059         running = 0;
00060         //printf("Barrel Hit")
00061     }
00062 }
00063 @endcode
00064 */
00065 void barrel_drop(Gamepad &pad, N5110 &lcd, Donkey &dky);
00066 };
00067 
00068 #endif