Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

Committer:
thestudent
Date:
Thu May 07 08:58:21 2020 +0000
Revision:
16:e2aaef863d7c
Parent:
15:3f558f8b54ea
Child:
17:cb208b15be5c
Game design finished;

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"
eencae 0:b7f1f47bb26a 19
eencae 0:b7f1f47bb26a 20
eencae 0:b7f1f47bb26a 21 // objects
eencae 0:b7f1f47bb26a 22 Gamepad pad;
eencae 0:b7f1f47bb26a 23 N5110 lcd;
thestudent 16:e2aaef863d7c 24
thestudent 16:e2aaef863d7c 25
thestudent 2:ee6a6bcbce87 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 16:e2aaef863d7c 33 bool game_playing = false;
thestudent 10:f5b920a6a71a 34
thestudent 11:4722bf70b2be 35
eencae 0:b7f1f47bb26a 36 int main()
eencae 0:b7f1f47bb26a 37 {
thestudent 2:ee6a6bcbce87 38 initialise();
thestudent 16:e2aaef863d7c 39 while(1) {
thestudent 16:e2aaef863d7c 40 //create the game
thestudent 16:e2aaef863d7c 41 game();
thestudent 2:ee6a6bcbce87 42 }
thestudent 2:ee6a6bcbce87 43 }
thestudent 2:ee6a6bcbce87 44
thestudent 6:33bdb54c2c88 45 void initialise()
thestudent 6:33bdb54c2c88 46 {
thestudent 2:ee6a6bcbce87 47 pad.init();//initialises the gamepad
thestudent 2:ee6a6bcbce87 48 lcd.init();//initialises the N5100 screen
thestudent 11:4722bf70b2be 49 lcd.clear();
thestudent 6:33bdb54c2c88 50
eencae 0:b7f1f47bb26a 51 }
eencae 0:b7f1f47bb26a 52
thestudent 16:e2aaef863d7c 53 void game()
thestudent 16:e2aaef863d7c 54 {
thestudent 16:e2aaef863d7c 55
thestudent 16:e2aaef863d7c 56 Objects objects;
thestudent 16:e2aaef863d7c 57 Functions functions;
thestudent 16:e2aaef863d7c 58 while(game_check == false) {
thestudent 16:e2aaef863d7c 59 lcd.clear();
thestudent 16:e2aaef863d7c 60
thestudent 16:e2aaef863d7c 61 objects.draw_shots(lcd,pad, true);// draws the shot
thestudent 16:e2aaef863d7c 62 //creates the balls and clears the shots
thestudent 16:e2aaef863d7c 63 functions.ball_creater_linear(lcd, objects, pad);
thestudent 16:e2aaef863d7c 64 functions.ball_creater_parabolic(lcd,objects,pad);
thestudent 16:e2aaef863d7c 65 objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen
thestudent 16:e2aaef863d7c 66 functions.collision_checker(lcd,objects);//cheks for the collisions
thestudent 16:e2aaef863d7c 67
thestudent 16:e2aaef863d7c 68 objects.draw_base(lcd);//draws the base of the game
thestudent 16:e2aaef863d7c 69 objects.cannon_position(pad);//changes the cannon postion
thestudent 16:e2aaef863d7c 70 objects.draw_cannon(lcd);//draws the cannon
thestudent 16:e2aaef863d7c 71 game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball
thestudent 16:e2aaef863d7c 72 lcd.refresh();
thestudent 16:e2aaef863d7c 73 wait(0.15);
thestudent 16:e2aaef863d7c 74
thestudent 16:e2aaef863d7c 75 lcd.clear();
thestudent 16:e2aaef863d7c 76 //added this so the cannon moves faster than the balls
thestudent 16:e2aaef863d7c 77 objects.cannon_position(pad);//eveluates the cannon position
thestudent 16:e2aaef863d7c 78 objects.draw_cannon(lcd);//draws the cannon
thestudent 16:e2aaef863d7c 79 lcd.refresh();
thestudent 16:e2aaef863d7c 80 wait(0.005);
thestudent 16:e2aaef863d7c 81 }
thestudent 16:e2aaef863d7c 82 //prints the the score and game over and the continue option
thestudent 16:e2aaef863d7c 83 lcd.printString("Game over!", 15,2);
thestudent 16:e2aaef863d7c 84 char buf_score[4];
thestudent 16:e2aaef863d7c 85 sprintf(buf_score,"%d",functions.get_score());
thestudent 16:e2aaef863d7c 86 lcd.printString("Score:",0,0);
thestudent 16:e2aaef863d7c 87 lcd.printString(buf_score,36,0);
thestudent 16:e2aaef863d7c 88 lcd.refresh();
thestudent 16:e2aaef863d7c 89 wait(2);
thestudent 16:e2aaef863d7c 90 game_check = false;
thestudent 16:e2aaef863d7c 91 }