Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Map/Map.h
- Revision:
- 9:f720f5d87420
- Parent:
- 8:9b77eea95088
- Child:
- 10:da5743dfb137
diff -r 9b77eea95088 -r f720f5d87420 Map/Map.h
--- a/Map/Map.h Wed May 08 13:49:01 2019 +0000
+++ b/Map/Map.h Wed May 08 23:09:43 2019 +0000
@@ -9,12 +9,6 @@
#include <vector>
-/** Map Class
-@author Kostadin Chakarov, University of Leeds
-@brief Creates the map and controls collision between objects in the Breakout game
-@date April 2019
-*/
-
/** Struct containing all parameters for the bricks */
struct Brick {
int x, y, w, h; /**x and y coords, width, height*/
@@ -57,6 +51,14 @@
virtual void initBricks(Map &map);
};
+/** Inherits from level and doesn't have any additional functions */
+class Level3 : public Level
+{
+public:
+ /** Draws the bricks and stores them in the levels vector */
+ virtual void initBricks(Map &map);
+};
+
/*
Power ups Coding strategy:
@@ -76,36 +78,45 @@
struct PowerUpType {
- int type;
- int* sprite;
+ int type; /** Stores the type of the powerup */
+ int* sprite; /** Stores the sprite of the powerup */
+ /** Constructor */
PowerUpType(int type, int* sprite) : type(type), sprite(sprite) {}
+ /** Gives the powerup effect to the player */
virtual void giveBonus(Paddle &paddle, Ball &ball) {}
+ /** Draws the powerup on the LCD */
virtual void draw(N5110 &lcd, PowerUp &pUp);
};
+/** Inherits from the powerUpType struct and only changes the giveBonus function */
struct PaddleSizePUpType : public PowerUpType {
+ /** Constructor */
PaddleSizePUpType(int type, int* sprite) : PowerUpType(type, sprite) {}
-
+ /** Gives the powerup effect to the player */
virtual void giveBonus(Paddle &paddle, Ball &ball);
};
+/** Inherits from the powerUpType struct and only changes the giveBonus function */
struct PaddleSpeedPUpType : public PowerUpType {
+ /** Constructor */
PaddleSpeedPUpType(int type, int* sprite) : PowerUpType(type, sprite) {}
-
+ /** Gives the powerup effect to the player */
virtual void giveBonus(Paddle &paddle, Ball &ball);
};
+/** Inherits from the powerUpType struct and only changes the giveBonus function */
struct BallSpeedPUpType : public PowerUpType {
+ /** Constructor */
BallSpeedPUpType(int type, int* sprite) : PowerUpType(type, sprite) {}
-
+ /** Gives the powerup effect to the player */
virtual void giveBonus(Paddle &paddle, Ball &ball);
};
#define PowerUpW 3
#define PowerUpH 4
-#define PowerUpDropChancePct 100
+#define PowerUpDropChancePct 10
/** PowerUp Class
@@ -124,17 +135,29 @@
public:
+ /** Constructor
+ * @param x the initial x-position of the PowerUp
+ * @param y the initial y-position of the PowerUp
+ * @param pUpType the type of the PowerUp
+ */
PowerUp(float x, float y, PowerUpType& pUpType);
+ /** Destructor - empty */
~PowerUp() {};
+ /** Determines the bonus depending on the type of the powerup */
void giveBonus(Paddle &paddle, Ball &ball) {
_pUpType->giveBonus(paddle, ball);
}
+ /** Draws the powerup */
virtual void draw(N5110 &lcd);
};
-
+/** Map Class
+@author Kostadin Chakarov, University of Leeds
+@brief Creates the map and controls collision between objects in the Breakout game
+@date April 2019
+*/
class Map
{
@@ -154,27 +177,30 @@
*/
int getCurrentLevel() { return currentLevel; }
/** Checks if all levels are defeated
- * @return true if current level = number of levels
+ * @return true if current level == number of levels
*/
bool hasWon() { return currentLevel >= levels.size(); }
- /** ???? */
+ /** Get the level object based on the current level number and call initBricks() on it */
void initBricks();
- /** Updates drawing of moving objects on map */
+ /** Updates the moving powerups on map */
void update();
- /** Creates powerUps depending on the percentage chance */
+ /** Creates powerUps depending on the PowerUpDropChancePct */
void onBrickHit(const Brick&);
- /** Initializes and draws all the bricks on the level, as well as powerUps */
+ /** Draws all the bricks on the level, as well as powerUps */
void drawMap(N5110 &lcd);
/** Checks if brick <-> ball collided */
void checkCollision(Ball &ball, Paddle &paddle);
/** Resolves the collision */
void resolveCollision(const Brick &brick, GameObject &obj);
- /** Checks if we cleared the level and if we won */
+ /** Checks if we cleared the level and if we won
+ * @return true if level is cleared
+ */
bool checkLevel();
- /** Resets the whole map when game is restarted */
+ /** Resets the whole map when game is (re-)started */
void reset();
- /** Adds the bricks to the vector */
+ /** Adds the brick to the vector */
void addBrick(Brick& brick) { bricks.push_back(brick); }
-
+ /** Stores the score of the game */
+ int score;
};
#endif
\ No newline at end of file