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.
Dependencies: mbed Gamepad N5110 mbed-rtos
MiniGame/MiniGame.h@7:574c66ebd8b0, 2019-05-09 (annotated)
- Committer:
- RexRoshan
- Date:
- Thu May 09 09:54:50 2019 +0000
- Revision:
- 7:574c66ebd8b0
- Child:
- 8:748187456a1a
Documentation has been completed and the code has been slightly modified
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| RexRoshan | 7:574c66ebd8b0 | 1 | #ifndef MINIGAME_H | 
| RexRoshan | 7:574c66ebd8b0 | 2 | #define MINIGAME_H | 
| RexRoshan | 7:574c66ebd8b0 | 3 | |
| RexRoshan | 7:574c66ebd8b0 | 4 | #include "mbed.h" | 
| RexRoshan | 7:574c66ebd8b0 | 5 | #include "N5110.h" | 
| RexRoshan | 7:574c66ebd8b0 | 6 | #include "Gamepad.h" | 
| RexRoshan | 7:574c66ebd8b0 | 7 | #include "Background.h" | 
| RexRoshan | 7:574c66ebd8b0 | 8 | #include "MiniEnemy.h" | 
| RexRoshan | 7:574c66ebd8b0 | 9 | #include "Beam.h" | 
| RexRoshan | 7:574c66ebd8b0 | 10 | #include "Spacecraft.h" | 
| RexRoshan | 7:574c66ebd8b0 | 11 | |
| RexRoshan | 7:574c66ebd8b0 | 12 | #define GAP 2 | 
| RexRoshan | 7:574c66ebd8b0 | 13 | |
| RexRoshan | 7:574c66ebd8b0 | 14 | /** GameEngine Class | 
| RexRoshan | 7:574c66ebd8b0 | 15 | * @brief The game engine for the game | 
| RexRoshan | 7:574c66ebd8b0 | 16 | * @author Rex Roshan Raj | 
| RexRoshan | 7:574c66ebd8b0 | 17 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 18 | class MiniGame | 
| RexRoshan | 7:574c66ebd8b0 | 19 | { | 
| RexRoshan | 7:574c66ebd8b0 | 20 | |
| RexRoshan | 7:574c66ebd8b0 | 21 | public: | 
| RexRoshan | 7:574c66ebd8b0 | 22 | |
| RexRoshan | 7:574c66ebd8b0 | 23 | /** Constructor */ | 
| RexRoshan | 7:574c66ebd8b0 | 24 | MiniGame(); | 
| RexRoshan | 7:574c66ebd8b0 | 25 | |
| RexRoshan | 7:574c66ebd8b0 | 26 | /** Destructor */ | 
| RexRoshan | 7:574c66ebd8b0 | 27 | ~MiniGame(); | 
| RexRoshan | 7:574c66ebd8b0 | 28 | |
| RexRoshan | 7:574c66ebd8b0 | 29 | /** Initialises the parameters | 
| RexRoshan | 7:574c66ebd8b0 | 30 | * @param spacecraft x pos | 
| RexRoshan | 7:574c66ebd8b0 | 31 | * @param spacecraft y pos | 
| RexRoshan | 7:574c66ebd8b0 | 32 | * @param beam_size | 
| RexRoshan | 7:574c66ebd8b0 | 33 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 34 | void init(int spacecraft_xpos,int spacecraft_ypos,int beam_size,int u_cloudx, int u_cloudy, int l_cloudx, int l_cloudy); | 
| RexRoshan | 7:574c66ebd8b0 | 35 | |
| RexRoshan | 7:574c66ebd8b0 | 36 | /** Read the input | 
| RexRoshan | 7:574c66ebd8b0 | 37 | * @param Gamepad pad | 
| RexRoshan | 7:574c66ebd8b0 | 38 | * @brief Reads the input from the Gamepad | 
| RexRoshan | 7:574c66ebd8b0 | 39 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 40 | void read_input(Gamepad &pad); | 
| RexRoshan | 7:574c66ebd8b0 | 41 | |
| RexRoshan | 7:574c66ebd8b0 | 42 | /** Draws objects in minigame | 
| RexRoshan | 7:574c66ebd8b0 | 43 | * @param N5110 lcd | 
| RexRoshan | 7:574c66ebd8b0 | 44 | * @brief Draws the characters and the beams involved in the minigame | 
| RexRoshan | 7:574c66ebd8b0 | 45 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 46 | void draw_minigame(Gamepad &pad,N5110 &lcd); | 
| RexRoshan | 7:574c66ebd8b0 | 47 | |
| RexRoshan | 7:574c66ebd8b0 | 48 | /** Updates minigame | 
| RexRoshan | 7:574c66ebd8b0 | 49 | * @param Gamepad pad | 
| RexRoshan | 7:574c66ebd8b0 | 50 | * @param N5110 lcd | 
| RexRoshan | 7:574c66ebd8b0 | 51 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 52 | void update_minigame(Gamepad &pad,N5110 &lcd); | 
| RexRoshan | 7:574c66ebd8b0 | 53 | |
| RexRoshan | 7:574c66ebd8b0 | 54 | /** Draws the score | 
| RexRoshan | 7:574c66ebd8b0 | 55 | * @param N5110 lcd | 
| RexRoshan | 7:574c66ebd8b0 | 56 | * @brief Outputs the score obtained by the player | 
| RexRoshan | 7:574c66ebd8b0 | 57 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 58 | void draw_score(N5110 &lcd); | 
| RexRoshan | 7:574c66ebd8b0 | 59 | |
| RexRoshan | 7:574c66ebd8b0 | 60 | /** Gets the game stage | 
| RexRoshan | 7:574c66ebd8b0 | 61 | * @brief Gets the current stage of the game | 
| RexRoshan | 7:574c66ebd8b0 | 62 | * @return stage | 
| RexRoshan | 7:574c66ebd8b0 | 63 | */ | 
| RexRoshan | 7:574c66ebd8b0 | 64 | int get_game_stage(); | 
| RexRoshan | 7:574c66ebd8b0 | 65 | |
| RexRoshan | 7:574c66ebd8b0 | 66 | private: | 
| RexRoshan | 7:574c66ebd8b0 | 67 | |
| RexRoshan | 7:574c66ebd8b0 | 68 | void check_cloud_wall_collision(Gamepad &pad); // check if the background has collided with the wall | 
| RexRoshan | 7:574c66ebd8b0 | 69 | void check_wall_collision(Gamepad &pad); // check if the enemy has collided with the wall | 
| RexRoshan | 7:574c66ebd8b0 | 70 | void check_player_collision(Gamepad &pad); // Check if the player has collided with the enemy | 
| RexRoshan | 7:574c66ebd8b0 | 71 | void check_enemy_collisions(Gamepad &pad); // check if the player spacecraft beam collided with the enemy in minigame | 
| RexRoshan | 7:574c66ebd8b0 | 72 | void enemy_dead(N5110 &lcd,Gamepad &pad); // check if enemy spacecraft is dead | 
| RexRoshan | 7:574c66ebd8b0 | 73 | void spacecraft_dead(N5110 &lcd,Gamepad &pad); // check if the player spacecraft is dead | 
| RexRoshan | 7:574c66ebd8b0 | 74 | void check_playerbeam_collision(Gamepad &pad); // check if the player's spacecraft beam collided with the wall | 
| RexRoshan | 7:574c66ebd8b0 | 75 | |
| RexRoshan | 7:574c66ebd8b0 | 76 | void add_speed(); // adds the speed | 
| RexRoshan | 7:574c66ebd8b0 | 77 | void add_counter(); // adds the counter | 
| RexRoshan | 7:574c66ebd8b0 | 78 | |
| RexRoshan | 7:574c66ebd8b0 | 79 | void draw_kills(N5110 &lcd); // draws the number of kills | 
| RexRoshan | 7:574c66ebd8b0 | 80 | |
| RexRoshan | 7:574c66ebd8b0 | 81 | int _spacecraft_xpos; // x position of the spacecrafts | 
| RexRoshan | 7:574c66ebd8b0 | 82 | int _spacecraft_ypos; // y position of the spacecrafts | 
| RexRoshan | 7:574c66ebd8b0 | 83 | |
| RexRoshan | 7:574c66ebd8b0 | 84 | int _u_cloudx; | 
| RexRoshan | 7:574c66ebd8b0 | 85 | int _u_cloudy; | 
| RexRoshan | 7:574c66ebd8b0 | 86 | |
| RexRoshan | 7:574c66ebd8b0 | 87 | int _l_cloudx; | 
| RexRoshan | 7:574c66ebd8b0 | 88 | int _l_cloudy; | 
| RexRoshan | 7:574c66ebd8b0 | 89 | |
| RexRoshan | 7:574c66ebd8b0 | 90 | int _p1x; | 
| RexRoshan | 7:574c66ebd8b0 | 91 | int get_counter(); // value of the counter | 
| RexRoshan | 7:574c66ebd8b0 | 92 | int _counter; | 
| RexRoshan | 7:574c66ebd8b0 | 93 | int set_counter(); | 
| RexRoshan | 7:574c66ebd8b0 | 94 | |
| RexRoshan | 7:574c66ebd8b0 | 95 | Beam _beam; // Player beam | 
| RexRoshan | 7:574c66ebd8b0 | 96 | |
| RexRoshan | 7:574c66ebd8b0 | 97 | int _beam_size; // beam size in minigame | 
| RexRoshan | 7:574c66ebd8b0 | 98 | |
| RexRoshan | 7:574c66ebd8b0 | 99 | Direction _d; | 
| RexRoshan | 7:574c66ebd8b0 | 100 | float _mag; | 
| RexRoshan | 7:574c66ebd8b0 | 101 | |
| RexRoshan | 7:574c66ebd8b0 | 102 | bool _L; | 
| RexRoshan | 7:574c66ebd8b0 | 103 | bool _R; | 
| RexRoshan | 7:574c66ebd8b0 | 104 | bool spacebeam; | 
| RexRoshan | 7:574c66ebd8b0 | 105 | bool score; | 
| RexRoshan | 7:574c66ebd8b0 | 106 | |
| RexRoshan | 7:574c66ebd8b0 | 107 | |
| RexRoshan | 7:574c66ebd8b0 | 108 | Spacecraft _p1; // player spacecraft | 
| RexRoshan | 7:574c66ebd8b0 | 109 | MiniEnemy _e1; // Minigame enemy | 
| RexRoshan | 7:574c66ebd8b0 | 110 | Background _b1; // Background | 
| RexRoshan | 7:574c66ebd8b0 | 111 | |
| RexRoshan | 7:574c66ebd8b0 | 112 | int _stage; | 
| RexRoshan | 7:574c66ebd8b0 | 113 | int _score; | 
| RexRoshan | 7:574c66ebd8b0 | 114 | |
| RexRoshan | 7:574c66ebd8b0 | 115 | }; | 
| RexRoshan | 7:574c66ebd8b0 | 116 | |
| RexRoshan | 7:574c66ebd8b0 | 117 | #endif |