Hugo Hu / Mbed 2 deprecated BRAVEHEART

Dependencies:   mbed N5110 ShiftReg PinDetect

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Global.h Source File

Global.h

Go to the documentation of this file.
00001 #ifndef GLOBAL_H
00002 #define GLOBAL_H
00003 
00004 #include "mbed.h"
00005 #include <string>
00006 #include <vector>
00007 
00008 /// @file Global.h
00009 /// @brief Contains global variables and functions
00010 
00011 namespace Record
00012 {
00013     /// A highscore element consists of initials and a score.
00014     struct Highscore
00015     {
00016         std::string initials;
00017         int score;
00018     };
00019     
00020     /// An achievement element consists of all records made.
00021     struct Achievement
00022     {
00023         int totalGamePlayed;
00024         int totalSucceedTimes;
00025         int totalDeathTimes;
00026         int totalWalkLength;
00027         int totalChestUnlocked;
00028         int totalCoinSpent;
00029         int totalEnemyDiscovered;
00030         int totalWeaponDiscovered;
00031         int totalCharacterDiscovred;
00032         int totalEnemyDestroyed;
00033         int totalBulletShot;
00034         int totalBulletAccuracy;
00035     };
00036 }
00037 
00038 /// Simple objects with a position (x,y) and velocity (vx, vy)
00039 struct Point
00040 {
00041     int x;
00042     int y;
00043     int vx, vy;
00044 };
00045 
00046 /// Rectangle with position (x and y) and dimensions (width and height)
00047 struct Rectangle
00048 {
00049     Rectangle(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) {}
00050     int x;
00051     int y;
00052     int width;
00053     int height;
00054 };
00055 
00056 namespace Global
00057 {
00058     /// Score in last game
00059     extern int score;
00060     
00061     /// List showing the three all time highest score achieved. Sorted from highest to lowest.
00062     extern Highscore highscores[3];     
00063     
00064     /// Clears the highscore list
00065     void clearHighscoreList();
00066 }
00067 
00068 /** An entity represents a movable character, such as the player, enemies etc.
00069 *   Note that the entity class does not contain the sprite (image) of the entity.
00070 *   Different sprites are given as 2D const int arrays in 
00071 *   OBS! The entity's dimensions should be the same as the width and height or else this will lead to undefined behaviour!
00072 */
00073 class Entity
00074 {
00075     public:
00076         Entity() {x = y = width = height = vx = vy = 0; facingLeft = true; dead = false;}
00077         Entity(int x, int y, int w = 0, int h = 0) : x(x), y(y), width(w), height(h) {vx = vy = 0; facingLeft = true; dead = false;}
00078         
00079         /// Position of entity (origin: left upper corner)
00080         int x, y;
00081         
00082         /// Velocity of entity
00083         int vx, vy;
00084         
00085         /// Width of entity
00086         int width; 
00087         
00088         /// Height of entity     
00089         int height;
00090         
00091         /// True if the entity is facing left
00092         bool facingLeft; 
00093         
00094         /// True if enemy is dead.
00095         bool dead;
00096         
00097         /// Returns x-position of the right edge
00098         int getRight() {return x + width - 1;}
00099         
00100         /// Returns y-position of the bottom edge   
00101         int getBottom() {return y + height - 1;}
00102 };
00103 
00104 /// Enemy class
00105 class Enemy : public Entity
00106 {
00107     public:
00108         /// Different type of enemies
00109         enum Type{SIMPLE, JUMPER, RUNNER};
00110     
00111     public:
00112         Enemy(int x, int y, bool facingLeft, Type type = SIMPLE) : Entity(x,y), type(type) {setup();}
00113         
00114         /// What type of enemy it is.
00115         Type type;      
00116         
00117         /// Multiplier used for giving more points
00118         int difficulty; 
00119         
00120         /// Probability (in percent) of trying to jump if at ground.
00121         int jumpRate;
00122         
00123         private:
00124             void setup();
00125 };
00126 
00127 namespace Map
00128 {
00129     enum MapType {Normal, Store, Chest, BIG, BOSS};
00130     struct MapProperty
00131     {
00132         int mapSize[2];
00133         int respawnPosition[2];
00134         int succeedPosition[2];
00135         int enermyPosition[3][2];
00136         MapType mapType;
00137         int chestPosition[2];
00138         int storePosition[6];
00139         int goldCoinNum;
00140         int goldCoinPosition[10];
00141         int spawnRate;
00142         int maxEnermy;
00143     };
00144 }
00145 
00146 namespace GameX
00147 {
00148     struct GameProperty
00149     {
00150         Entity player;  // Player object
00151         std::vector<Point*> bullets;    // Container for bullets
00152         std::vector<Enemy*> enemies;    // Container for enemies
00153         int livesLeft;  // The number of lives left
00154         bool paused;    // True if the game is paused
00155         int currentLayer; // To determine which layer the player is.
00156     };
00157 }
00158 
00159 #endif