ELEC2645 (2018/19) / Mbed 2 deprecated fy14lkaa

Dependencies:   mbed

main.cpp

Committer:
fy14lkaa
Date:
2019-03-22
Revision:
0:e2af4c8e462e
Child:
1:e8c6d93c9122

File content as of revision 0:e2af4c8e462e:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name:Laila Al Badwawi
Username: fy14lkaa
Student ID Number: 200906179
Date:19/3/2019
*/


///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "SpaceInvadersEngine.h"

#ifdef WITH_TESTING
# include "tests.h"
#endif

#define 
#define
#define
#define
#define

/////////////// structs /////////////////
struct UserInput {
    Direction d;
    float mag;
};


/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
SpaceInvadersEngine SpaceInvaders;

///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
void render();
void welcome();




const int alien [3] [3]={
    

{0000000000000000000000000000000000000000}
{0000000000011100000000000011100000000000}
{0000000000011100000000000011100000000000}
{0000000110011111000000001111100110000000}
{0000001110000111000000001110000111000000}
{0000001110000111100000011110000111000000}
{0000001110011111111111111111100111000000}
{0000001110011111111111111111100111000000}
{0000001111111111111111111111111111000000}
{0000001111111111111111111111111111000000}
{0000001111111111111111111111111111000000}
{0000001111111111111111111111111111000000}
{0000001111111111111111111111111111000000}
{0000001111111111111111111111111111000000}
{0000000011111111111111111111111100000000}
{0000000001111111111111111111111000000000}
{0000000000011100000000000011100000000000}
{0000000000011100000000000011100000000000}
{0000000001111100000000000011111000000000}
{0000000001100000000000000000011000000000}
{0000000001100000000000000000011000000000}
{0000000000000000000000000000000000000000}


const int alien [3] [3]={

1111111111111111111111111111111111111111
1111111111111111110000111111111111111111
1111111111111111110000111111111111111111
1111111111111111000000001111111111111111
1111111111111110000000001111111111111111
1111111111111110000000000111111111111111
1111111111111000000000000011111111111111
1111111111111000000000000001111111111111
1111111111100001110000110000011111111111
1111111111100001110000110000011111111111
1111111111100000000000000000011111111111
1111111111100000000000000000011111111111
1111111111111110001111001111111111111111
1111111111111110001111001111111111111111
1111111111111101111111111011111111111111
1111111111111001111111110011111111111111
1111111111111001111111110011111111111111
1111111111111110001111001111111111111111
1111111111111110001111001111111111111111
1111111111111111111111111111111111111111

figure 3 





0000000000000000000000000000000000000000
0000000000110000000000000110000000000000
0000000000110000000000000110000000000000
0000000000000000000000000000000000000000
0000000000000110000000011000000000000000
0000000000000110000000011000000000000000
0000000000111111111111111110000000000000
0000000000111111111111111110000000000000
0000000000111001111111100111000000000000
0000000011110001111111000111110000000000
0000000011110001111111000111110000000000
0000011111111111111111111111111100000000
0000011111111111111111111111111100000000
0000011100111111111111111111001100000000
0000011000111111111111111110001100000000
0000011000111111111111111110001100000000
0000011000110000000000000110001100000000
0000011000110000000000000110001100000000
0000000000000000000000000000000000000000
0000000000000111100011111000000000000000
0000000000000111100011111000000000000000
0000000000000000000000000000000000000000



sapce ship=
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000011000000000000000000
00000000000000000011000000000000000000
00000000000000000011000000000000000000
00000000000000000011000000000000000000
00000000000000000011000000000000000000
00000000000000001111110000000000000000
00000000000000001111110000000000000000
00000000000000001111110000000000000000
00000000000000001111110000000000000000
00000000000000001111110000000000000000
00000000000000001111110000000000000000
00000000000000001111110000000000000000
00000000000000011111111000000000000000
00000000000000011111111000000000000000
00000000000110011111111001100000000000
00000000000110011111111001100000000000
00000000000110111100111101100000000000
00000000000110111100111101100000000000
00000000000001110000001110000000000000
00000000000001110000001110000000000000
00001000011111110011001111111000010000
00001000011111111111111111111000010000
00001001111111111111111111111110010000
00001111111111111111111111111111110000
00001111111111111111111111111111110000
00001111111111101111110111111111110000
00001111111111101111110111111111110000
00001111111000001111110000011111110000
00001111111000001111110000011111110000
00001111100000001111110000000111110000
00001111100000001111110000000111110000
00001110000000000011000000000001110000
00001100000000000011000000000000110000
00001000000000000011000000000000010000
00001000000000000011000000000000010000
00001000000000000011000000000000010000
00000000000000000000000000000000000000
00000000000000000000000000000000000000


welcome:

11111111111111111111111111111
11111111000001111111111111111
11111111110000111111111111111
11111111100011011111111111111
11111111100011011111111111111
11111111110000011111111111111
11111111110010011111111111111
11111111111000001111110011111
11111111110011101111110010001
11111111110000001111100000001
11111001001100000001100000001
10011000111111001110001000111
10000000111111111111001100111
10000000111111111100010001111
11000010011111111110011010111
11000000011111111110001000111
11000000011111100001000000111
11001011011110000000001110011
11001011011100111111000111011
10000000001011111111000110011
10011110101111111111000000111
10011110100111111111011001111
11011101100111111110011111111
11100011100111111110111111111
11111111101111111100111111111
11111111101111111001111111111
11111111101111110011111111111
11111111001100101111111111111
11111110001100011111111111111
11111110000001111111111111111
11111110000001111111111111111
11111100000011111111111111111
11111100001111111111111111111
11111100001111111111111111111
11111100011111111111111111111
11111100011111111111111111111
11111100001100011111111111111
11111110000000111111111111111
11111111100111111111111111111
11111111111111111111111111111


game over :






///////////// functions ////////////////
int main()
{
#ifdef WITH_TESTING
    int number_of_failures = run_all_tests();

    if(number_of_failures > 0) return number_of_failures;
#endif

    int fps = 8;  // frames per second

    init();     // initialise and then display welcome screen...
    welcome();  // waiting for the user to start
    
    render();  // first draw the initial frame 
    wait(1.0f/fps);  // and wait for one frame period
 // game loop - read input, update the game state and render the display
    while (1) {
         pong.read_input(pad);
        pong.update(pad);
        render();
        wait(1.0f/fps);
    }
}
        
        
        
        // initialies all classes and libraries
void init()
{
    // need to initialise LCD and Gamepad 
    lcd.init();
     pad.init();
      
    // initialise the game with correct ball and paddle sizes
    SpaceInvaders.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED);
    
    // this function draws each frame on the LCD
void render()
{
    // clear screen, re-draw and refresh
    lcd.clear();  
    SpaceInvaders.draw(lcd);
    lcd.refresh();
}
 
// simple splash screen displayed on start-up
void welcome() {
    
    lcd.printString("    SpaceInvaders !    ",0,1);  
    lcd.printString("  Press Start ",0,4);
    lcd.refresh();
     
    // wait flashing LEDs until start button is pressed 
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
 
}