Kaif Kutchwala 201267448 ELEC2645 Project
Dependencies: mbed
main.cpp
- Committer:
- KaifK
- Date:
- 2020-04-27
- Revision:
- 3:f86c1cf90d0d
- Parent:
- 2:21973e665a32
- Child:
- 4:08a0ff6668df
File content as of revision 3:f86c1cf90d0d:
/* Stay Home Stay Safe ELEC2645 Project EL18KK 201267448 */ #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "Ball.h" #include "Splash.h" Gamepad pad; N5110 lcd; const int baall[3][11][15] = { {{0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0}, {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0}, {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0}, {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, {0,1,1,0,0,1,1,1,1,1,0,0,1,1,0}, {0,1,0,0,0,0,1,1,1,0,0,0,0,1,0}, {0,0,1,0,0,0,0,1,0,0,0,0,1,0,0}, {0,0,0,1,1,0,1,1,1,0,1,1,0,0,0}, {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}}, {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, {0,0,0,0,1,0,0,1,0,0,1,0,0,0,0}, {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0}, {0,0,1,1,1,1,1,1,1,1,1,1,1,0,0}, {0,0,1,1,0,0,1,1,1,0,0,1,1,0,0}, {0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}, {0,0,0,0,1,0,1,1,1,0,1,0,0,0,0}, {0,0,0,0,0,1,1,1,1,1,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}, {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0}, {0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0}, {0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0}, {0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0}, {0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0}, }; int grass1[2][7][7] = { {{0,0,0,0,0,0,0}, {0,0,0,0,0,0,0}, {0,0,1,0,0,0,0}, {0,0,1,0,1,0,0}, {0,1,0,1,0,1,0}, {0,1,0,1,0,1,0}, {1,0,1,0,0,0,1}}, {{1,1,1,1,1,1,1}, {0,0,0,0,0,0,0}, {0,0,1,0,0,0,0}, {0,0,1,0,1,0,0}, {0,1,0,1,0,1,0}, {0,1,0,1,0,1,0}, {1,0,1,0,0,0,1},}, }; int grass2[3][3] = { {1,0,1}, {0,1,0}, {1,1,1}, }; int initial_pos = WIDTH/2; int dir =1 ; int dirr =1; int aim_line = WIDTH/2; int _user_input_x = 40; int _user_input_y = 12; int _ball_x = 35; int _ball_y = 43; int j = 0; int k = 0; int sizex = 11; int sizey = 15; char sprite = 'b'; Ball ball; Splash splashscreen; int main() { lcd.init(); lcd.setContrast(0.5); pad.init(); lcd.backLightOn(); splashscreen.displayInfo(lcd); splashscreen.playIntro(lcd,ball); while(1) { ball.init(lcd); lcd.drawLine(WIDTH/2,41,aim_line,24,2); lcd.drawSprite(7,0,24,70,(int *)goal); lcd.drawSprite(1,17,7,7,(int *)grass1[0]); lcd.drawSprite(76,17,7,7,(int *)grass1[1]); lcd.drawSprite(67,26,3,3,(int *)grass2); lcd.drawSprite(67,26,3,3,(int *)grass2); lcd.drawSprite(16,30,3,3,(int *)grass2); lcd.drawSprite(6,35,3,3,(int *)grass2); lcd.drawSprite(72,32,3,3,(int *)grass2); lcd.drawSprite(69,43,3,3,(int *)grass2); lcd.drawSprite(12,45,3,3,(int *)grass2); lcd.drawSprite(32,34,3,3,(int *)grass2); Vector2D joystick = pad.get_mapped_coord(); float ballx = WIDTH/2 - 7; float bally = 43; lcd.drawLine(0,24,84,24,1); lcd.drawLine(WIDTH/2-5,41,initial_pos,HEIGHT/2+7,1); lcd.drawLine(WIDTH/2+5,41,initial_pos,HEIGHT/2+7,1); lcd.drawLine(WIDTH/2+5,41,WIDTH/2-5,41,1); lcd.printString("Score",0,5); aim_line += dir; initial_pos += dirr; if(initial_pos >84) { dirr = -1; } if ( initial_pos < 0) { dirr = 1; } if (aim_line > 84) { dir = -1; } if ( aim_line < 0) { dir = 1;} if(pad.A_pressed()){ wait(0.2); ball.playShot(70,12,lcd); } //printf("done"); wait_ms(100); lcd.refresh(); lcd.clear(); } }