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.
HighScore/HighScore.cpp@76:6daba3002424, 2020-05-24 (annotated)
- Committer:
- evanso
- Date:
- Sun May 24 18:38:50 2020 +0000
- Revision:
- 76:6daba3002424
- Parent:
- 75:643a509cf9ed
- Child:
- 77:2ee9d1f9e282
Added functions to high score that save and read the high score. Displays "NEW HIGH SOCRE" on the game over screen and plays a different song
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evanso | 75:643a509cf9ed | 1 | #include "HighScore.h" |
evanso | 75:643a509cf9ed | 2 | |
evanso | 76:6daba3002424 | 3 | HighScore::HighScore() { |
evanso | 76:6daba3002424 | 4 | |
evanso | 76:6daba3002424 | 5 | } |
evanso | 76:6daba3002424 | 6 | |
evanso | 76:6daba3002424 | 7 | HighScore::~HighScore() { |
evanso | 76:6daba3002424 | 8 | |
evanso | 76:6daba3002424 | 9 | } |
evanso | 76:6daba3002424 | 10 | |
evanso | 76:6daba3002424 | 11 | void HighScore::init(){ |
evanso | 76:6daba3002424 | 12 | error_ = false; |
evanso | 76:6daba3002424 | 13 | } |
evanso | 76:6daba3002424 | 14 | |
evanso | 76:6daba3002424 | 15 | void HighScore::no_high_scores(N5110 &lcd){ |
evanso | 76:6daba3002424 | 16 | //print error screen |
evanso | 76:6daba3002424 | 17 | lcd.clear(); |
evanso | 76:6daba3002424 | 18 | lcd.printString("No High Scores",0,3); |
evanso | 76:6daba3002424 | 19 | lcd.refresh(); |
evanso | 76:6daba3002424 | 20 | wait(3); |
evanso | 76:6daba3002424 | 21 | } |
evanso | 76:6daba3002424 | 22 | |
evanso | 76:6daba3002424 | 23 | void HighScore::error_open_file(N5110 &lcd){ |
evanso | 76:6daba3002424 | 24 | error_ = true; |
evanso | 76:6daba3002424 | 25 | |
evanso | 76:6daba3002424 | 26 | //print error screen |
evanso | 76:6daba3002424 | 27 | lcd.clear(); |
evanso | 76:6daba3002424 | 28 | lcd.printString(" Unable to ",9,3); |
evanso | 76:6daba3002424 | 29 | lcd.printString(" open file ",9,4); |
evanso | 76:6daba3002424 | 30 | lcd.refresh(); |
evanso | 76:6daba3002424 | 31 | wait(3); |
evanso | 76:6daba3002424 | 32 | } |
evanso | 76:6daba3002424 | 33 | |
evanso | 76:6daba3002424 | 34 | void HighScore::save_new_high_score(SDFileSystem &sd, N5110 &lcd, |
evanso | 76:6daba3002424 | 35 | int new_high_score){ |
evanso | 76:6daba3002424 | 36 | FILE *fp; |
evanso | 76:6daba3002424 | 37 | |
evanso | 76:6daba3002424 | 38 | //overwirtes previous high score |
evanso | 76:6daba3002424 | 39 | fp = fopen("/sd/SavedGamesOne.csv", "w"); |
evanso | 76:6daba3002424 | 40 | |
evanso | 76:6daba3002424 | 41 | |
evanso | 76:6daba3002424 | 42 | if (fp == NULL) { |
evanso | 76:6daba3002424 | 43 | error_open_file(lcd); |
evanso | 76:6daba3002424 | 44 | |
evanso | 76:6daba3002424 | 45 | }else{ |
evanso | 76:6daba3002424 | 46 | |
evanso | 76:6daba3002424 | 47 | //Adda data to file if no error |
evanso | 76:6daba3002424 | 48 | fprintf(fp, "%d", new_high_score); |
evanso | 76:6daba3002424 | 49 | fclose(fp); |
evanso | 76:6daba3002424 | 50 | } |
evanso | 76:6daba3002424 | 51 | } |
evanso | 76:6daba3002424 | 52 | |
evanso | 76:6daba3002424 | 53 | int HighScore::read_high_score(SDFileSystem &sd){ |
evanso | 76:6daba3002424 | 54 | FILE *fp; |
evanso | 76:6daba3002424 | 55 | int saved_high_score = 0; |
evanso | 76:6daba3002424 | 56 | |
evanso | 76:6daba3002424 | 57 | fp = fopen("/sd/HighScore.csv", "r"); |
evanso | 76:6daba3002424 | 58 | |
evanso | 76:6daba3002424 | 59 | //check if highscore game files |
evanso | 76:6daba3002424 | 60 | if (fp == NULL) { |
evanso | 76:6daba3002424 | 61 | error_ = true; |
evanso | 76:6daba3002424 | 62 | |
evanso | 76:6daba3002424 | 63 | //Reads current high score if no high score is set zero is returned |
evanso | 76:6daba3002424 | 64 | }else{ |
evanso | 76:6daba3002424 | 65 | |
evanso | 76:6daba3002424 | 66 | //read save file and add values to saved_high_score int |
evanso | 76:6daba3002424 | 67 | fscanf(fp, "%d", &saved_high_score); |
evanso | 76:6daba3002424 | 68 | |
evanso | 76:6daba3002424 | 69 | fclose(fp); |
evanso | 76:6daba3002424 | 70 | } |
evanso | 76:6daba3002424 | 71 | |
evanso | 76:6daba3002424 | 72 | return saved_high_score; |
evanso | 76:6daba3002424 | 73 | } |
evanso | 76:6daba3002424 | 74 | |
evanso | 76:6daba3002424 | 75 | bool HighScore::get_error(){ |
evanso | 76:6daba3002424 | 76 | return error_; |
evanso | 76:6daba3002424 | 77 | } |
evanso | 76:6daba3002424 | 78 | |
evanso | 76:6daba3002424 | 79 | |
evanso | 76:6daba3002424 | 80 | void HighScore::set_error(bool error){ |
evanso | 76:6daba3002424 | 81 | error_ = error; |
evanso | 76:6daba3002424 | 82 | } |