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@8:d4e419dad90f, 2019-04-10 (annotated)
- Committer:
- el17mcd
- Date:
- Wed Apr 10 11:33:10 2019 +0000
- Revision:
- 8:d4e419dad90f
- Parent:
- 7:a3ccabdebe2e
- Child:
- 9:fe912235dd71
Working ballistic model prototype for projectile with visual feedback on LCD.
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 | 7:a3ccabdebe2e | 15 | #include "TankL.h" |
| el17mcd | 7:a3ccabdebe2e | 16 | #include "TanksEngine.h" |
| el17mcd | 7:a3ccabdebe2e | 17 | #include "Projectile.h" |
| el17mcd | 8:d4e419dad90f | 18 | #define PI 3.14159265 |
| el17mcd | 8:d4e419dad90f | 19 | #define DEG2PI 0.0174532925 |
| el17mcd | 2:8382613c86a0 | 20 | |
| el17mcd | 7:a3ccabdebe2e | 21 | #ifdef WITH_TESTING |
| el17mcd | 2:8382613c86a0 | 22 | |
| el17mcd | 7:a3ccabdebe2e | 23 | #endif |
| el17mcd | 7:a3ccabdebe2e | 24 | |
| el17mcd | 7:a3ccabdebe2e | 25 | /////////////// objects /////////////// |
| el17mcd | 7:a3ccabdebe2e | 26 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17mcd | 7:a3ccabdebe2e | 27 | TankL tankl; |
| el17mcd | 7:a3ccabdebe2e | 28 | Projectile proj; |
| el17mcd | 7:a3ccabdebe2e | 29 | TanksEngine engine; |
| el17mcd | 7:a3ccabdebe2e | 30 | |
| el17mcd | 2:8382613c86a0 | 31 | void welcome() |
| el17mcd | 2:8382613c86a0 | 32 | { |
| el17mcd | 2:8382613c86a0 | 33 | lcd.clear(); |
| el17mcd | 2:8382613c86a0 | 34 | lcd.printString(" ELEC 2645",0,0); |
| el17mcd | 2:8382613c86a0 | 35 | lcd.printString(" Game ",0,1); |
| el17mcd | 2:8382613c86a0 | 36 | lcd.printString(" Project",0,2); |
| el17mcd | 2:8382613c86a0 | 37 | lcd.printString("Max C. Delacoe",0,4); |
| el17mcd | 2:8382613c86a0 | 38 | lcd.printString(" 2011 58344",0,5); |
| el17mcd | 2:8382613c86a0 | 39 | lcd.refresh(); |
| el17mcd | 2:8382613c86a0 | 40 | wait(0.2); |
| el17mcd | 2:8382613c86a0 | 41 | } |
| el17mcd | 2:8382613c86a0 | 42 | |
| el17mcd | 2:8382613c86a0 | 43 | int main() |
| el17mcd | 2:8382613c86a0 | 44 | { |
| el17mcd | 2:8382613c86a0 | 45 | lcd.init(); |
| el17mcd | 8:d4e419dad90f | 46 | int p_pos_x = 0; |
| el17mcd | 8:d4e419dad90f | 47 | int p_pos_y = 0; |
| el17mcd | 8:d4e419dad90f | 48 | int time = 0; |
| el17mcd | 8:d4e419dad90f | 49 | float lnch_ang = 70.0; //in degrees |
| el17mcd | 8:d4e419dad90f | 50 | float init_vel = 1.3; |
| el17mcd | 8:d4e419dad90f | 51 | float init_x = 0; |
| el17mcd | 8:d4e419dad90f | 52 | float init_y = 0; |
| el17mcd | 8:d4e419dad90f | 53 | float grav_acc = 0.02; |
| el17mcd | 8:d4e419dad90f | 54 | float wind_acc = 0; |
| el17mcd | 8:d4e419dad90f | 55 | //tankl.set_health(1); |
| el17mcd | 3:087b28bf8b96 | 56 | // welcome(); // display welcome message |
| el17mcd | 2:8382613c86a0 | 57 | |
| el17mcd | 5:8a2e96f7fb4d | 58 | while(1) { // infinite loop |
| el17mcd | 8:d4e419dad90f | 59 | |
| el17mcd | 8:d4e419dad90f | 60 | p_pos_x = 10 + init_vel * time * cos(lnch_ang * DEG2PI) - 0.5 * wind_acc * time * time; |
| el17mcd | 8:d4e419dad90f | 61 | p_pos_y = 6 + init_vel * time * sin(lnch_ang * DEG2PI) - 0.5 * grav_acc * time * time; |
| el17mcd | 8:d4e419dad90f | 62 | time++; |
| el17mcd | 8:d4e419dad90f | 63 | proj.set_position(p_pos_x, p_pos_y); |
| el17mcd | 8:d4e419dad90f | 64 | if (p_pos_x < -3 || p_pos_x > 87 || p_pos_y < -3) {break;} |
| el17mcd | 8:d4e419dad90f | 65 | lcd.clear(); |
| el17mcd | 8:d4e419dad90f | 66 | proj.draw(lcd); |
| el17mcd | 8:d4e419dad90f | 67 | lcd.refresh(); |
| el17mcd | 8:d4e419dad90f | 68 | wait_ms(50); |
| el17mcd | 8:d4e419dad90f | 69 | } |
| el17mcd | 8:d4e419dad90f | 70 | lcd.clear(); |
| el17mcd | 8:d4e419dad90f | 71 | lcd.printString("DONE",0,1); |
| el17mcd | 8:d4e419dad90f | 72 | lcd.refresh(); |
| el17mcd | 8:d4e419dad90f | 73 | wait(10); |
| el17mcd | 8:d4e419dad90f | 74 | } |
| el17mcd | 8:d4e419dad90f | 75 | /* srand(time(NULL)); |
| el17mcd | 6:5d57c758c31d | 76 | int t_pos_x = rand() % (84-1-10); // Tank position |
| el17mcd | 6:5d57c758c31d | 77 | int t_pos_y = rand() % (48-1-6); |
| el17mcd | 7:a3ccabdebe2e | 78 | tankl.set_position(t_pos_x, t_pos_y); |
| el17mcd | 6:5d57c758c31d | 79 | |
| el17mcd | 6:5d57c758c31d | 80 | int p_pos_x = rand() % (84-1-5); // projectile position |
| el17mcd | 6:5d57c758c31d | 81 | int p_pos_y = rand() % (48-1-5); |
| el17mcd | 7:a3ccabdebe2e | 82 | proj.set_position(p_pos_x, p_pos_y); |
| el17mcd | 5:8a2e96f7fb4d | 83 | |
| el17mcd | 7:a3ccabdebe2e | 84 | tankl.generate_hitbox(); |
| el17mcd | 7:a3ccabdebe2e | 85 | proj.generate_hitbox(); |
| el17mcd | 7:a3ccabdebe2e | 86 | bool hit = engine.collision_pl(tankl, proj); |
| el17mcd | 4:3b3a7f102250 | 87 | |
| el17mcd | 7:a3ccabdebe2e | 88 | lcd.clear(); |
| el17mcd | 7:a3ccabdebe2e | 89 | tankl.draw(lcd); |
| el17mcd | 7:a3ccabdebe2e | 90 | proj.draw(lcd); |
| el17mcd | 7:a3ccabdebe2e | 91 | lcd.refresh(); |
| el17mcd | 7:a3ccabdebe2e | 92 | if (hit == true) { |
| el17mcd | 7:a3ccabdebe2e | 93 | wait(1.5); |
| el17mcd | 7:a3ccabdebe2e | 94 | lcd.clear(); |
| el17mcd | 7:a3ccabdebe2e | 95 | tankl.lose_health(); |
| el17mcd | 8:d4e419dad90f | 96 | lcd.printString("DONE",0,1); |
| el17mcd | 7:a3ccabdebe2e | 97 | lcd.refresh(); |
| el17mcd | 7:a3ccabdebe2e | 98 | wait(0.5); |
| el17mcd | 6:5d57c758c31d | 99 | } |
| el17mcd | 7:a3ccabdebe2e | 100 | else {wait_ms(50);} |
| el17mcd | 7:a3ccabdebe2e | 101 | } |
| el17mcd | 8:d4e419dad90f | 102 | */ |