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.
Map/Map.h@7:cd3cafda3dd4, 2019-04-10 (annotated)
- Committer:
- kocemax
- Date:
- Wed Apr 10 09:18:25 2019 +0000
- Revision:
- 7:cd3cafda3dd4
- Parent:
- 6:39bda45efeed
- Child:
- 8:9b77eea95088
Made a working collision and added 2 levels, can add more later. Also started doing power-ups but haven't finished yet. Need to think of some of them and also thinking of adding some randomisation to the ball<->pad collision.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kocemax | 5:12c179da4788 | 1 | #ifndef MAP_H |
| kocemax | 5:12c179da4788 | 2 | #define MAP_H |
| kocemax | 5:12c179da4788 | 3 | |
| kocemax | 5:12c179da4788 | 4 | #include "mbed.h" |
| kocemax | 5:12c179da4788 | 5 | #include "N5110.h" |
| kocemax | 5:12c179da4788 | 6 | #include "Gamepad.h" |
| kocemax | 5:12c179da4788 | 7 | #include "PlayerControl.h" |
| kocemax | 5:12c179da4788 | 8 | #include "Ball.h" |
| kocemax | 7:cd3cafda3dd4 | 9 | //#include "PowerUp.h" |
| kocemax | 6:39bda45efeed | 10 | #include <vector> |
| kocemax | 5:12c179da4788 | 11 | |
| kocemax | 7:cd3cafda3dd4 | 12 | |
| kocemax | 5:12c179da4788 | 13 | /** Map Class |
| kocemax | 5:12c179da4788 | 14 | @author Kostadin Chakarov, University of Leeds |
| kocemax | 7:cd3cafda3dd4 | 15 | @brief Creates the map in the Breakout game |
| kocemax | 7:cd3cafda3dd4 | 16 | @date April 2019 |
| kocemax | 7:cd3cafda3dd4 | 17 | */ |
| kocemax | 7:cd3cafda3dd4 | 18 | //x and y coords, width, height |
| kocemax | 6:39bda45efeed | 19 | struct Brick { |
| kocemax | 6:39bda45efeed | 20 | int x, y, w, h; |
| kocemax | 5:12c179da4788 | 21 | }; |
| kocemax | 7:cd3cafda3dd4 | 22 | //need to write above to able to use in level |
| kocemax | 7:cd3cafda3dd4 | 23 | class Map; |
| kocemax | 7:cd3cafda3dd4 | 24 | |
| kocemax | 7:cd3cafda3dd4 | 25 | //this only contains the initBricks function as it stores the bricks in the level |
| kocemax | 7:cd3cafda3dd4 | 26 | class Level |
| kocemax | 7:cd3cafda3dd4 | 27 | { |
| kocemax | 7:cd3cafda3dd4 | 28 | public: |
| kocemax | 7:cd3cafda3dd4 | 29 | virtual void initBricks(Map &map) {} //virtual because will be different for each level |
| kocemax | 7:cd3cafda3dd4 | 30 | }; |
| kocemax | 7:cd3cafda3dd4 | 31 | |
| kocemax | 7:cd3cafda3dd4 | 32 | class Level1 : public Level |
| kocemax | 7:cd3cafda3dd4 | 33 | { |
| kocemax | 7:cd3cafda3dd4 | 34 | public: |
| kocemax | 7:cd3cafda3dd4 | 35 | virtual void initBricks(Map &map); |
| kocemax | 7:cd3cafda3dd4 | 36 | }; |
| kocemax | 7:cd3cafda3dd4 | 37 | |
| kocemax | 7:cd3cafda3dd4 | 38 | class Level2 : public Level |
| kocemax | 7:cd3cafda3dd4 | 39 | { |
| kocemax | 7:cd3cafda3dd4 | 40 | public: |
| kocemax | 7:cd3cafda3dd4 | 41 | virtual void initBricks(Map &map); |
| kocemax | 7:cd3cafda3dd4 | 42 | }; |
| kocemax | 7:cd3cafda3dd4 | 43 | |
| kocemax | 7:cd3cafda3dd4 | 44 | |
| kocemax | 5:12c179da4788 | 45 | |
| kocemax | 5:12c179da4788 | 46 | class Map |
| kocemax | 5:12c179da4788 | 47 | { |
| kocemax | 6:39bda45efeed | 48 | private: |
| kocemax | 7:cd3cafda3dd4 | 49 | int currentLevel; //keeps track of the current level |
| kocemax | 7:cd3cafda3dd4 | 50 | std::vector<Level*> levels; //stores the levels in a vector |
| kocemax | 7:cd3cafda3dd4 | 51 | std::vector<Brick> bricks; //stores the bricks in a vector |
| kocemax | 7:cd3cafda3dd4 | 52 | //std::vector<PowerUp> powerUps; |
| kocemax | 5:12c179da4788 | 53 | |
| kocemax | 5:12c179da4788 | 54 | public: |
| kocemax | 7:cd3cafda3dd4 | 55 | Map(); |
| kocemax | 5:12c179da4788 | 56 | ~Map(); |
| kocemax | 7:cd3cafda3dd4 | 57 | |
| kocemax | 7:cd3cafda3dd4 | 58 | int getCurrentLevel() { return currentLevel; } //returns the current level |
| kocemax | 7:cd3cafda3dd4 | 59 | bool hasWon() { return currentLevel >= levels.size(); } //true if current level = number of levels |
| kocemax | 7:cd3cafda3dd4 | 60 | |
| kocemax | 6:39bda45efeed | 61 | void initBricks(); |
| kocemax | 5:12c179da4788 | 62 | void drawMap(N5110 &lcd); |
| kocemax | 7:cd3cafda3dd4 | 63 | void checkCollision(GameObject &obj); // checks if brick<->ball collided |
| kocemax | 7:cd3cafda3dd4 | 64 | void resolveCollision(const Brick &brick, GameObject &obj); //resolves the collision |
| kocemax | 7:cd3cafda3dd4 | 65 | bool checkLevel(); //checks if we cleared the level and if we won |
| kocemax | 7:cd3cafda3dd4 | 66 | void reset(); //resets game |
| kocemax | 7:cd3cafda3dd4 | 67 | void addBrick(Brick& brick) { bricks.push_back(brick); } //adds the bricks to the vector |
| kocemax | 5:12c179da4788 | 68 | |
| kocemax | 5:12c179da4788 | 69 | }; |
| kocemax | 5:12c179da4788 | 70 | #endif |