Ben Evans University Second Year Project. Game Called Defender.
Hello, soldier, you have been specially selected as the defender of planet earth.
Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.
But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.
As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.
SavedGames/SavedGames.h@60:55fdc6bb29b9, 2020-05-20 (annotated)
- Committer:
- evanso
- Date:
- Wed May 20 18:14:42 2020 +0000
- Revision:
- 60:55fdc6bb29b9
- Parent:
- 59:0b2e43312d6b
- Child:
- 61:7c4ec680a428
Added function to the screen that lets you select with file to save to
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evanso | 49:ed569eceeaa4 | 1 | #ifndef SAVEDGAMES_H |
evanso | 49:ed569eceeaa4 | 2 | #define SAVEDGAMES_H |
evanso | 49:ed569eceeaa4 | 3 | |
evanso | 49:ed569eceeaa4 | 4 | // Included libraries ---------------------------------------------------------- |
evanso | 49:ed569eceeaa4 | 5 | #include "mbed.h" |
evanso | 49:ed569eceeaa4 | 6 | #include "N5110.h" |
evanso | 49:ed569eceeaa4 | 7 | #include "Gamepad.h" |
evanso | 50:13c8710985f4 | 8 | #include "SDFileSystem.h" |
evanso | 51:35cb8e604b72 | 9 | #include <vector> |
evanso | 51:35cb8e604b72 | 10 | |
evanso | 51:35cb8e604b72 | 11 | struct SavedGamesData{ |
evanso | 52:feb8cf28bcff | 12 | int score; /**< Score variable */ |
evanso | 52:feb8cf28bcff | 13 | int lives; /**< lives left variable */ |
evanso | 52:feb8cf28bcff | 14 | int smart_bombs; /**< smart_bombs left variable */ |
evanso | 52:feb8cf28bcff | 15 | int alien_number; /**< number of alien on screen variable*/ |
evanso | 51:35cb8e604b72 | 16 | }; |
evanso | 49:ed569eceeaa4 | 17 | |
evanso | 49:ed569eceeaa4 | 18 | /** SavedGames class |
evanso | 49:ed569eceeaa4 | 19 | * @brief Stores saved games on sd card, stores score, lives, smart bombs and |
evanso | 49:ed569eceeaa4 | 20 | * number of current alliens |
evanso | 49:ed569eceeaa4 | 21 | * @author Benjamin Evans, University of Leeds |
evanso | 49:ed569eceeaa4 | 22 | * @date May 2020 |
evanso | 49:ed569eceeaa4 | 23 | */ |
evanso | 49:ed569eceeaa4 | 24 | class SavedGames{ |
evanso | 49:ed569eceeaa4 | 25 | public: |
evanso | 49:ed569eceeaa4 | 26 | /** Constructor */ |
evanso | 49:ed569eceeaa4 | 27 | SavedGames(); |
evanso | 49:ed569eceeaa4 | 28 | |
evanso | 49:ed569eceeaa4 | 29 | /** Destructor */ |
evanso | 49:ed569eceeaa4 | 30 | ~SavedGames(); |
evanso | 49:ed569eceeaa4 | 31 | |
evanso | 51:35cb8e604b72 | 32 | /** Initalises SavedGames |
evanso | 51:35cb8e604b72 | 33 | * @param lcd @details N5110 object |
evanso | 51:35cb8e604b72 | 34 | * @param sd @details sd card object |
evanso | 51:35cb8e604b72 | 35 | */ |
evanso | 50:13c8710985f4 | 36 | void init(SDFileSystem &sd,N5110 &lcd); |
evanso | 49:ed569eceeaa4 | 37 | |
evanso | 51:35cb8e604b72 | 38 | /** Check if sd card is inserted and print message if not |
evanso | 51:35cb8e604b72 | 39 | * @param lcd @details N5110 object |
evanso | 51:35cb8e604b72 | 40 | * @param sd @details sd card object |
evanso | 51:35cb8e604b72 | 41 | */ |
evanso | 51:35cb8e604b72 | 42 | void check_sd_present(SDFileSystem &sd,N5110 &lcd); |
evanso | 51:35cb8e604b72 | 43 | |
evanso | 53:01be7898c23f | 44 | /** shows error if saved data files opens incorrectly |
evanso | 51:35cb8e604b72 | 45 | * @param lcd @details N5110 object |
evanso | 51:35cb8e604b72 | 46 | */ |
evanso | 53:01be7898c23f | 47 | void error_open_file(N5110 &lcd); |
evanso | 51:35cb8e604b72 | 48 | |
evanso | 51:35cb8e604b72 | 49 | /** Adds saved data to sd card |
evanso | 51:35cb8e604b72 | 50 | * @param sd @details sd card object |
evanso | 53:01be7898c23f | 51 | * @param data @details SavedGamesData struct |
evanso | 54:d46459104dea | 52 | * @param lcd @details N5110 object |
evanso | 51:35cb8e604b72 | 53 | */ |
evanso | 59:0b2e43312d6b | 54 | void add_saved_data(SDFileSystem &sd,SavedGamesData data, N5110 &lcd); |
evanso | 53:01be7898c23f | 55 | |
evanso | 53:01be7898c23f | 56 | /** Reads saved data to sd card |
evanso | 53:01be7898c23f | 57 | * @param sd @details sd card object |
evanso | 54:d46459104dea | 58 | * @param lcd @details N5110 object |
evanso | 53:01be7898c23f | 59 | */ |
evanso | 53:01be7898c23f | 60 | void read_saved_data(SDFileSystem &sd, N5110 &lcd); |
evanso | 54:d46459104dea | 61 | |
evanso | 54:d46459104dea | 62 | /** Scrolls through the diffent saved games parts |
evanso | 54:d46459104dea | 63 | * @param d_ @details Direction of joystick |
evanso | 54:d46459104dea | 64 | */ |
evanso | 59:0b2e43312d6b | 65 | void saved_games_scroll(Direction d_); |
evanso | 54:d46459104dea | 66 | |
evanso | 54:d46459104dea | 67 | /** Draws the saved game screen |
evanso | 54:d46459104dea | 68 | * @param lcd @details N5110 object |
evanso | 54:d46459104dea | 69 | */ |
evanso | 54:d46459104dea | 70 | void display_saved_games(N5110 &lcd); |
evanso | 59:0b2e43312d6b | 71 | |
evanso | 60:55fdc6bb29b9 | 72 | /** Draws the select save to save to screen |
evanso | 60:55fdc6bb29b9 | 73 | * @param lcd @details N5110 object |
evanso | 60:55fdc6bb29b9 | 74 | */ |
evanso | 60:55fdc6bb29b9 | 75 | void save_game_screen(N5110 &lcd); |
evanso | 60:55fdc6bb29b9 | 76 | |
evanso | 59:0b2e43312d6b | 77 | /** Vector to store saved game data*/ |
evanso | 59:0b2e43312d6b | 78 | std::vector<SavedGamesData> saved_data_vector; |
evanso | 49:ed569eceeaa4 | 79 | |
evanso | 49:ed569eceeaa4 | 80 | // Accessors and mutators -------------------------------------------------- |
evanso | 49:ed569eceeaa4 | 81 | |
evanso | 50:13c8710985f4 | 82 | /** Gets error flag |
evanso | 50:13c8710985f4 | 83 | * @return error_; |
evanso | 50:13c8710985f4 | 84 | */ |
evanso | 50:13c8710985f4 | 85 | bool get_error(); |
evanso | 50:13c8710985f4 | 86 | |
evanso | 59:0b2e43312d6b | 87 | /** Gets the displayed saved game number |
evanso | 59:0b2e43312d6b | 88 | * @return display_data_number_; |
evanso | 59:0b2e43312d6b | 89 | */ |
evanso | 59:0b2e43312d6b | 90 | int get_display_data_number(); |
evanso | 59:0b2e43312d6b | 91 | |
evanso | 49:ed569eceeaa4 | 92 | private: |
evanso | 49:ed569eceeaa4 | 93 | |
evanso | 49:ed569eceeaa4 | 94 | // Varibles ---------------------------------------------------------------- |
evanso | 49:ed569eceeaa4 | 95 | |
evanso | 50:13c8710985f4 | 96 | /** Flag for error, true = error */ |
evanso | 50:13c8710985f4 | 97 | bool error_; |
evanso | 51:35cb8e604b72 | 98 | |
evanso | 54:d46459104dea | 99 | /** Variable for which vector data to select */ |
evanso | 54:d46459104dea | 100 | int display_data_number_; |
evanso | 49:ed569eceeaa4 | 101 | }; |
evanso | 49:ed569eceeaa4 | 102 | #endif |