Final Submission. I have read and agreed with Statement of Academic Integrity.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:2e2134c27c23
- Parent:
- 2:586409836de7
- Child:
- 4:8b75386f68ef
--- a/main.cpp Fri May 29 21:15:42 2020 +0000 +++ b/main.cpp Wed Jun 03 16:22:43 2020 +0000 @@ -9,13 +9,13 @@ char player_char = 'x'; int player_xpos = 1; -int player_ypos = 45; +int player_ypos = 46; int portal_1_xpos = 30; -int portal_1_ypos = 45; +int portal_1_ypos = 46; int portal_2_xpos = 60; -int portal_2_ypos = 45; +int portal_2_ypos = 46; char array[84][48]; int move = 0; @@ -41,11 +41,11 @@ void spawn_portal_2(); void erase_old_sprites(char,char); void jump(); +void portal_angle(); //Main function int main() { - wait_ms(50); pad_init(); array_init(); add_surface_array(); @@ -71,8 +71,8 @@ } void array_init(){ - for(int j = 0; j < 47; j++){ - for(int i = 0; i < 83; i++){ + for(int j = 0; j < 48; j++){ + for(int i = 0; i < 84; i++){ array[i][j] = '0'; }}} @@ -92,8 +92,8 @@ void print_screen(){ - for(int j = 0; j < 47; j++){ - for(int i = 0; i < 83; i++){ + for(int j = 0; j < 48; j++){ + for(int i = 0; i < 84; i++){ if (array[i][j] == '0'){ lcd.setPixel(i,j,false); @@ -109,6 +109,8 @@ lcd.setPixel(i,j, false); } }} + + portal_angle(); } @@ -117,7 +119,7 @@ //Prototype functions void pad_init(){ lcd.init(); - lcd.setContrast(0.6); + lcd.setContrast(0.45); lcd.clear(); pad.init(); } @@ -125,8 +127,18 @@ void add_surface_array() { for(int i = 0; i < 84; i++){ - array[i][46] = '1'; + array[i][47] = '1'; + } + for(int i = 0; i < 84; i++){ + array[i][0] = '1'; } + for(int i = 0; i < 48; i++){ + array[0][i] = '1'; + } + for(int i = 0; i < 48; i++){ + array[83][i] = '1'; + } + } void add_player_array() @@ -191,26 +203,26 @@ void spawn_object() { - array[10][45] = '1'; + array[10][46] = '1'; + array[11][46] = '1'; array[11][45] = '1'; - array[11][44] = '1'; + array[30][45] = '1'; array[30][44] = '1'; - array[30][43] = '1'; + array[31][45] = '1'; array[31][44] = '1'; - array[31][43] = '1'; - array[31][45] = '1'; + array[31][46] = '1'; + array[60][45] = '1'; array[60][44] = '1'; - array[60][43] = '1'; + array[59][45] = '1'; array[59][44] = '1'; - array[59][43] = '1'; - array[59][45] = '1'; + array[59][46] = '1'; } void spawn_portal_1() { @@ -231,4 +243,49 @@ } -//////////////////code so far has movement, surface and portal detection and relevant behaviours. \ No newline at end of file +//////////////////code so far has movement, surface and portal detection and relevant behaviours. +// next steps are to turn pot into degrees and make a function which chechks which pixel the pot is pointing at. + +void portal_angle() +{ + double angle_input = pad.read_pot2(); + float gradient = tan(angle_input*360); + int aim_xpos = player_xpos; + int aim_ypos = player_ypos; + double aim_yposs = player_ypos; + if(angle_input > 0.25 && angle_input < 0.5){ + while(array[aim_xpos -1 ][aim_ypos - 1] != '1'){ + aim_xpos += - 1; + aim_yposs+= - gradient; + aim_ypos = aim_yposs; + }} + else if(angle_input > 0 && angle_input < 0.25){ + while(array[aim_xpos -1 ][aim_ypos + 1] != '1'){ + aim_xpos += - 1; + aim_yposs+= gradient/2; + aim_ypos = aim_yposs; + }} + else if(angle_input > 0.75 && angle_input < 1){ + while(array[aim_xpos +1 ][aim_ypos + 1] != '1'){ + aim_xpos += 1; + aim_yposs+= gradient/3; + aim_ypos = aim_yposs; + }} + else if(angle_input > 0.5 && angle_input < 0.75){ + while(array[aim_xpos +1 ][aim_ypos - 1] != '1'){ + aim_xpos += 1; + aim_yposs+= - gradient/4; + aim_ypos = aim_yposs; + }} + lcd.drawLine(player_xpos,player_ypos, aim_xpos,aim_ypos,1); + lcd.refresh(); + } + + + + + + + + + \ No newline at end of file