Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:985fab783b92
- Parent:
- 2:6c1d7aa20e81
- Child:
- 4:13cc179c11c5
--- a/main.cpp Wed Apr 03 15:37:52 2019 +0000
+++ b/main.cpp Fri Apr 12 13:56:13 2019 +0000
@@ -1,326 +1,174 @@
-/*
-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 //
+///////// 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
+#define PADDLE_WIDTH 2
+#define PADDLE_HEIGHT 8
+#define BALL_SIZE 2
+#define BALL_SPEED 3
-// structs //
+/////////////// structs /////////////////
struct UserInput {
Direction d;
float mag;
};
-
-
-// objects //
+/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
-SpaceInvadersEngine SpaceInvaders;
-
-// prototypes //
+//Direction _d;
+//SpaceEngine space;
+///////////// 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
-
-
+const int run[12][10] = {
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,1,1,1,1,0,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,1,1,0,1,1,0,1,1,1 },
+ { 1,0,0,0,1,1,0,0,0,0 },
+ { 0,0,0,1,1,1,1,0,0,0 },
+ { 0,0,1,1,0,0,1,1,0,0 },
+ { 1,1,1,1,0,0,0,1,1,0 },
+ { 0,0,0,0,0,0,1,1,0,0 },
+ { 0,0,0,0,0,1,1,0,0,0 },
+ { 0,0,0,0,1,1,0,0,0,0 },
+};
+const int bullet[4][10] = {
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,1,1,1,1,0,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+};
+const int alien[12][10] = {
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,1,1,1,1,0,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
+ { 0,0,1,1,1,1,0,1,0,0 },
-sapceship=
-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 :
-
-
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000001111000000000000000000
-0000000000000000111111110000000000000000
-0000000000000000111111110000000000000000
-0000000000000000011111100000000000000000
-0000000000000000001111000000000000000000
-0000000000000000111111110000000000000000
-0000000000000011100110001100000000000000
-0000000000000111000110001110000000000000
-0000000000001101101111011011000000000000
-0000000100000000111111110000000010000000
-0000001100000000111111110000000011000000
-0000001100000010000000000100000011000000
-0000011100001111000000001111000011100000
-0000011100011111111001011111100011100000
-0000011110111111111100111111110111100000
-0000011111111111111111111111111111100000
-0000011111111111111111111111111111100000
-0000001111111111111111111111111111000000
-0000000111110111111111111110111110000000
-0000000011000111111111111110001100000000
-0000000000000011111111111100000000000000
-0000000000000001111111111000000000000000
-0000000000000000111111110000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-0000000000000000000000000000000000000000
-
-
-
-
-//functions //
+};
+/*
+const int space_ship[10][12]={
+ {0,0,0,0,0,0,0,1,0,0,0,0},
+ {},
+
+ };
+*/
+Direction _d2;
+///////////// 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
+ //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
+
+ int y=0;
+
+ //define the x position of bullet from the space ship
+ int x_bullet=0;
+
+ //define the y position of the bullet from the space ship
+ int y_bullet=0;
+ int y_alien=10;
+ int x_alien=70;
+ int bullet_fired=0;
+ // game loop - read input, update the game state and render the display
while (1) {
- pong.read_input(pad);
- pong.update(pad);
- render();
+ lcd.clear();
+ lcd.drawSprite(0,y,12,10,(int *)run);
+
+ lcd.drawSprite(x_alien,y_alien,12,10,(int *)alien);
+ lcd.drawSprite(x_bullet,y_bullet,4,10,(int *)bullet);
+ //space.read_input(pad);
+ _d2 = pad.get_direction();
+ if(_d2==N)
+ //pong.update(pad);
+ //render();
+ y=y-2;
+ else
+ if(_d2==S)
+ y=y+2;
+ else if(_d2==E){
+ bullet_fired=1;
+ x_bullet=11;
+ y_bullet=y;
+ }
+ if(y>=40)
+ y=40;
+ else
+ if(y<=0)
+ y=0;
+
+ if(bullet_fired==1)
+ x_bullet+=4;
+ if(x_bullet>=x_alien && y_bullet >=y_alien && y_bullet <=y_alien+10)
+ y=0;
wait(1.0f/fps);
+
+ lcd.refresh();
}
}
-
-
-
- // initialies all classes and libraries
+
+// 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
+ //pong.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("Space Invador!",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);
+ wait(0.1); //wait 0.1 seconds
pad.leds_off();
wait(0.1);
}
-}
-
\ No newline at end of file
+}
\ No newline at end of file