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@7:a3ccabdebe2e, 2019-04-09 (annotated)
- Committer:
- el17mcd
- Date:
- Tue Apr 09 17:09:29 2019 +0000
- Revision:
- 7:a3ccabdebe2e
- Parent:
- 6:5d57c758c31d
- Child:
- 8:d4e419dad90f
! Hit detection mechanic implemented with separate classes.
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 | 2:8382613c86a0 | 18 | |
| el17mcd | 7:a3ccabdebe2e | 19 | #ifdef WITH_TESTING |
| el17mcd | 2:8382613c86a0 | 20 | |
| el17mcd | 7:a3ccabdebe2e | 21 | #endif |
| el17mcd | 7:a3ccabdebe2e | 22 | |
| el17mcd | 7:a3ccabdebe2e | 23 | /////////////// objects /////////////// |
| el17mcd | 7:a3ccabdebe2e | 24 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17mcd | 7:a3ccabdebe2e | 25 | TankL tankl; |
| el17mcd | 7:a3ccabdebe2e | 26 | Projectile proj; |
| el17mcd | 7:a3ccabdebe2e | 27 | TanksEngine engine; |
| el17mcd | 7:a3ccabdebe2e | 28 | |
| el17mcd | 2:8382613c86a0 | 29 | void welcome() |
| el17mcd | 2:8382613c86a0 | 30 | { |
| el17mcd | 2:8382613c86a0 | 31 | lcd.clear(); |
| el17mcd | 2:8382613c86a0 | 32 | lcd.printString(" ELEC 2645",0,0); |
| el17mcd | 2:8382613c86a0 | 33 | lcd.printString(" Game ",0,1); |
| el17mcd | 2:8382613c86a0 | 34 | lcd.printString(" Project",0,2); |
| el17mcd | 2:8382613c86a0 | 35 | lcd.printString("Max C. Delacoe",0,4); |
| el17mcd | 2:8382613c86a0 | 36 | lcd.printString(" 2011 58344",0,5); |
| el17mcd | 2:8382613c86a0 | 37 | lcd.refresh(); |
| el17mcd | 2:8382613c86a0 | 38 | wait(0.2); |
| el17mcd | 2:8382613c86a0 | 39 | } |
| el17mcd | 2:8382613c86a0 | 40 | |
| el17mcd | 2:8382613c86a0 | 41 | int main() |
| el17mcd | 2:8382613c86a0 | 42 | { |
| el17mcd | 2:8382613c86a0 | 43 | lcd.init(); |
| el17mcd | 7:a3ccabdebe2e | 44 | tankl.set_health(1); |
| el17mcd | 3:087b28bf8b96 | 45 | // welcome(); // display welcome message |
| el17mcd | 2:8382613c86a0 | 46 | |
| el17mcd | 5:8a2e96f7fb4d | 47 | while(1) { // infinite loop |
| el17mcd | 4:3b3a7f102250 | 48 | |
| el17mcd | 6:5d57c758c31d | 49 | srand(time(NULL)); |
| el17mcd | 6:5d57c758c31d | 50 | int t_pos_x = rand() % (84-1-10); // Tank position |
| el17mcd | 6:5d57c758c31d | 51 | int t_pos_y = rand() % (48-1-6); |
| el17mcd | 7:a3ccabdebe2e | 52 | tankl.set_position(t_pos_x, t_pos_y); |
| el17mcd | 6:5d57c758c31d | 53 | |
| el17mcd | 6:5d57c758c31d | 54 | int p_pos_x = rand() % (84-1-5); // projectile position |
| el17mcd | 6:5d57c758c31d | 55 | int p_pos_y = rand() % (48-1-5); |
| el17mcd | 7:a3ccabdebe2e | 56 | proj.set_position(p_pos_x, p_pos_y); |
| el17mcd | 5:8a2e96f7fb4d | 57 | |
| el17mcd | 7:a3ccabdebe2e | 58 | tankl.generate_hitbox(); |
| el17mcd | 7:a3ccabdebe2e | 59 | proj.generate_hitbox(); |
| el17mcd | 7:a3ccabdebe2e | 60 | bool hit = engine.collision_pl(tankl, proj); |
| el17mcd | 4:3b3a7f102250 | 61 | |
| el17mcd | 7:a3ccabdebe2e | 62 | lcd.clear(); |
| el17mcd | 7:a3ccabdebe2e | 63 | tankl.draw(lcd); |
| el17mcd | 7:a3ccabdebe2e | 64 | proj.draw(lcd); |
| el17mcd | 7:a3ccabdebe2e | 65 | lcd.refresh(); |
| el17mcd | 7:a3ccabdebe2e | 66 | if (hit == true) { |
| el17mcd | 7:a3ccabdebe2e | 67 | wait(1.5); |
| el17mcd | 7:a3ccabdebe2e | 68 | lcd.clear(); |
| el17mcd | 7:a3ccabdebe2e | 69 | tankl.lose_health(); |
| el17mcd | 7:a3ccabdebe2e | 70 | lcd.printString("HIT",0,1); |
| el17mcd | 7:a3ccabdebe2e | 71 | lcd.refresh(); |
| el17mcd | 7:a3ccabdebe2e | 72 | wait(0.5); |
| el17mcd | 6:5d57c758c31d | 73 | } |
| el17mcd | 7:a3ccabdebe2e | 74 | else {wait_ms(50);} |
| el17mcd | 7:a3ccabdebe2e | 75 | } |
| el17mcd | 7:a3ccabdebe2e | 76 | |
| el17mcd | 7:a3ccabdebe2e | 77 | } |