Joe Body 201215898

Dependencies:   mbed

Navigation

  • From the Main Menu the A button will take you into one of the play, highscore or instructions options.
  • The B button will return you to the Main Menu from either the highscore or instruction screens, though this is prompted on screen.
  • When in the Main Menu Pot1 can be used to adjust the contrast and the volume control by the speaker is active.
  • When the game is over the B button can be used to return to the Main Menu, again this is prompted.
  • To return to the Main Menu while the game is being played the reset button must be pressed, this will not save your score or anything about the game.

In Game

  • While in the game the A button is used to shoot while you aim with the Joystick.
  • You have control over the cross while the objective of the game is to rack up as many points shooting the moving head.
  • There is a slight reload time on each shot so you are unable to spam A if you miss.
  • Once you miss 6 times the game will end and your score will be saved.
  • When hit by a falling spike the game will transition and the head will vanish.
  • 4 new spikes will spawn which you need to avoid, being hit by 1 of these will decrease your remaining miss chances by 5.
  • When the game is in this state you must avoid these spikes by tilting the device, the Joystick will have no effect.
  • The head will move progressively faster as the game goes on, make use of the clock power up by shooting it when it appears, this will slow the head down to a more manageable level hopefully helping you to reach a higher score.

Highscore

  • If you have a SD card inserted into the device the game can save your highest score.
  • A decent score is somewhere around 25.
