el14mw Martin Woodhams 200870391 Elec 2645 project

Dependencies:   N5110 mbed

Files at this revision

API Documentation at this revision

Comitter:
Martin48
Date:
Thu May 05 14:52:21 2016 +0000
Parent:
0:00f0deb0a029
Commit message:
Asteroid game

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 00f0deb0a029 -r 1250fdc01f88 main.cpp
--- a/main.cpp	Thu May 05 13:45:31 2016 +0000
+++ b/main.cpp	Thu May 05 14:52:21 2016 +0000
@@ -39,7 +39,7 @@
     //A Welcome message is displayed
 
     lcd.printString("Welcome to",2,1);
-    lcd.printString("Astroids" ,2,2);
+    lcd.printString("Asteroids" ,2,2);
     lcd.refresh();              //the screen is refreshed to display the message
     wait(2);                    //a small wait so the player can read the message
     lcd.clear();                //clers the message
@@ -56,7 +56,7 @@
         }
         if(g_b1_flag) {
             g_b1_flag = 0;                              //the flag is cleared
-            settings =1;                                //settings variable is increased to 1to allow the settings menu to be accessed 
+            settings =1;                                //settings variable is increased to 1to allow the settings menu to be accessed
             lcd.clear();
         }
 
@@ -65,7 +65,7 @@
             lcd.printString("Inverse mode",2,3);        //prints the options from the settings menu
             lcd.refresh();
 
-            if (g_b2_flag) {                                
+            if (g_b2_flag) {
                 g_b2_flag = 0;                          //resets the flag
                 lcd.normalMode();                       //normal mode is activated
                 settings = 0;                           //the settings is decreased to 0 to exit the loop
@@ -86,7 +86,8 @@
                 updateJoystick();   // the joystick is read
                 lcd.clear();        //the previous screen is cleared
                 game();             //the game function
-                score ++;           //the score is incremented with time
+                score ++;
+                //the score is incremented with time
                 lcd.refresh();      //the screen is refreshed to display the updated settings
             }
             sleep();                //the mbed is put to sleep to try and save power
@@ -383,341 +384,349 @@
                     asteroid[x][1]=4;   //3 gives asteroid type 4
                 }
             }
-        }
+
+
+            switch(asteroid[x][2]) {           //the case is selected based on which direction the asteroid comes from determined by r
+
+
+                case 1:                 //asteroid from top left
+
+                    int flag = 0;
+
+
+                    if (flag == 1) {
+                        flag=0;         //the flag is cleared and bypasses the setting of the array
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) {    //checks to see if there is a collision with the ship
+                        game_over = 1;  //game over is increased to 1 to end the game
+                    }
+
+                    else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=1;
+                        }
+                        asteroid[x][3]=asteroid[x][3]+1;    //asteroids x coordinate increase to move right
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=1;
+                        }
+                        asteroid[x][4]=asteroid[x][4]+1;   //asteroids y coordinates increase to move down
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 2:                 //asteroid from top
+
+
+                    if (flag == 1) {
+                        flag=0;                 //the flag is cleared and the setting of asteroids is bypassed
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) {        //checks to see if the asteroid collides with the ship
+                        game_over = 1;      //if the ship is hit the game over is increased to break the while loop
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=20;
+                        }
+                        asteroid[x][3]=asteroid[x][3];      //moving vertically so x coordinates don't change
 
