Final Submission. I have read and agreed with Statement of Academic Integrity.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 5:a33d791bd7fb
- Parent:
- 4:8b75386f68ef
- Child:
- 6:65c01b46fc88
--- a/main.cpp Fri Jun 05 10:37:47 2020 +0000 +++ b/main.cpp Fri Jun 05 12:08:30 2020 +0000 @@ -2,6 +2,7 @@ #include "mbed.h" #include "Gamepad.h" #include "N5110.h" +#include "PortalEngine.h" //Objects Gamepad pad; @@ -130,7 +131,7 @@ void collision_detection(int); void erase_old_sprites(char,char); void jump(); -void portal_angle(); +void get_portal_angle(); void place_portal_1(); void place_portal_2(); //Main function @@ -143,7 +144,6 @@ update_display(); //Loop runs forever while(endgame == false){ - //portal_angle(); get_move(move, pad); collision_detection(move); if(pad.A_pressed() == 1){ @@ -151,14 +151,11 @@ } else if(pad.B_pressed() == 1){ place_portal_1(); - portal_1_xpos = aim_xpos; - portal_1_ypos = aim_ypos; - array[portal_1_xpos][portal_1_ypos] = 'P';} + } + else if(pad.Y_pressed() == 1){ place_portal_2(); - portal_2_xpos = aim_xpos; - portal_2_ypos = aim_ypos; - array[portal_2_xpos][portal_2_ypos] = 'Q';} + } else apply_move(); add_player_array(); @@ -220,32 +217,15 @@ } }} - //portal_angle(); - lcd.setPixel(player_xpos-1,player_ypos-1, true); - lcd.setPixel(player_xpos-2,player_ypos-2, true); + get_portal_angle(); + lcd.setPixel(player_xpos,player_ypos-1, true); + lcd.setPixel(player_xpos-1,player_ypos-2, true); + lcd.setPixel(player_xpos-1,player_ypos-3, true); lcd.setPixel(player_xpos-2,player_ypos-3, true); - lcd.setPixel(player_xpos-2,player_ypos-4, true); - lcd.setPixel(player_xpos-2,player_ypos-5, true); - lcd.setPixel(player_xpos-1,player_ypos-5, true); - lcd.setPixel(player_xpos-1,player_ypos-6, true); - lcd.setPixel(player_xpos-1,player_ypos-7, true); - lcd.setPixel(player_xpos-1,player_ypos-8, true); - lcd.setPixel(player_xpos-2,player_ypos-9, true); - lcd.setPixel(player_xpos-3,player_ypos-9, true); - lcd.setPixel(player_xpos-3,player_ypos-10, true); - lcd.setPixel(player_xpos-4,player_ypos-9, true); - lcd.setPixel(player_xpos-5,player_ypos-8, true); - lcd.setPixel(player_xpos-5,player_ypos-7, true); - lcd.setPixel(player_xpos-5,player_ypos-6, true); - lcd.setPixel(player_xpos-5,player_ypos-5, true); - lcd.setPixel(player_xpos-4,player_ypos-5, true); - lcd.setPixel(player_xpos-4,player_ypos-4, true); - lcd.setPixel(player_xpos-4,player_ypos-3, true); - lcd.setPixel(player_xpos-4,player_ypos-2, true); - lcd.setPixel(player_xpos-5,player_ypos-1, true); - lcd.setPixel(player_xpos-6,player_ypos, true); - lcd.setPixel(player_xpos-3,player_ypos-7, true); - lcd.setPixel(player_xpos-3,player_ypos-3, true); + lcd.setPixel(player_xpos,player_ypos-3, true); + lcd.setPixel(player_xpos-1,player_ypos-4, true); + lcd.setPixel(player_xpos-2,player_ypos-1, true); + lcd.setPixel(player_xpos-2,player_ypos, true); } @@ -300,33 +280,37 @@ if(array[player_xpos-1][player_ypos] == '4' && dir == W){ move = 0;} if(array[player_xpos+1][player_ypos] == 'P' || array[player_xpos-1][player_ypos] == 'P' || array[player_xpos][player_ypos-1] == 'P' || array[player_xpos][player_ypos+1] == 'P' ){ - if (array[portal_2_xpos+1][portal_2_ypos] == '3' || array[portal_2_xpos-1][portal_2_ypos] == '3'){ + move = 0; + array[player_xpos][player_ypos] = '0'; + if (array[portal_2_xpos-1][portal_2_ypos] == '3'){ player_xpos = portal_2_xpos; - player_ypos = portal_2_ypos+1;} - else if(array[portal_2_xpos+1][portal_2_ypos] == '2' || array[portal_2_xpos-1][portal_2_ypos] == '2'){ + player_ypos = portal_2_ypos+2;} + else if(array[portal_2_xpos-1][portal_2_ypos] == '2'){ player_xpos = portal_2_xpos + 1; player_ypos = portal_2_ypos-1;} - else if(array[portal_2_xpos][portal_2_ypos-1] == '1' || array[portal_2_xpos][portal_2_ypos+1] == '1'){ - player_xpos = portal_2_xpos - 1; + else if(array[portal_2_xpos][portal_2_ypos + 1] == '1'){ + player_xpos = portal_2_xpos - 2; player_ypos = portal_2_ypos;} - else if(array[portal_2_xpos][portal_2_ypos-1] == '4' || array[portal_2_xpos][portal_2_ypos+1] == '4'){ - player_xpos = portal_2_xpos + 1; + else if(array[portal_2_xpos][portal_2_ypos+ 1] == '4'){ + player_xpos = portal_2_xpos + 2; player_ypos = portal_2_ypos;} } - if(array[player_xpos+1][player_ypos] == 'Q' || array[player_xpos-1][player_ypos] == 'Q' || array[player_xpos][player_ypos-1] == 'Q' || array[player_xpos][player_ypos+1] == 'Q') { - if (array[portal_1_xpos+1][portal_1_ypos] == '3' || array[portal_1_xpos-1][portal_1_ypos] == '3'){ + if(array[player_xpos+1][player_ypos] == 'Q' || array[player_xpos-1][player_ypos] == 'Q' || array[player_xpos][player_ypos-1] == 'Q' || array[player_xpos][player_ypos+1] == 'Q' ){ + move = 0; + array[player_xpos][player_ypos] = '0'; + if (array[portal_1_xpos-1][portal_1_ypos] == '3'){ player_xpos = portal_1_xpos; - player_ypos = portal_1_ypos+1;} - else if(array[portal_1_xpos+1][portal_1_ypos] == '2' || array[portal_1_xpos-1][portal_1_ypos] == '2'){ + player_ypos = portal_1_ypos+2;} + else if(array[portal_1_xpos-1][portal_1_ypos] == '2'){ player_xpos = portal_1_xpos + 1; player_ypos = portal_1_ypos-1;} - else if(array[portal_1_xpos][portal_1_ypos-1] == '1' || array[portal_1_xpos][portal_1_ypos+1] == '1'){ - player_xpos = portal_1_xpos - 1; + else if(array[portal_1_xpos][portal_1_ypos + 1] == '1'){ + player_xpos = portal_1_xpos - 2; player_ypos = portal_1_ypos;} - else if(array[portal_1_xpos][portal_1_ypos-1] == '4' || array[portal_1_xpos][portal_1_ypos+1] == '4'){ - player_xpos = portal_1_xpos + 1; - player_ypos = portal_1_ypos;} - } + else if(array[portal_1_xpos][portal_1_ypos+ 1] == '4'){ + player_xpos = portal_1_xpos + 2; + player_ypos = portal_1_ypos;} + } @@ -373,14 +357,14 @@ aim_xpos = player_xpos; aim_ypos = player_ypos; if(angle_input > 0 && angle_input < 0.125){ - while(array[aim_xpos][aim_ypos + 1] != '1' || array[aim_xpos][aim_ypos + 1] != '2' || array[aim_xpos][aim_ypos + 1] != '3' || array[aim_xpos][aim_ypos + 1] != '4' ){ + while(array[aim_xpos][aim_ypos + 1] == '0'){ aim_ypos = player_ypos + 1; } aim_ypos = player_ypos + 1; } else if(angle_input > 0.125 && angle_input < 0.25){ - while(array[aim_xpos -1 ][aim_ypos + 1] != '1' || array[aim_xpos -1 ][aim_ypos + 1] != '2' || array[aim_xpos -1 ][aim_ypos + 1] != '3' || array[aim_xpos -1 ][aim_ypos + 1] != '4'){ + while(array[aim_xpos -1 ][aim_ypos + 1] == '0'){ aim_xpos += - 1; aim_ypos += 1; } @@ -388,13 +372,13 @@ aim_ypos += 1; } else if(angle_input > 0.25 && angle_input < 0.375){ - while(array[aim_xpos -1 ][aim_ypos] != '1' || array[aim_xpos -1 ][aim_ypos] != '2' || array[aim_xpos -1 ][aim_ypos] != '3' || array[aim_xpos -1 ][aim_ypos] != '4'){ + while(array[aim_xpos -1 ][aim_ypos] == '0'){ aim_xpos += - 1; } aim_xpos += - 1; } else if(angle_input > 0.375 && angle_input < 0.5){ - while(array[aim_xpos -1 ][aim_ypos-1] != '1' || array[aim_xpos -1 ][aim_ypos-1] != '2' || array[aim_xpos -1 ][aim_ypos-1] != '3' || array[aim_xpos -1 ][aim_ypos-1] != '4'){ + while(array[aim_xpos -1 ][aim_ypos-1] == '0'){ aim_xpos += - 1; aim_ypos += - 1; } @@ -402,13 +386,13 @@ aim_ypos += -1; } else if(angle_input > 0.5 && angle_input < 0.625){ - while(array[aim_xpos][aim_ypos-1] != '1' || array[aim_xpos][aim_ypos-1] != '2' || array[aim_xpos][aim_ypos-1] != '3' || array[aim_xpos][aim_ypos-1] != '4'){ + while(array[aim_xpos][aim_ypos-1] == '0'){ aim_ypos += - 1; } aim_ypos += -1; } else if(angle_input > 0.625 && angle_input < 0.75){ - while(array[aim_xpos+1][aim_ypos-1] != '1' || array[aim_xpos+1][aim_ypos-1] != '2' || array[aim_xpos+1][aim_ypos-1] != '3' || array[aim_xpos+1][aim_ypos-1] != '4'){ + while(array[aim_xpos+1][aim_ypos-1] == '0'){ aim_ypos += - 1; aim_xpos += 1; } @@ -416,13 +400,13 @@ aim_xpos += 1; } else if(angle_input > 0.75 && angle_input < 0.875){ - while(array[aim_xpos+1][aim_ypos] != '1' || array[aim_xpos+1][aim_ypos] != '2' || array[aim_xpos+1][aim_ypos] != '3' || array[aim_xpos+1][aim_ypos] != '4'){ + while(array[aim_xpos+1][aim_ypos] == '0'){ aim_xpos += 1; } aim_xpos += 1; } else if(angle_input > 0.875 && angle_input < 1){ - while(array[aim_xpos+1][aim_ypos + 1] != '1' || array[aim_xpos+1][aim_ypos + 1] != '2' || array[aim_xpos+1][aim_ypos + 1] != '3' || array[aim_xpos+1][aim_ypos + 1] != '4'){ + while(array[aim_xpos+1][aim_ypos + 1] == '0'){ aim_xpos += 1; aim_ypos += 1; } @@ -440,7 +424,10 @@ int old_p1_xpos = portal_1_xpos; int old_p1_ypos = portal_1_ypos; array[old_p1_xpos][old_p1_ypos] = '1'; - } + portal_1_xpos = aim_xpos; + portal_1_ypos = aim_ypos; + array[portal_1_xpos][portal_1_ypos] = 'P';} + void place_portal_2() {