Committer:
el18jgb
Date:
Sun May 24 11:24:57 2020 +0000
Revision:
23:0e8155320571
Parent:
22:7406068f6c59
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:b7f1f47bb26a 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
el18jgb 1:1144f48b5965 7 Name:Joe Body
el18jgb 1:1144f48b5965 8 Username:el18jgb
el18jgb 1:1144f48b5965 9 Student ID Number:201215898
el18jgb 1:1144f48b5965 10 Date:11/03/2020
eencae 0:b7f1f47bb26a 11 */
eencae 0:b7f1f47bb26a 12
eencae 0:b7f1f47bb26a 13 // includes
eencae 0:b7f1f47bb26a 14 #include "mbed.h"
eencae 0:b7f1f47bb26a 15 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 16 #include "N5110.h"
el18jgb 4:6f898b000797 17 #include "Aim.h"
el18jgb 2:56b31902c800 18 #include "Heston.h"
el18jgb 5:c37f4ed2cad3 19 #include "Eng.h"
el18jgb 14:66a1965318cb 20 #include "Menu.h"
el18jgb 18:c600a6545e81 21 #include "FXOS8700CQ.h"
el18jgb 19:33c77517cb88 22 #include "SDFileSystem.h"
el18jgb 19:33c77517cb88 23 #include "Highscore.h"
el18jgb 20:6db651a3cfec 24 #include "Sound.h"
el18jgb 19:33c77517cb88 25
eencae 0:b7f1f47bb26a 26
el18jgb 22:7406068f6c59 27 // macro for testing, includes tests.h which contains all tests
el18jgb 22:7406068f6c59 28 #ifdef TEST_GAME
el18jgb 22:7406068f6c59 29 #include "test.h"
el18jgb 22:7406068f6c59 30 #endif
el18jgb 22:7406068f6c59 31
eencae 0:b7f1f47bb26a 32
eencae 0:b7f1f47bb26a 33 // objects
eencae 0:b7f1f47bb26a 34 Gamepad pad;
eencae 0:b7f1f47bb26a 35 N5110 lcd;
el18jgb 14:66a1965318cb 36 Menu menu;
el18jgb 5:c37f4ed2cad3 37 Eng eng;
el18jgb 18:c600a6545e81 38 FXOS8700CQ acc(I2C_SDA,I2C_SCL);
el18jgb 19:33c77517cb88 39 Highscore hs;
el18jgb 19:33c77517cb88 40 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
el18jgb 1:1144f48b5965 41
el18jgb 1:1144f48b5965 42
el18jgb 1:1144f48b5965 43 void init();
el18jgb 1:1144f48b5965 44 void render();
el18jgb 18:c600a6545e81 45 void play(Gamepad &pad, N5110 &lcd, FXOS8700CQ &acc);
el18jgb 23:0e8155320571 46
eencae 0:b7f1f47bb26a 47
eencae 0:b7f1f47bb26a 48 int main()
eencae 0:b7f1f47bb26a 49 {
el18jgb 22:7406068f6c59 50
el18jgb 22:7406068f6c59 51 #ifdef TEST_GAME
el18jgb 22:7406068f6c59 52 int failed = run_all_tests(sd);
el18jgb 22:7406068f6c59 53 printf("\n\n%d failed\n", failed);
el18jgb 22:7406068f6c59 54 printf("complete \n");
el18jgb 22:7406068f6c59 55 #endif
el18jgb 22:7406068f6c59 56
el18jgb 14:66a1965318cb 57 //int fps = 10; // frames per second
el18jgb 14:66a1965318cb 58 //int A_timer = 0;
el18jgb 1:1144f48b5965 59 init(); // initialise and then display welcome screen...
el18jgb 1:1144f48b5965 60 while (1) {
el18jgb 16:7c612029d9c9 61 menu.display(lcd, pad);
el18jgb 16:7c612029d9c9 62 int mode = menu.getmode();
el18jgb 14:66a1965318cb 63 wait(0.1); // and wait for one frame period
el18jgb 16:7c612029d9c9 64 if (mode == 0){
el18jgb 16:7c612029d9c9 65 menu.display(lcd, pad);
el18jgb 16:7c612029d9c9 66 }
el18jgb 14:66a1965318cb 67 if (mode == 1){
el18jgb 18:c600a6545e81 68 play(pad, lcd, acc);
el18jgb 8:0b9a824c75fe 69 }
el18jgb 19:33c77517cb88 70 else if (mode == 2){
el18jgb 19:33c77517cb88 71 menu.highs_screen(lcd, pad, hs, sd);
el18jgb 19:33c77517cb88 72 }
el18jgb 14:66a1965318cb 73 else if (mode == 3){
el18jgb 14:66a1965318cb 74 menu.instructions(lcd, pad);
el18jgb 14:66a1965318cb 75 }
el18jgb 16:7c612029d9c9 76 mode = 0;
el18jgb 1:1144f48b5965 77 }
eencae 0:b7f1f47bb26a 78
eencae 0:b7f1f47bb26a 79 }
eencae 0:b7f1f47bb26a 80
el18jgb 1:1144f48b5965 81 // initialies all classes and libraries
el18jgb 1:1144f48b5965 82 void init()
el18jgb 1:1144f48b5965 83 {
el18jgb 1:1144f48b5965 84 // need to initialise LCD and Gamepad
el18jgb 1:1144f48b5965 85 lcd.init();
el18jgb 1:1144f48b5965 86 pad.init();
el18jgb 18:c600a6545e81 87
el18jgb 18:c600a6545e81 88 acc.init();
el18jgb 5:c37f4ed2cad3 89
el18jgb 5:c37f4ed2cad3 90 eng.init();
el18jgb 18:c600a6545e81 91
el18jgb 1:1144f48b5965 92
el18jgb 1:1144f48b5965 93 }
el18jgb 1:1144f48b5965 94
el18jgb 1:1144f48b5965 95 // this function draws each frame on the LCD
el18jgb 1:1144f48b5965 96 void render()
el18jgb 1:1144f48b5965 97 {
el18jgb 1:1144f48b5965 98 // clear screen, re-draw and refresh
el18jgb 1:1144f48b5965 99 lcd.clear();
el18jgb 5:c37f4ed2cad3 100
el18jgb 5:c37f4ed2cad3 101 eng.draw(lcd);
el18jgb 1:1144f48b5965 102 lcd.refresh();
el18jgb 1:1144f48b5965 103 }
el18jgb 1:1144f48b5965 104
el18jgb 14:66a1965318cb 105
el18jgb 18:c600a6545e81 106 void play(Gamepad &pad, N5110 &lcd, FXOS8700CQ &acc)
el18jgb 14:66a1965318cb 107 {
el18jgb 14:66a1965318cb 108 int A_timer = 0;
el18jgb 16:7c612029d9c9 109 eng.init();
el18jgb 14:66a1965318cb 110 while (1) {
el18jgb 14:66a1965318cb 111 //read_input(pad);
el18jgb 14:66a1965318cb 112 int fire = 0;
el18jgb 23:0e8155320571 113 if (A_timer <= 0){//shot timer to prevent spam
el18jgb 14:66a1965318cb 114 fire = 0;
el18jgb 23:0e8155320571 115 if (pad.A_held()){//a held worked better than pressed
el18jgb 14:66a1965318cb 116 fire = 1;
el18jgb 14:66a1965318cb 117 A_timer = 6;
el18jgb 14:66a1965318cb 118
el18jgb 14:66a1965318cb 119 }
el18jgb 14:66a1965318cb 120 }
el18jgb 14:66a1965318cb 121
el18jgb 14:66a1965318cb 122
el18jgb 18:c600a6545e81 123 eng.update(pad, fire, lcd, acc);
el18jgb 14:66a1965318cb 124 render();
el18jgb 14:66a1965318cb 125 wait(0.1);
el18jgb 14:66a1965318cb 126
el18jgb 19:33c77517cb88 127 //if (fire == 1){
el18jgb 19:33c77517cb88 128 int x = eng.checkgame(lcd);
el18jgb 19:33c77517cb88 129 if (x == 1) {
el18jgb 19:33c77517cb88 130 eng.gameover(lcd, pad, hs, sd);
el18jgb 19:33c77517cb88 131 break;
el18jgb 19:33c77517cb88 132 }
el18jgb 19:33c77517cb88 133 //}
el18jgb 15:01a69bdb85e9 134
el18jgb 14:66a1965318cb 135 A_timer--;
el18jgb 14:66a1965318cb 136
el18jgb 14:66a1965318cb 137 eng.tik();
el18jgb 14:66a1965318cb 138 //printf("fire = %d\n", fire);
el18jgb 14:66a1965318cb 139 //printf("shot cooldown = %d\n", A_timer);
el18jgb 14:66a1965318cb 140
el18jgb 14:66a1965318cb 141 }
el18jgb 14:66a1965318cb 142 }