-        switch(asteroid[x][2]) {           //the case is selected based on which direction the asteroid comes from determined by r
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=1;
+                        }
+                        asteroid[x][4]=asteroid[x][4]+1;    //moving down so y coordinates need to increase
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 3:             //asteroid from top right
+
+
+                    if (flag == 1) {
+                        flag=0;             //the flag is cleared and the setting of asteroids is bypassed
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) { //checks for collisions with the ship
+                        game_over=1;        //game over is increased to one to break the while loop
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=48;
+                        }
+                        asteroid[x][3]=asteroid[x][3]-1;        //asteroid is moving left so the x coordinate decreases
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=1;
+                        }
+                        asteroid[x][4]=asteroid[x][4]+1;        //asteroid is moving from top so the y coordinate increases
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 4:         //asteroid from right
+
+
+                    if (flag == 1) {
+                        flag=0;             //the flag is cleared and astroids being set is bypassed
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>= 24)) {        //checks if the ship has been hit
+                        game_over = 1;       //game_over is increased to 1 to break the while loop
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=48;
+                        }
+                        asteroid[x][3]=asteroid[x][3]-1;        //the x coordinate decreases to move the ship left
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=20;
+                        }
+                        asteroid[x][4]=asteroid[x][4];          // no vertical movement so stays constant
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 5:     //asteroid from down right
 
 
-            case 1:                 //asteroid from top left
+                    if (flag == 1) {
+                        flag=0;                     //flag is cleared and setting of asteroids is bypassed
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) {      //checks if the asteroid has collided with the ship
+                        game_over = 1;      //game_over is increased breaking the while loop and causing the game to end
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=48;
+                        }
+                        asteroid[x][3]=asteroid[x][3]-1;        //x coordinates decrease to move ship left
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=48;
+                        }
+                        asteroid[x][4]=asteroid[x][4]-1;        //y coordinates decrease to move ship up
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 6:     //asteroid from bottom
+
+
+                    if (flag == 1) {
+                        flag=0;             //the flag is cleared and the setting of the asteroids is bypassed
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) {        //checks to see if the ship has been hit
+                        game_over = 1;  //game over is increased to 1 which ends the game
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=20;
+                        }
+                        asteroid[x][3]=asteroid[x][3]; //as no horizontal movement the x coordinates are constant
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=48;
+                        }
+                        asteroid[x][4]=asteroid[x][4]-1;        //the y coordinate decreases to cause the asteroid to move up
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 7:                 //asteroid from bottom left
 
