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:
- 8:3c15554e6723
- Parent:
- 7:e0cab3e73df9
- Child:
- 9:436b88b70fdd
--- a/main.cpp Wed May 08 19:25:27 2019 +0000
+++ b/main.cpp Wed May 08 22:32:36 2019 +0000
@@ -25,11 +25,54 @@
void render();
void welcome();
void Game1Over();
+void x1_1();
+void x1_2();
+void x2_1();
+void x2_2();
+void x3_1();
+void x3_2();
///////////// gloabal variable ////////////////
bool end = false;
float counter = 1.0;
int score = 0;
int speed = MISSILES_SPEED;
+int i=0;
+int X_1[11][11] = {
+ { 1,1,0,0,0,0,0,0,0,0,0 },
+ { 1,1,1,0,0,0,0,0,0,0,0 },
+ { 0,1,1,1,0,0,0,0,0,0,0 },
+ { 0,0,1,1,1,0,0,0,0,0,0 },
+ { 0,0,0,1,1,1,0,0,0,0,0 },
+ { 0,0,0,0,1,1,1,0,0,0,0 },
+ { 0,0,0,0,0,1,1,1,0,0,0 },
+ { 0,0,0,0,0,0,1,1,1,0,0 },
+ { 0,0,0,0,0,0,0,1,1,1,0 },
+ { 0,0,0,0,0,0,0,0,1,1,1 },
+ { 0,0,0,0,0,0,0,0,0,1,1 },
+ };
+int X_2[11][11] = {
+ { 1,1,0,0,0,0,0,0,0,1,1 },
+ { 1,1,1,0,0,0,0,0,1,1,1 },
+ { 0,1,1,1,0,0,0,1,1,1,0 },
+ { 0,0,1,1,1,0,1,1,1,0,0 },
+ { 0,0,0,1,1,1,1,1,0,0,0 },
+ { 0,0,0,0,1,1,1,0,0,0,0 },
+ { 0,0,0,1,1,1,1,1,0,0,0 },
+ { 0,0,1,1,1,0,1,1,1,0,0 },
+ { 0,1,1,1,0,0,0,1,1,1,0 },
+ { 1,1,1,0,0,0,0,0,1,1,1 },
+ { 1,1,0,0,0,0,0,0,0,1,1 },
+ };
+int invader[8][11] = {
+ { 0,0,1,0,0,0,0,0,1,0,0 },
+ { 0,0,0,1,0,0,0,1,0,0,0 },
+ { 0,0,1,1,1,1,1,1,1,0,0 },
+ { 0,1,1,0,1,1,1,0,1,1,0 },
+ { 1,1,1,1,1,1,1,1,1,1,1 },
+ { 1,0,1,1,1,1,1,1,1,0,1 },
+ { 1,0,1,0,0,0,0,0,1,0,1 },
+ { 0,0,0,1,1,0,1,1,0,0,0 },
+};
///////////// functions ////////////////
int main()
{
@@ -53,6 +96,56 @@
counter = counter + 1/8;
}
lcd.clear();
+ i = 0;
+ while(i < 200) {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_BLACK);
+ lcd.refresh();
+ i++;
+ }
+ lcd.clear();
+ i = 0;
+ while(i < 200) {
+ x1_1();
+ lcd.refresh();
+ pad.tone(1200.0,0.2);
+ i++;
+ }
+ i = 0;
+ while(i < 200) {
+ x1_2();
+ lcd.refresh();
+ pad.tone(1500.0,0.2);
+ i++;
+ }
+ i = 0;
+ while(i < 200) {
+ x2_1();
+ lcd.refresh();
+ pad.tone(1200.0,0.2);
+ i++;
+ }
+ i = 0;
+ while(i < 200) {
+ x2_2();
+ lcd.refresh();
+ pad.tone(1500.0,0.2);
+ i++;
+ }
+ i = 0;
+ while(i < 200) {
+ x3_1();
+ lcd.refresh();
+ pad.tone(1200.0,0.2);
+ i++;
+ }
+ i = 0;
+ while(i < 200) {
+ x3_2();
+ lcd.refresh();
+ pad.tone(1500.0,0.2);
+ i++;
+ }
+ lcd.clear();
Game1Over();
goto start;
}
@@ -81,9 +174,11 @@
// simple splash screen displayed on start-up
void welcome() {
- lcd.printString(" Space ",0,1);
- lcd.printString(" Rebellion! ",0,2);
- lcd.printString("Press Start...",0,4);
+ lcd.printString(" Space ",0,1);
+ lcd.printString(" Rebellion! ",0,2);
+ lcd.printString(" Press Start...",0,4);
+ lcd.drawSprite(8,3,8,11,(int *)invader); //adds spaceinvader into top left corner
+ lcd.drawSprite(WIDTH - 16,3,8,11,(int *)invader); //adds spaceinvader into top right corner
lcd.refresh();
// wait flashing LEDs until start button is pressed
@@ -100,7 +195,9 @@
lcd.printString(" You died! ",0,1);
lcd.printString(" Score =",0,2);
spacerebellion.print_scores(lcd);
- lcd.printString("Press BACK...",0,4);
+ lcd.drawSprite(5,3,11,11,(int *)X_2);
+ lcd.drawSprite(WIDTH - 13,3,11,11,(int *)X_2);
+ lcd.printString(" Press BACK...",0,4);
lcd.refresh();
// wait flashing LEDs until start button is pressed
while ( pad.check_event(Gamepad::BACK_PRESSED) == false) {
@@ -112,3 +209,32 @@
}
+void x1_1() {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawSprite(WIDTH/2 - 27,HEIGHT/2 - 6,11,11,(int *)X_1);
+}
+
+void x1_2() {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawSprite(WIDTH/2 - 27,HEIGHT/2 - 6,11,11,(int *)X_2);
+}
+
+void x2_1() {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawSprite(WIDTH/2 - 6,HEIGHT/2 - 6,11,11,(int *)X_1);
+}
+
+void x2_2() {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawSprite(WIDTH/2 - 6,HEIGHT/2 - 6,11,11,(int *)X_2);
+}
+
+void x3_1() {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawSprite(WIDTH/2 + 15,HEIGHT/2 - 6,11,11,(int *)X_1);
+}
+
+void x3_2() {
+ lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawSprite(WIDTH/2 + 15,HEIGHT/2 - 6,11,11,(int *)X_2);
+}
\ No newline at end of file