Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.

Dependencies:   mbed

Revision:
149:bd0f37008f5a
Parent:
137:fe80c0f2da9d
Child:
150:bd02678bfdb1
--- a/main.cpp	Thu May 09 12:09:59 2019 +0000
+++ b/main.cpp	Thu May 09 14:13:43 2019 +0000
@@ -8,50 +8,49 @@
 
 
 
-const 
-int spaceman [48][48]={
+const int spaceman [48][48]= {
 
 
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1},
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1},
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1},
-{0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1},
-{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},
-{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
-{0,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
 
@@ -81,16 +80,16 @@
 int main()
 {
 
-    int fps = 8;      //declaration of intger value of fps.
-    init();           //initialise first, then display welcome screen
-    welcome();       //wait the player to begin 
-    render();        //start with drawing the first frame.
-    wait(1.0f/fps);  //wait for one frame period
+    int fps = 8;  // declaration of intger value of fps.
+    init();  // initialise first, then display welcome screen
+    welcome();  // wait the player to begin
+    render();  // start with drawing the first frame.
+    wait(1.0f/fps);  // wait for one frame period
 
     while (1) {
-        space.read_input(pad); //Gamepad library reads the positions of the objects.
-        space.update(pad);    // Gamepad library updates the positions of the objects. 
-        render();             
+        space.read_input(pad); // Gamepad library reads the positions of the objects.
+        space.update(pad);  // Gamepad library updates the positions of the objects.
+        render();
         wait(1.0f/fps);
     }
 }
@@ -98,35 +97,42 @@
 // initialies all classes and libraries
 void init()
 {
-    lcd.init(); //intialise the N5110 library .
-    pad.init(); //ntialise the  Gamepad library
-
-
-    space.init(0,10,16,10,0,70,10,1,1,1); // intialise the parameters of space. 
-
+    lcd.init(); // intialise the N5110 library .
+    pad.init(); // ntialise the Gamepad library
+    space.init(0,10,16,10,0,70,10,1,1,1); // intialise the parameters of space.
 }
 
 void render()
 {
-
-    lcd.clear(); //clear the screen
-    space.draw(lcd); //draw the objects in the lcd.
+    lcd.clear(); // clear the screen
+    space.draw(lcd); // draw the objects in the lcd.
     lcd.refresh();  // refresh the screen.
 }
 
 
 void welcome()
 {
-  lcd.clear();
-  
-    lcd.printString("SpaceInvaders!",0,1); //print the title of the game.
-    lcd.printString("  Press Start ",4,4); //print the press start to guide the user to the game. 
-    lcd.clear();                           
+    lcd.clear();
+
+    lcd.printString("SpaceInvaders!",0,1); // print the title of the game.
+    lcd.refresh();
+    wait(1.5);
+
+    lcd.clear();
+    lcd.drawSprite(0,10,48,48,(int *)spaceman); // draw the spaceman to welcom the player.
     lcd.refresh();
-    lcd.printString(" Space is yours!",0,1); //motivation pharse.
-    lcd.drawSprite(10,10,48,48,(int *)spaceman); //draw the spaceman to welcom the player.
+    wait(1.5);
+
+    lcd.clear();
+    lcd.printString(" Space is yours!",0,2); // motivation pharse.
     lcd.refresh();
- 
+    wait(1.5);
+
+    lcd.clear();
+    lcd.printString("  Press Start ",0,1); //print the press start to guide the user to the game.
+    lcd.refresh();
+    wait(1.5);
+
     // wait flashing LEDs until start button is pressed
     while ( pad.check_event(Gamepad::START_PRESSED) == false) {
         pad.leds_on();