-                int flag = 0;
-                for (int z=0; z<10; z++) {      //loops through the shoot array
-                    if((asteroid[x][3]+8==shoot[z][2]) and (asteroid[x][4]+8==shoot[z][3])) {     //checks to see if the astroid is moving into a bullet
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;    //the flag is raised to show a collision has occured
+                    if (flag == 1) {
+                        flag=0;                 //clears the flag and bypasses the setting of asteroids
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) {      //checks to see if there is a collision with the ship
+                        game_over=1;          //raises game over to 1 to break the while loop
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=1;
+                        }
+                        asteroid[x][3]=asteroid[x][3]+1;        //x coordinates increase to move asteroid right
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=48;
+                        }
+                        asteroid[x][4]=asteroid[x][4]-1;        //y coordinates decrease to move asteroid up
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+
+                case 8:         //asteroid from left
+
+                    if (flag == 1) {
+                        flag=0;             //clears the flag and bypasses the asteroid placement
+                    } else if((asteroid[x][3]<=24)and (asteroid[x][3]+9>= 24) and (asteroid[x][4]<=24) and (asteroid[x][4]+9>=24)) {   //checks to see if the ship has been hit
+                        game_over = 1;      //game over is increased to 1 to break the while loop
+                    } else {
+                        //checks if asteroids x coordinates have been set if not sets them
+                        if(asteroid[x][3]==0) {
+                            asteroid[x][3]=1;
+                        }
+                        asteroid[x][3]=asteroid[x][3]+1;        //x coordinates increase to move ship right
+
+                        //checks if asteroids y coordinates have been set if not sets them
+                        if(asteroid[x][4]==0) {
+                            asteroid[x][4]=20;
+                        }
+                        asteroid[x][4]=asteroid[x][4];      //y coordinates stay constant as there is no vertical movement
+                        for (int z=0; z<8; z++) {
+                            if((asteroid[x][3]<=shoot[z][2])and ((asteroid[x][3]+9)>= shoot[z][2]) and (asteroid[x][4]<=shoot[z][3]) and ((asteroid[x][4]+9)>= shoot[z][3])) { // checks to see if an asteroid collides with a bullet
+                                asteroid[x][0]=0;       //the asteroid number is erased
+                                asteroid[x][1]=0;       //the asteroid type is erased
+                                asteroid[x][2]=0;       //the asteroid direction is erased
+                                asteroid[x][3]=0;       //the asteroids x position is erased
+                                asteroid[x][4]=0;       //the asteroids y positionis erased
+                                shoot[z][0]=0;          //the bullets number is erased
+                                shoot[z][1]=0;          //the bullets direction is erased
+                                shoot[z][2]=0;          //the bullets x coordinate is erased
+                                shoot[z][3]=0;          // the bulets y coordinate is erased
+                                flag = 1;       //the flag is raised
+                            }
+                        }
+                        break;
+                    }
+            }
+
+            //for asteroid type 1 the code loops through the array for asteroid1 and sets the pixels
+            if (asteroid[x][1] == 1) {
+                for (int i = 0; i<9; i++) {
+                    for (int j=0; j<9; j++) {
+                        if (asteroid1[i][j]==1) {
+                            lcd.setPixel(i+asteroid[x][3],j+asteroid[x][4]);
+                        }
+                    }
+                }
+            }
+            //for asteroid type 2 the code loops through the array for asteroid2 and sets the pixels
+            if(asteroid[x][1] == 2) {
+                for (int i = 0; i<8; i++) {
+                    for (int j=0; j<9; j++) {
+                        if (asteroid2[i][j]==1) {
+                            lcd.setPixel(i+ asteroid[x][3],j+asteroid[x][4]);
+                        }
                     }
                 }
 
-                if (flag == 1) {
-                    flag=0;         //the flag is cleared and bypasses the setting of the array
-                } else if((asteroid[x][3]+1==20) and (asteroid[x][4]+1==20)) {    //checks to see if there is a collision with the ship
-                    game_over = 1;  //game over is increased to 1 to end the game
-                }
-
-                else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=1;
-                    }
-                    asteroid[x][3]=asteroid[x][3]+1;    //asteroids x coordinate increase to move right
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=1;
-                    }
-                    asteroid[x][4]=asteroid[x][4]+1;   //asteroids y coordinates increase to move down
-                    break;
-                }
-
-            case 2:                 //asteroid from top
-
-                for (int z=0; z<8; z++) {
-                    if(asteroid[x][4]+8==shoot[z][3]) {        //checks if any bullets share the same y coordinates as the edge of the asteroid
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;               // the flag is raised
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;                 //the flag is cleared and the setting of asteroids is bypassed
-                } else if((asteroid[x][3]==24) and (asteroid[x][4]+1==20)) {        //checks to see if the asteroid collides with the ship
-                    game_over = 1;      //if the ship is hit the game over is increased to break the while loop
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=20;
-                    }
-                    asteroid[x][3]=asteroid[x][3];      //moving vertically so x coordinates don't change
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=1;
+            }
+            //for asteroid type 3 the code loops through the array for asteroid3 and sets the pixels
+            if(asteroid[x][1] == 3) {
+                for (int i = 0; i<9; i++) {
+                    for (int j=0; j<9; j++) {
+                        if (asteroid3[i][j]==1) {
+                            lcd.setPixel(i+ asteroid[x][3],j+asteroid[x][4]);
+                        }
                     }
-                    asteroid[x][4]=asteroid[x][4]+1;    //moving down so y coordinates need to increase
-                    break;
-                }
-
-            case 3:             //asteroid from top right
-
-                for (int z=0; z<8; z++) {
-                    if((asteroid[x][3]+1==shoot[x][2])and (asteroid[x][4]+8==shoot[x][3])) { //checks to see if a bullet has hit the astroid
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;       //the flag is raised to show a collision
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;             //the flag is cleared and the setting of asteroids is bypassed
-                } else if((asteroid[x][3]-1==28) and (asteroid[x][4]+1==20)) { //checks for collisions with the ship
-                    game_over=1;        //game over is increased to one to break the while loop
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=48;
-                    }
-                    asteroid[x][3]=asteroid[x][3]-1;        //asteroid is moving left so the x coordinate decreases
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=1;
-                    }
-                    asteroid[x][4]=asteroid[x][4]+1;        //asteroid is moving from top so the y coordinate increases
-                    break;
-                }
-
-            case 4:         //asteroid from right
-
-                for (int z=0; z<8; z++) {
-                    if(asteroid[x][3]-1 == shoot[z][2]) { // checks to see if an asteroid collides with a bullet
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;       //the flag is raised
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;             //the flag is cleared and astroids being set is bypassed
-                } else if((asteroid[x][3]-1==28) and (asteroid[x][4]==24)) {        //checks if the ship has been hit
-                    game_over = 1;       //game_over is increased to 1 to break the while loop
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=48;
-                    }
-                    asteroid[x][3]=asteroid[x][3]-1;        //the x coordinate decreases to move the ship left
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=20;
-                    }
-                    asteroid[x][4]=asteroid[x][4];          // no vertical movement so stays constant
-                    break;
                 }
 
