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:
- 5:476696df08dd
- Parent:
- 4:13cc179c11c5
- Child:
- 8:eec0d7fc365f
--- a/main.cpp	Fri Apr 12 14:00:51 2019 +0000
+++ b/main.cpp	Sun Apr 14 14:29:05 2019 +0000
@@ -1,3 +1,4 @@
+
 ///////// pre-processor directives ////////
 #include "mbed.h"
 #include "Gamepad.h"
@@ -7,19 +8,23 @@
 # include "tests.h"
 #endif
 
-#define PADDLE_WIDTH 2
-#define PADDLE_HEIGHT 8
-#define BALL_SIZE 2
-#define BALL_SPEED 3
+//#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 ///////////////
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
+
 //Direction _d;
 //SpaceEngine space;
 ///////////// prototypes ///////////////
@@ -27,6 +32,7 @@
 void update_game(UserInput input);
 void render();
 void welcome();
+/*
 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 },
@@ -40,7 +46,7 @@
     { 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 },
@@ -75,9 +81,24 @@
     {0,0,0,0,0,0,0,1,0,0,0,0},
     {0,0,0,0,0,0,0,1,0,0,0,0},
    
-    
     };
 */
+
+
+
+const int space_ship[10][12]={
+{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,0,0,0,0,0,0,0},
+{0,1,1,1,1,1,1,1,0,0,0,0},
+{0,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,0,0,0,0},
+{0,0,0,1,1,0,0,0,0,0,0,0},
+{0,0,0,1,1,0,0,0,0,0,0,0},
+
+};
 Direction _d2;
 ///////////// functions ////////////////
 int main()
@@ -107,11 +128,13 @@
     int y_alien=10;
     int x_alien=70;
     int bullet_fired=0;
+     int x_space_ship=0;
+    int y_space_ship=40;
     // game loop - read input, update the game state and render the display
     while (1) {
         lcd.clear();
-        lcd.drawSprite(0,y,12,10,(int *)run);
-        
+        //lcd.drawSprite(0,y,12,10,(int *)run);
+        lcd.drawSprite(0,y,12,10,(int *)space_ship);
         lcd.drawSprite(x_alien,y_alien,12,10,(int *)alien);
         lcd.drawSprite(x_bullet,y_bullet,4,10,(int *)bullet);
         //space.read_input(pad);
@@ -138,8 +161,10 @@
             x_bullet+=4;
             if(x_bullet>=x_alien && y_bullet >=y_alien && y_bullet <=y_alien+10)
                 y=0;
+                if (x_bullet == x_alien && y_bullet ==y_alien)
+                score ++;
         wait(1.0f/fps);
-        
+        lcd.clear ();
         lcd.refresh();
     }
 }