Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

Committer:
thestudent
Date:
Sat May 09 10:09:35 2020 +0000
Revision:
19:913d123554ee
Parent:
18:8f7291885e19
Child:
21:32429d8e90ff
The entire design finished. Need to revise ball creation;

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 19:913d123554ee 37 int pause_return_value = 0;
thestudent 19:913d123554ee 38 int game_return_value = 2;
thestudent 19:913d123554ee 39 string game_speed;
thestudent 19:913d123554ee 40 float extra_speed = 0.5;
thestudent 11:4722bf70b2be 41
eencae 0:b7f1f47bb26a 42 int main()
eencae 0:b7f1f47bb26a 43 {
thestudent 2:ee6a6bcbce87 44 initialise();
thestudent 17:cb208b15be5c 45 menu.first_screen();
thestudent 16:e2aaef863d7c 46 while(1) {
thestudent 18:8f7291885e19 47 //menu
thestudent 18:8f7291885e19 48 menu.menu_screen();
thestudent 19:913d123554ee 49 game_speed = menu.get_game_speed();
thestudent 19:913d123554ee 50 if (game_speed == "fast"){
thestudent 19:913d123554ee 51 extra_speed = 0.0f;
thestudent 19:913d123554ee 52 }else{
thestudent 19:913d123554ee 53 //decreasesn the speed
thestudent 19:913d123554ee 54 extra_speed = 0.05f;
thestudent 19:913d123554ee 55 }
thestudent 16:e2aaef863d7c 56 //create the game
thestudent 16:e2aaef863d7c 57 game();
thestudent 2:ee6a6bcbce87 58 }
thestudent 2:ee6a6bcbce87 59 }
thestudent 2:ee6a6bcbce87 60
thestudent 6:33bdb54c2c88 61 void initialise()
thestudent 6:33bdb54c2c88 62 {
thestudent 2:ee6a6bcbce87 63 pad.init();//initialises the gamepad
thestudent 18:8f7291885e19 64 lcd.init();//initialises the N5110 screen
thestudent 11:4722bf70b2be 65 lcd.clear();
thestudent 6:33bdb54c2c88 66
eencae 0:b7f1f47bb26a 67 }
eencae 0:b7f1f47bb26a 68
thestudent 16:e2aaef863d7c 69 void game()
thestudent 16:e2aaef863d7c 70 {
thestudent 19:913d123554ee 71
thestudent 16:e2aaef863d7c 72 Objects objects;
thestudent 16:e2aaef863d7c 73 Functions functions;
thestudent 16:e2aaef863d7c 74 while(game_check == false) {
thestudent 19:913d123554ee 75
thestudent 16:e2aaef863d7c 76 lcd.clear();
thestudent 16:e2aaef863d7c 77
thestudent 16:e2aaef863d7c 78 objects.draw_shots(lcd,pad, true);// draws the shot
thestudent 16:e2aaef863d7c 79 //creates the balls and clears the shots
thestudent 16:e2aaef863d7c 80 functions.ball_creater_linear(lcd, objects, pad);
thestudent 16:e2aaef863d7c 81 functions.ball_creater_parabolic(lcd,objects,pad);
thestudent 16:e2aaef863d7c 82 objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen
thestudent 16:e2aaef863d7c 83 functions.collision_checker(lcd,objects);//cheks for the collisions
thestudent 16:e2aaef863d7c 84
thestudent 16:e2aaef863d7c 85 objects.draw_base(lcd);//draws the base of the game
thestudent 16:e2aaef863d7c 86 objects.cannon_position(pad);//changes the cannon postion
thestudent 16:e2aaef863d7c 87 objects.draw_cannon(lcd);//draws the cannon
thestudent 16:e2aaef863d7c 88 game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball
thestudent 16:e2aaef863d7c 89 lcd.refresh();
thestudent 19:913d123554ee 90 wait(0.1 + extra_speed);
thestudent 16:e2aaef863d7c 91
thestudent 16:e2aaef863d7c 92 lcd.clear();
thestudent 16:e2aaef863d7c 93 //added this so the cannon moves faster than the balls
thestudent 16:e2aaef863d7c 94 objects.cannon_position(pad);//eveluates the cannon position
thestudent 16:e2aaef863d7c 95 objects.draw_cannon(lcd);//draws the cannon
thestudent 16:e2aaef863d7c 96 lcd.refresh();
thestudent 16:e2aaef863d7c 97 wait(0.005);
thestudent 19:913d123554ee 98
thestudent 19:913d123554ee 99 pause_return_value = menu.pause_screen();
thestudent 19:913d123554ee 100 if(pause_return_value == 1) {
thestudent 19:913d123554ee 101 break;
thestudent 19:913d123554ee 102 }
thestudent 16:e2aaef863d7c 103 }
thestudent 19:913d123554ee 104 if(pause_return_value == 0) {
thestudent 19:913d123554ee 105 //prints the the score and game over
thestudent 19:913d123554ee 106 game_return_value = menu.game_over_screen(functions.get_score());
thestudent 19:913d123554ee 107 if (game_return_value == 2) {
thestudent 19:913d123554ee 108 game_check = false;
thestudent 19:913d123554ee 109 }
thestudent 19:913d123554ee 110 }
thestudent 19:913d123554ee 111
thestudent 16:e2aaef863d7c 112 }