-            case 5:     //asteroid from down right
-
-                for (int z=0; z<8; z++) {
-                    if((asteroid[x][3]-1==shoot[x][2])and(asteroid[x][4]-1==shoot[x][3])) {      //sees if a bullet has hit the asteroid
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;               //flag is set
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;                     //flag is cleared and setting of asteroids is bypassed
-                } else if((asteroid[x][3]-1==28) and (asteroid[x][4]-1==28)) {      //checks if the asteroid has collided with the ship
-                    game_over = 1;      //game_over is increased breaking the while loop and causing the game to end
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=48;
-                    }
-                    asteroid[x][3]=asteroid[x][3]-1;        //x coordinates decrease to move ship left
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=48;
-                    }
-                    asteroid[x][4]=asteroid[x][4]-1;        //y coordinates decrease to move ship up
-                    break;
-                }
-
-            case 6:     //asteroid from bottom
-
-                for (int z=0; z<8; z++) {
-                    if(asteroid[x][4]-1==shoot[z][3]) {     //checks to see if the bullet has hit an asteroid
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;               //the flag is raised
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;             //the flag is cleared and the setting of the asteroids is bypassed
-                } else if((asteroid[x][3]==24) and (asteroid[x][4]-1==28)) {        //checks to see if the ship has been hit
-                    game_over = 1;  //game over is increased to 1 which ends the game
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=20;
-                    }
-                    asteroid[x][3]=asteroid[x][3]; //as no horizontal movement the x coordinates are constant
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=48;
-                    }
-                    asteroid[x][4]=asteroid[x][4]-1;        //the y coordinate decreases to cause the asteroid to move up
-                    break;
-                }
-
-            case 7:                 //asteroid from bottom left
-                for (int z=0; z<8; z++) {
-                    if((asteroid[x][3]+8==shoot[z][2])and (asteroid[x][4]-1==shoot[z][3] )) {       //checks to see if theres a collision
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;               //raises the flag
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;                 //clears the flag and bypasses the setting of asteroids
-                } else if((asteroid[x][3]+1==20) and (asteroid[x][4]-1==28)) {      //checks to see if there is a collision with the ship
-                    game_over=1;          //raises game over to 1 to break the while loop
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=1;
-                    }
-                    asteroid[x][3]=asteroid[x][3]+1;        //x coordinates increase to move asteroid right
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=48;
-                    }
-                    asteroid[x][4]=asteroid[x][4]-1;        //y coordinates decrease to move asteroid up
-                    break;
-                }
-
-            case 8:         //asteroid from left
-                for (int z=0; z<8; z++) {
-                    if(asteroid[x][3]+9==shoot[z][2]) {     //checks to see if there has been a collision
-                        asteroid[x][0]=0;       //the asteroid number is erased
-                        asteroid[x][1]=0;       //the asteroid type is erased
-                        asteroid[x][2]=0;       //the asteroid direction is erased
-                        asteroid[x][3]=0;       //the asteroids x position is erased
-                        asteroid[x][4]=0;       //the asteroids y positionis erased
-                        shoot[z][0]=0;          //the bullets number is erased
-                        shoot[z][1]=0;          //the bullets direction is erased
-                        shoot[z][2]=0;          //the bullets x coordinate is erased
-                        shoot[z][3]=0;          // the bulets y coordinate is erased
-                        flag = 1;               //raises the flag
-                    }
-                }
-                if (flag == 1) {
-                    flag=0;             //clears the flag and bypasses the asteroid placement
-                } else if((asteroid[x][3]+1==20) and (asteroid[x][4]==24)) {   //checks to see if the ship has been hit
-                    game_over = 1;      //game over is increased to 1 to break the while loop
-                } else {
-                    //checks if asteroids x coordinates have been set if not sets them
-                    if(asteroid[x][3]==0) {
-                        asteroid[x][3]=1;
-                    }
-                    asteroid[x][3]=asteroid[x][3]+1;        //x coordinates increase to move ship right
-
-                    //checks if asteroids y coordinates have been set if not sets them
-                    if(asteroid[x][4]==0) {
-                        asteroid[x][4]=20;
-                    }
-                    asteroid[x][4]=asteroid[x][4];      //y coordinates stay constant as there is no vertical movement
-                    break;
-                }
-        }
-
-        //for asteroid type 1 the code loops through the array for asteroid1 and sets the pixels
-        if (asteroid[x][1] == 1) {
-            for (int i = 0; i<9; i++) {
-                for (int j=0; j<9; j++) {
-                    if (asteroid1[i][j]==1) {
-                        lcd.setPixel(i+asteroid[x][3],j+asteroid[x][4]);
+            }
+            //for asteroid type 4 the code loops through the array for asteroid4 and sets the pixels
+            if(asteroid[x][1] == 4) {
+                for (int i = 0; i<9; i++) {
+                    for (int j=0; j<9; j++) {
+                        if (asteroid4[i][j]==1) {
+                            lcd.setPixel(i+ asteroid[x][3],j+asteroid[x][4]);
+                        }
                     }
                 }
             }
         }
-        //for asteroid type 2 the code loops through the array for asteroid2 and sets the pixels
-        if(asteroid[x][1] == 2) {
-            for (int i = 0; i<8; i++) {
-                for (int j=0; j<9; j++) {
-                    if (asteroid2[i][j]==1) {
-                        lcd.setPixel(i+ asteroid[x][3],j+asteroid[x][4]);
-                    }
-                }
-            }
 
-        }
-        //for asteroid type 3 the code loops through the array for asteroid3 and sets the pixels
-        if(asteroid[x][1] == 3) {
-            for (int i = 0; i<9; i++) {
-                for (int j=0; j<9; j++) {
-                    if (asteroid3[i][j]==1) {
-                        lcd.setPixel(i+ asteroid[x][3],j+asteroid[x][4]);
-                    }
-                }
-            }
-
-        }
-        //for asteroid type 4 the code loops through the array for asteroid4 and sets the pixels
-        if(asteroid[x][1] == 4) {
-            for (int i = 0; i<9; i++) {
-                for (int j=0; j<9; j++) {
-                    if (asteroid4[i][j]==1) {
-                        lcd.setPixel(i+ asteroid[x][3],j+asteroid[x][4]);
-                    }
-                }
-            }
-        }
     }
 
 }
