Updated Space Invaders on the mbed. Improved upon Michael Son's "Mbed Space Invaders" at https://os.mbed.com/users/michaeljson/notebook/mbed-space-invaders/.

Dependencies:   mbed wave_player mbed-rtos 4DGL-uLCD-SE SparkfunAnalogJoystick SDFileSystem LSM9DS1_Library_cal_updated

Fork of Two-PlayerSpaceInvaders by William Minix

test

Revision:
21:a6b4c5598083
Parent:
20:ede4fa57d082
Child:
22:a907eeb128a4
--- a/player.cpp	Sun Apr 25 03:13:50 2021 +0000
+++ b/player.cpp	Sun Apr 25 04:04:31 2021 +0000
@@ -4,33 +4,50 @@
 #define GREEN 0x00FF00
 #define BLUE 0x0000FF
 #define PINK 0xFFC0CB
+#define PURPLE 0x800080
 #define YELLOW 0xFFFF00
-#define BROWN  0xD2691E
-#define DIRT   BROWN
-void draw_img(int u, int v, const char* img)
+// Modified from the RPG Game from ECE 2035. Draw more complex player object (with changing color).
+void draw_img(int u, int v, int width, int height, const char* img)
 {
-    int colors[11*11];
-    for (int i = 0; i < 11*11; i++)
+    int colors[width*height];
+    for (int i = 0; i < width*height; i++)
     {
-        if (img[i] == 'R') colors[i] = RED;
+        if (img[i] == 'G') colors[i] = GREEN;
+        else if (img[i] == 'B') colors[i] = BLUE;
+        else if (img[i] == 'P') colors[i] = PINK;
+        else if (img[i] == 'U') colors[i] = PURPLE;
         else if (img[i] == 'Y') colors[i] = YELLOW;
-        else if (img[i] == 'G') colors[i] = GREEN;
-        else if (img[i] == 'D') colors[i] = DIRT;
-        else if (img[i] == '5') colors[i] = LGREY;
-        else if (img[i] == '3') colors[i] = DGREY;
-        else if (img[i] == 'W') colors[i] = WHITE;
-        else if (img[i] == 'U') colors[i] = BLUE;
         else colors[i] = BLACK;
     }
-    uLCD.BLIT(u, v, 11, 11, colors);
+    uLCD.BLIT(u, v, width, height, colors);
     wait_us(250); // Recovery time!
 }
 
 void draw_player_object(int blk_x, int blk_y, int player_color, int p_width, int p_height)
 {
+    char* colors;
     //uLCD.filled_rectangle(blk_x,blk_y,blk_x+p_width,blk_y+p_height,player_color);
-    const int* colors = [
-    uLCD.BLIT(blk_x, blk_y, e_width, e_height, 
+    if (player_color == GREEN) {
+        colors = "000000G00000000000GGG0000000000GGG000000GGGGGGGGGGG0GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG";
+    } else if (player_color == BLUE) {
+        colors = "000000B00000000000BBB0000000000BBB000000BBBBBBBBBBB0BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
+    } else if (player_color == PINK) {
+        colors = "000000P00000000000PPP0000000000PPP000000PPPPPPPPPPP0PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP";
+    } else if (player_color == PURPLE) {
+        colors = "000000U00000000000UUU0000000000UUU000000UUUUUUUUUUU0UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
+    } else {
+        colors = "000000Y00000000000YYY0000000000YYY000000YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
+    }
+         
+/*         "000000G000000
+         00000GGG00000
+         00000GGG00000
+         0GGGGGGGGGGG0
+         GGGGGGGGGGGGG
+         GGGGGGGGGGGGG
+         GGGGGGGGGGGGG
+         GGGGGGGGGGGGG    */
+    draw_img(blk_x, blk_y, p_width, p_height, colors);
 }
 
 void erase_player(int blk_x, int blk_y, int p_width, int p_height)
@@ -43,8 +60,10 @@
     g->player_blk_x = blk_x;
     g->player_blk_y = blk_y;
     g->player_color = 0x00FF00;
+    //g->player_height = 8;
+    //g->player_width = 8;
     g->player_height = 8;
-    g->player_width = 8;
+    g->player_width = 13;
     g->status = PLAYER_ALIVE;
 }