Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@17:cb208b15be5c, 2020-05-07 (annotated)
- Committer:
- thestudent
- Date:
- Thu May 07 10:36:39 2020 +0000
- Revision:
- 17:cb208b15be5c
- Parent:
- 16:e2aaef863d7c
- Child:
- 18:8f7291885e19
The initial screen is working. The ball movement on it has to be corrected.
Who changed what in which revision?
User | Revision | Line number | New 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 | 10:f5b920a6a71a | 33 | //variables |
thestudent | 10:f5b920a6a71a | 34 | bool game_check = false; |
thestudent | 16:e2aaef863d7c | 35 | bool game_playing = false; |
thestudent | 10:f5b920a6a71a | 36 | |
thestudent | 11:4722bf70b2be | 37 | |
eencae | 0:b7f1f47bb26a | 38 | int main() |
eencae | 0:b7f1f47bb26a | 39 | { |
thestudent | 2:ee6a6bcbce87 | 40 | initialise(); |
thestudent | 17:cb208b15be5c | 41 | menu.first_screen(); |
thestudent | 16:e2aaef863d7c | 42 | while(1) { |
thestudent | 16:e2aaef863d7c | 43 | //create the game |
thestudent | 16:e2aaef863d7c | 44 | game(); |
thestudent | 2:ee6a6bcbce87 | 45 | } |
thestudent | 2:ee6a6bcbce87 | 46 | } |
thestudent | 2:ee6a6bcbce87 | 47 | |
thestudent | 6:33bdb54c2c88 | 48 | void initialise() |
thestudent | 6:33bdb54c2c88 | 49 | { |
thestudent | 2:ee6a6bcbce87 | 50 | pad.init();//initialises the gamepad |
thestudent | 2:ee6a6bcbce87 | 51 | lcd.init();//initialises the N5100 screen |
thestudent | 11:4722bf70b2be | 52 | lcd.clear(); |
thestudent | 6:33bdb54c2c88 | 53 | |
eencae | 0:b7f1f47bb26a | 54 | } |
eencae | 0:b7f1f47bb26a | 55 | |
thestudent | 16:e2aaef863d7c | 56 | void game() |
thestudent | 16:e2aaef863d7c | 57 | { |
thestudent | 16:e2aaef863d7c | 58 | |
thestudent | 16:e2aaef863d7c | 59 | Objects objects; |
thestudent | 16:e2aaef863d7c | 60 | Functions functions; |
thestudent | 16:e2aaef863d7c | 61 | while(game_check == false) { |
thestudent | 16:e2aaef863d7c | 62 | lcd.clear(); |
thestudent | 16:e2aaef863d7c | 63 | |
thestudent | 16:e2aaef863d7c | 64 | objects.draw_shots(lcd,pad, true);// draws the shot |
thestudent | 16:e2aaef863d7c | 65 | //creates the balls and clears the shots |
thestudent | 16:e2aaef863d7c | 66 | functions.ball_creater_linear(lcd, objects, pad); |
thestudent | 16:e2aaef863d7c | 67 | functions.ball_creater_parabolic(lcd,objects,pad); |
thestudent | 16:e2aaef863d7c | 68 | objects.draw_shots(lcd,pad, true);//again draws the shots so they would be visible on the screen |
thestudent | 16:e2aaef863d7c | 69 | functions.collision_checker(lcd,objects);//cheks for the collisions |
thestudent | 16:e2aaef863d7c | 70 | |
thestudent | 16:e2aaef863d7c | 71 | objects.draw_base(lcd);//draws the base of the game |
thestudent | 16:e2aaef863d7c | 72 | objects.cannon_position(pad);//changes the cannon postion |
thestudent | 16:e2aaef863d7c | 73 | objects.draw_cannon(lcd);//draws the cannon |
thestudent | 16:e2aaef863d7c | 74 | game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball |
thestudent | 16:e2aaef863d7c | 75 | lcd.refresh(); |
thestudent | 16:e2aaef863d7c | 76 | wait(0.15); |
thestudent | 16:e2aaef863d7c | 77 | |
thestudent | 16:e2aaef863d7c | 78 | lcd.clear(); |
thestudent | 16:e2aaef863d7c | 79 | //added this so the cannon moves faster than the balls |
thestudent | 16:e2aaef863d7c | 80 | objects.cannon_position(pad);//eveluates the cannon position |
thestudent | 16:e2aaef863d7c | 81 | objects.draw_cannon(lcd);//draws the cannon |
thestudent | 16:e2aaef863d7c | 82 | lcd.refresh(); |
thestudent | 16:e2aaef863d7c | 83 | wait(0.005); |
thestudent | 16:e2aaef863d7c | 84 | } |
thestudent | 16:e2aaef863d7c | 85 | //prints the the score and game over and the continue option |
thestudent | 16:e2aaef863d7c | 86 | lcd.printString("Game over!", 15,2); |
thestudent | 16:e2aaef863d7c | 87 | char buf_score[4]; |
thestudent | 16:e2aaef863d7c | 88 | sprintf(buf_score,"%d",functions.get_score()); |
thestudent | 16:e2aaef863d7c | 89 | lcd.printString("Score:",0,0); |
thestudent | 16:e2aaef863d7c | 90 | lcd.printString(buf_score,36,0); |
thestudent | 16:e2aaef863d7c | 91 | lcd.refresh(); |
thestudent | 16:e2aaef863d7c | 92 | wait(2); |
thestudent | 16:e2aaef863d7c | 93 | game_check = false; |
thestudent | 16:e2aaef863d7c | 94 | } |