-
-
 void game()
 {
 
@@ -748,11 +757,10 @@
     }
 
 //loops through coloumn 48 to draw a line to make the playing area square
-    for (int j = 0;
-            j < WIDTH;
-            j++) {
+    for (int j = 0;j < WIDTH;j++) {
         lcd.setPixel(48,j);
     }
+    lcd.drawRect(48,0,35,47,1); 
     // set shipDirection of current state (use dot syntax to access struct members)
     shipDirection = fsm[state].shipDirection;
     // set the next state depending on direction
@@ -891,4 +899,16 @@
 
         }
     }
-}
\ No newline at end of file
+}
+//void checkAsteroid()
+//{
+//    for (int x = 0; x<8; x++) {            //loops through each row of the shoot array
+//        if ((asteroid[x][3] == 0)or(asteroid[x][4] == 0)or(asteroid[x][3] == 48) or(asteroid[x][4] == 48)) {            //checks the 4 orders
+//            asteroid[x][0]=0;  //bullet_number is erased
+//            asteroid[x][1]=0;  //shipDirection is erased
+//            asteroid[x][2]=0;  //bullet x coordinate is erased
+//            asteroid[x][3]=0;  //bullet y coordinate is erased
+//            asteroid[x][4]=0;
+//        }
+//    }
+//}
\ No newline at end of file