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.

main.cpp

Committer:
el18jgb
Date:
2020-05-24
Revision:
23:0e8155320571
Parent:
22:7406068f6c59

File content as of revision 23:0e8155320571:

/* 
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
2019/20

Name:Joe Body
Username:el18jgb
Student ID Number:201215898
Date:11/03/2020
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Aim.h"
#include "Heston.h"
#include "Eng.h"
#include "Menu.h"
#include "FXOS8700CQ.h"
#include "SDFileSystem.h"
#include "Highscore.h"
#include "Sound.h"


// macro for testing, includes tests.h which contains all tests
#ifdef TEST_GAME
    #include "test.h"
#endif


// objects
Gamepad pad;
N5110 lcd;
Menu menu;
Eng eng;
FXOS8700CQ acc(I2C_SDA,I2C_SCL);
Highscore hs;
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");


void init();
void render();
void play(Gamepad &pad, N5110 &lcd, FXOS8700CQ &acc);


int main()
{
    
#ifdef TEST_GAME
    int failed = run_all_tests(sd);
    printf("\n\n%d failed\n", failed);
    printf("complete \n");
#endif

    //int fps = 10;  // frames per second
    //int A_timer = 0;
    init();     // initialise and then display welcome screen...
    while (1) {
        menu.display(lcd, pad);
        int mode = menu.getmode();
        wait(0.1);  // and wait for one frame period
        if (mode == 0){
            menu.display(lcd, pad);
        }
        if (mode == 1){
            play(pad, lcd, acc);
        }
        else if (mode == 2){
            menu.highs_screen(lcd, pad, hs, sd);
        }
        else if (mode == 3){
            menu.instructions(lcd, pad);
        }
        mode = 0;
    }
    
}

// initialies all classes and libraries
void init()
{
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();
    
    acc.init();

    eng.init();
    

}

// this function draws each frame on the LCD
void render()
{
    // clear screen, re-draw and refresh
    lcd.clear(); 

    eng.draw(lcd);
    lcd.refresh();
}


void play(Gamepad &pad, N5110 &lcd, FXOS8700CQ &acc)
{
    int A_timer = 0;
    eng.init();
    while (1) {
        //read_input(pad);
        int fire = 0;
        if (A_timer <= 0){//shot timer to prevent spam
            fire = 0;
            if (pad.A_held()){//a held worked better than pressed
                fire = 1;
                A_timer = 6;
                
            }
        }
        

        eng.update(pad, fire, lcd, acc);
        render();
        wait(0.1);
        
        //if (fire == 1){
        int x = eng.checkgame(lcd);
            if (x == 1) {
                eng.gameover(lcd, pad, hs, sd);
                break;
            }
        //}
        
        A_timer--;
        
        eng.tik();
        //printf("fire =  %d\n", fire);
        //printf("shot cooldown =  %d\n", A_timer);

    }
}