Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

Committer:
thestudent
Date:
Thu May 21 17:49:49 2020 +0000
Revision:
27:da17a102c8d0
Parent:
24:74a53dd49806
Child:
28:b6f048f46ffb
Small changes to documentation and code

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 2:ee6a6bcbce87 27 //functions
thestudent 2:ee6a6bcbce87 28 void initialise();
thestudent 16:e2aaef863d7c 29 void game();
eencae 0:b7f1f47bb26a 30
thestudent 10:f5b920a6a71a 31 //variables
thestudent 10:f5b920a6a71a 32 bool game_check = false;
thestudent 19:913d123554ee 33 int pause_return_value = 0;
thestudent 19:913d123554ee 34 int game_return_value = 2;
thestudent 19:913d123554ee 35 string game_speed;
thestudent 21:32429d8e90ff 36 float extra_speed = 0.05;
thestudent 11:4722bf70b2be 37
eencae 0:b7f1f47bb26a 38 int main()
eencae 0:b7f1f47bb26a 39 {
thestudent 2:ee6a6bcbce87 40 initialise();
thestudent 21:32429d8e90ff 41 //creates the inital screen
thestudent 17:cb208b15be5c 42 menu.first_screen();
thestudent 21:32429d8e90ff 43 //infinite game and menu loop
thestudent 16:e2aaef863d7c 44 while(1) {
thestudent 18:8f7291885e19 45 //menu
thestudent 18:8f7291885e19 46 menu.menu_screen();
thestudent 21:32429d8e90ff 47 //checks the game speed setting
thestudent 19:913d123554ee 48 game_speed = menu.get_game_speed();
thestudent 19:913d123554ee 49 if (game_speed == "fast"){
thestudent 19:913d123554ee 50 extra_speed = 0.0f;
thestudent 19:913d123554ee 51 }else{
thestudent 19:913d123554ee 52 //decreasesn the speed
thestudent 19:913d123554ee 53 extra_speed = 0.05f;
thestudent 19:913d123554ee 54 }
thestudent 16:e2aaef863d7c 55 //create the game
thestudent 16:e2aaef863d7c 56 game();
thestudent 2:ee6a6bcbce87 57 }
thestudent 2:ee6a6bcbce87 58 }
thestudent 2:ee6a6bcbce87 59
thestudent 6:33bdb54c2c88 60 void initialise()
thestudent 6:33bdb54c2c88 61 {
thestudent 2:ee6a6bcbce87 62 pad.init();//initialises the gamepad
thestudent 18:8f7291885e19 63 lcd.init();//initialises the N5110 screen
thestudent 11:4722bf70b2be 64 lcd.clear();
eencae 0:b7f1f47bb26a 65 }
eencae 0:b7f1f47bb26a 66
thestudent 16:e2aaef863d7c 67 void game()
thestudent 16:e2aaef863d7c 68 {
thestudent 21:32429d8e90ff 69 //creates class objects
thestudent 16:e2aaef863d7c 70 Objects objects;
thestudent 16:e2aaef863d7c 71 Functions functions;
thestudent 21:32429d8e90ff 72
thestudent 21:32429d8e90ff 73 //runs the game engine
thestudent 16:e2aaef863d7c 74 while(game_check == false) {
thestudent 19:913d123554ee 75
thestudent 16:e2aaef863d7c 76 lcd.clear();
thestudent 16:e2aaef863d7c 77 objects.draw_shots(lcd,pad, true);// draws the shot
thestudent 21:32429d8e90ff 78
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 21:32429d8e90ff 82
thestudent 16:e2aaef863d7c 83 objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen
thestudent 24:74a53dd49806 84 functions.collision_checker(lcd,objects,pad);//cheks for the collisions
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 27:da17a102c8d0 90 wait(0.1f + extra_speed);
thestudent 16:e2aaef863d7c 91
thestudent 21:32429d8e90ff 92 //added this so the cannon moves faster than the balls
thestudent 16:e2aaef863d7c 93 lcd.clear();
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 21:32429d8e90ff 99 //if a pressed display pause screen
thestudent 22:f1811602a817 100 pause_return_value = menu.pause_screen(functions.get_score());
thestudent 19:913d123554ee 101 if(pause_return_value == 1) {
thestudent 19:913d123554ee 102 break;
thestudent 19:913d123554ee 103 }
thestudent 16:e2aaef863d7c 104 }
thestudent 21:32429d8e90ff 105
thestudent 19:913d123554ee 106 if(pause_return_value == 0) {
thestudent 19:913d123554ee 107 //prints the the score and game over
thestudent 19:913d123554ee 108 game_return_value = menu.game_over_screen(functions.get_score());
thestudent 19:913d123554ee 109 if (game_return_value == 2) {
thestudent 19:913d123554ee 110 game_check = false;
thestudent 19:913d123554ee 111 }
thestudent 22:f1811602a817 112 }
thestudent 16:e2aaef863d7c 113 }