Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

Committer:
thestudent
Date:
Sat May 09 08:19:00 2020 +0000
Revision:
18:8f7291885e19
Parent:
17:cb208b15be5c
Child:
19:913d123554ee
Commit before changing few things in the main file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thestudent 6:33bdb54c2c88 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
thestudent 1:664a272ab028 7 Name:Arturs Kolovskis
thestudent 1:664a272ab028 8 Username:el18ak
thestudent 1:664a272ab028 9 Student ID Number: 201253737
thestudent 1:664a272ab028 10 Date:08.03.2020
eencae 0:b7f1f47bb26a 11 */
eencae 0:b7f1f47bb26a 12
eencae 0:b7f1f47bb26a 13 // includes
eencae 0:b7f1f47bb26a 14 #include "mbed.h"
eencae 0:b7f1f47bb26a 15 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 16 #include "N5110.h"
thestudent 2:ee6a6bcbce87 17 #include "Objects.h"
thestudent 6:33bdb54c2c88 18 #include "Functions.h"
thestudent 17:cb208b15be5c 19 #include "Menu.h"
eencae 0:b7f1f47bb26a 20
eencae 0:b7f1f47bb26a 21
eencae 0:b7f1f47bb26a 22 // objects
eencae 0:b7f1f47bb26a 23 Gamepad pad;
eencae 0:b7f1f47bb26a 24 N5110 lcd;
thestudent 17:cb208b15be5c 25 Menu menu(lcd,pad);
thestudent 16:e2aaef863d7c 26
thestudent 16:e2aaef863d7c 27
thestudent 2:ee6a6bcbce87 28
thestudent 2:ee6a6bcbce87 29 //functions
thestudent 2:ee6a6bcbce87 30 void initialise();
thestudent 16:e2aaef863d7c 31 void game();
eencae 0:b7f1f47bb26a 32
thestudent 18:8f7291885e19 33
thestudent 10:f5b920a6a71a 34 //variables
thestudent 10:f5b920a6a71a 35 bool game_check = false;
thestudent 16:e2aaef863d7c 36 bool game_playing = false;
thestudent 10:f5b920a6a71a 37
thestudent 11:4722bf70b2be 38
eencae 0:b7f1f47bb26a 39 int main()
eencae 0:b7f1f47bb26a 40 {
thestudent 2:ee6a6bcbce87 41 initialise();
thestudent 17:cb208b15be5c 42 menu.first_screen();
thestudent 16:e2aaef863d7c 43 while(1) {
thestudent 18:8f7291885e19 44 //menu
thestudent 18:8f7291885e19 45 menu.menu_screen();
thestudent 16:e2aaef863d7c 46 //create the game
thestudent 16:e2aaef863d7c 47 game();
thestudent 2:ee6a6bcbce87 48 }
thestudent 2:ee6a6bcbce87 49 }
thestudent 2:ee6a6bcbce87 50
thestudent 6:33bdb54c2c88 51 void initialise()
thestudent 6:33bdb54c2c88 52 {
thestudent 2:ee6a6bcbce87 53 pad.init();//initialises the gamepad
thestudent 18:8f7291885e19 54 lcd.init();//initialises the N5110 screen
thestudent 11:4722bf70b2be 55 lcd.clear();
thestudent 6:33bdb54c2c88 56
eencae 0:b7f1f47bb26a 57 }
eencae 0:b7f1f47bb26a 58
thestudent 16:e2aaef863d7c 59 void game()
thestudent 16:e2aaef863d7c 60 {
thestudent 16:e2aaef863d7c 61
thestudent 16:e2aaef863d7c 62 Objects objects;
thestudent 16:e2aaef863d7c 63 Functions functions;
thestudent 16:e2aaef863d7c 64 while(game_check == false) {
thestudent 18:8f7291885e19 65
thestudent 16:e2aaef863d7c 66 lcd.clear();
thestudent 16:e2aaef863d7c 67
thestudent 16:e2aaef863d7c 68 objects.draw_shots(lcd,pad, true);// draws the shot
thestudent 16:e2aaef863d7c 69 //creates the balls and clears the shots
thestudent 16:e2aaef863d7c 70 functions.ball_creater_linear(lcd, objects, pad);
thestudent 16:e2aaef863d7c 71 functions.ball_creater_parabolic(lcd,objects,pad);
thestudent 16:e2aaef863d7c 72 objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen
thestudent 16:e2aaef863d7c 73 functions.collision_checker(lcd,objects);//cheks for the collisions
thestudent 16:e2aaef863d7c 74
thestudent 16:e2aaef863d7c 75 objects.draw_base(lcd);//draws the base of the game
thestudent 16:e2aaef863d7c 76 objects.cannon_position(pad);//changes the cannon postion
thestudent 16:e2aaef863d7c 77 objects.draw_cannon(lcd);//draws the cannon
thestudent 16:e2aaef863d7c 78 game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball
thestudent 16:e2aaef863d7c 79 lcd.refresh();
thestudent 16:e2aaef863d7c 80 wait(0.15);
thestudent 16:e2aaef863d7c 81
thestudent 16:e2aaef863d7c 82 lcd.clear();
thestudent 16:e2aaef863d7c 83 //added this so the cannon moves faster than the balls
thestudent 16:e2aaef863d7c 84 objects.cannon_position(pad);//eveluates the cannon position
thestudent 16:e2aaef863d7c 85 objects.draw_cannon(lcd);//draws the cannon
thestudent 16:e2aaef863d7c 86 lcd.refresh();
thestudent 16:e2aaef863d7c 87 wait(0.005);
thestudent 16:e2aaef863d7c 88 }
thestudent 16:e2aaef863d7c 89 //prints the the score and game over and the continue option
thestudent 16:e2aaef863d7c 90 lcd.printString("Game over!", 15,2);
thestudent 16:e2aaef863d7c 91 char buf_score[4];
thestudent 16:e2aaef863d7c 92 sprintf(buf_score,"%d",functions.get_score());
thestudent 16:e2aaef863d7c 93 lcd.printString("Score:",0,0);
thestudent 16:e2aaef863d7c 94 lcd.printString(buf_score,36,0);
thestudent 16:e2aaef863d7c 95 lcd.refresh();
thestudent 16:e2aaef863d7c 96 wait(2);
thestudent 16:e2aaef863d7c 97 game_check = false;
thestudent 16:e2aaef863d7c 98 }