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.
Dependencies: mbed
main.cpp@14:fe2e16cdf219, 2019-04-17 (annotated)
- Committer:
- el17mcd
- Date:
- Wed Apr 17 17:24:02 2019 +0000
- Revision:
- 14:fe2e16cdf219
- Parent:
- 13:feadff02d3f7
- Child:
- 15:fa5282fcd134
! Game now includes randomised wind that changes every turn. A bar at the top of the screen shows the severity of the wind in the x direction. Dot reticle added to show where the projectile is aimed.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| el17mcd | 2:8382613c86a0 | 1 | /* | 
| el17mcd | 2:8382613c86a0 | 2 | ELEC2645 Embedded Systems Project | 
| el17mcd | 2:8382613c86a0 | 3 | School of Electronic & Electrical Engineering | 
| el17mcd | 2:8382613c86a0 | 4 | University of Leeds | 
| el17mcd | 2:8382613c86a0 | 5 | Name: Maxim C. Delacoe | 
| el17mcd | 2:8382613c86a0 | 6 | Username: EL 17 MCD | 
| el17mcd | 2:8382613c86a0 | 7 | Student ID Number: 2011 58344 | 
| el17mcd | 2:8382613c86a0 | 8 | Date: 19/03/2019 | 
| el17mcd | 2:8382613c86a0 | 9 | */ | 
| el17mcd | 2:8382613c86a0 | 10 | ///////// pre-processor directives //////// | 
| el17mcd | 2:8382613c86a0 | 11 | #include "mbed.h" | 
| el17mcd | 2:8382613c86a0 | 12 | #include "Gamepad.h" | 
| el17mcd | 2:8382613c86a0 | 13 | #include "N5110.h" | 
| el17mcd | 2:8382613c86a0 | 14 | #include "Bitmap.h" | 
| el17mcd | 12:9e6d5d0a0c82 | 15 | #include "Tank.h" | 
| el17mcd | 7:a3ccabdebe2e | 16 | #include "TanksEngine.h" | 
| el17mcd | 7:a3ccabdebe2e | 17 | #include "Projectile.h" | 
| el17mcd | 12:9e6d5d0a0c82 | 18 | #include "Graphics.h" | 
| el17mcd | 8:d4e419dad90f | 19 | #define PI 3.14159265 | 
| el17mcd | 8:d4e419dad90f | 20 | #define DEG2PI 0.0174532925 | 
| el17mcd | 2:8382613c86a0 | 21 | |
| el17mcd | 10:d4fb12e9e7cd | 22 | #include <cmath> | 
| el17mcd | 10:d4fb12e9e7cd | 23 | |
| el17mcd | 7:a3ccabdebe2e | 24 | #ifdef WITH_TESTING | 
| el17mcd | 2:8382613c86a0 | 25 | |
| el17mcd | 7:a3ccabdebe2e | 26 | #endif | 
| el17mcd | 7:a3ccabdebe2e | 27 | |
| el17mcd | 7:a3ccabdebe2e | 28 | /////////////// objects /////////////// | 
| el17mcd | 7:a3ccabdebe2e | 29 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); | 
| el17mcd | 7:a3ccabdebe2e | 30 | TanksEngine engine; | 
| el17mcd | 11:4e2eb64031a0 | 31 | Gamepad pad; | 
| el17mcd | 12:9e6d5d0a0c82 | 32 | Graphics graphics; | 
| el17mcd | 7:a3ccabdebe2e | 33 | |
| el17mcd | 2:8382613c86a0 | 34 | void welcome() | 
| el17mcd | 2:8382613c86a0 | 35 | { | 
| el17mcd | 2:8382613c86a0 | 36 | lcd.clear(); | 
| el17mcd | 2:8382613c86a0 | 37 | lcd.printString(" ELEC 2645",0,0); | 
| el17mcd | 2:8382613c86a0 | 38 | lcd.printString(" Game ",0,1); | 
| el17mcd | 2:8382613c86a0 | 39 | lcd.printString(" Project",0,2); | 
| el17mcd | 2:8382613c86a0 | 40 | lcd.printString("Max C. Delacoe",0,4); | 
| el17mcd | 2:8382613c86a0 | 41 | lcd.printString(" 2011 58344",0,5); | 
| el17mcd | 2:8382613c86a0 | 42 | lcd.refresh(); | 
| el17mcd | 2:8382613c86a0 | 43 | wait(0.2); | 
| el17mcd | 2:8382613c86a0 | 44 | } | 
| el17mcd | 2:8382613c86a0 | 45 | |
| el17mcd | 2:8382613c86a0 | 46 | int main() | 
| el17mcd | 2:8382613c86a0 | 47 | { | 
| el17mcd | 2:8382613c86a0 | 48 | lcd.init(); | 
| el17mcd | 11:4e2eb64031a0 | 49 | pad.init(); | 
| el17mcd | 11:4e2eb64031a0 | 50 | engine.initgame(); | 
| el17mcd | 11:4e2eb64031a0 | 51 | int fps = 60; | 
| el17mcd | 11:4e2eb64031a0 | 52 | float frame_period_ms = 1000/fps; | 
| el17mcd | 13:feadff02d3f7 | 53 | pad.led(3,1) ; | 
| el17mcd | 13:feadff02d3f7 | 54 | pad.led(4,0.5) ; | 
| el17mcd | 13:feadff02d3f7 | 55 | pad.led(5,0.25) ; | 
| el17mcd | 10:d4fb12e9e7cd | 56 | |
| el17mcd | 3:087b28bf8b96 | 57 | // welcome(); // display welcome message | 
| el17mcd | 2:8382613c86a0 | 58 | |
| el17mcd | 5:8a2e96f7fb4d | 59 | while(1) { // infinite loop | 
| el17mcd | 11:4e2eb64031a0 | 60 | |
| el17mcd | 12:9e6d5d0a0c82 | 61 | lcd.clear(); | 
| el17mcd | 13:feadff02d3f7 | 62 | engine.read_input(pad); | 
| el17mcd | 14:fe2e16cdf219 | 63 | graphics.draw_parkinson_map(lcd); | 
| el17mcd | 11:4e2eb64031a0 | 64 | if (engine.get_turn() == 1) { | 
| el17mcd | 13:feadff02d3f7 | 65 | engine.left_tank_turn(graphics, pad); | 
| el17mcd | 12:9e6d5d0a0c82 | 66 | } else if (engine.get_turn() == 2 || engine.get_turn() == 4) { | 
| el17mcd | 13:feadff02d3f7 | 67 | engine.projectile_phase(lcd); | 
| el17mcd | 12:9e6d5d0a0c82 | 68 | } else if (engine.get_turn() == 3) { | 
| el17mcd | 13:feadff02d3f7 | 69 | engine.right_tank_turn(graphics, pad); } | 
| el17mcd | 13:feadff02d3f7 | 70 | engine.end(); | 
| el17mcd | 12:9e6d5d0a0c82 | 71 | if (engine.get_turn() == 5) { | 
| el17mcd | 12:9e6d5d0a0c82 | 72 | while (1) { | 
| el17mcd | 12:9e6d5d0a0c82 | 73 | lcd.clear(); | 
| el17mcd | 12:9e6d5d0a0c82 | 74 | engine.render(graphics, lcd); | 
| el17mcd | 12:9e6d5d0a0c82 | 75 | lcd.refresh(); | 
| el17mcd | 12:9e6d5d0a0c82 | 76 | } | 
| el17mcd | 13:feadff02d3f7 | 77 | } | 
| el17mcd | 12:9e6d5d0a0c82 | 78 | engine.render(graphics, lcd); | 
| el17mcd | 8:d4e419dad90f | 79 | lcd.refresh(); | 
| el17mcd | 12:9e6d5d0a0c82 | 80 | wait_ms(frame_period_ms); | 
| el17mcd | 8:d4e419dad90f | 81 | } | 
| el17mcd | 11:4e2eb64031a0 | 82 | /* | 
| el17mcd | 8:d4e419dad90f | 83 | lcd.clear(); | 
| el17mcd | 8:d4e419dad90f | 84 | lcd.printString("DONE",0,1); | 
| el17mcd | 8:d4e419dad90f | 85 | lcd.refresh(); | 
| el17mcd | 11:4e2eb64031a0 | 86 | wait(10);*/ | 
| el17mcd | 8:d4e419dad90f | 87 | } |