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@4:3b3a7f102250, 2019-04-02 (annotated)
- Committer:
- el17mcd
- Date:
- Tue Apr 02 19:00:18 2019 +0000
- Revision:
- 4:3b3a7f102250
- Parent:
- 3:087b28bf8b96
- Child:
- 5:8a2e96f7fb4d
Experimenting with generating a "hitbox" for the tank on a grid system whereby every space on the grid has a corresponding integer value. E.g pixel at (0,0) has the value 1 and pixel (1,0) has the value 2.
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 | 2:8382613c86a0 | 15 | |
| el17mcd | 2:8382613c86a0 | 16 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| el17mcd | 2:8382613c86a0 | 17 | |
| el17mcd | 2:8382613c86a0 | 18 | const int tank_left[6][10] = { |
| el17mcd | 2:8382613c86a0 | 19 | { 0,0,0,1,1,1,0,0,0,0 }, |
| el17mcd | 2:8382613c86a0 | 20 | { 0,0,1,1,1,1,1,0,0,0 }, |
| el17mcd | 2:8382613c86a0 | 21 | { 0,0,1,1,1,1,1,1,1,0 }, |
| el17mcd | 2:8382613c86a0 | 22 | { 1,1,1,1,1,1,1,1,1,1 }, |
| el17mcd | 2:8382613c86a0 | 23 | { 1,0,1,0,1,0,1,0,1,0 }, |
| el17mcd | 2:8382613c86a0 | 24 | { 0,1,0,1,0,1,0,1,0,0 }, |
| el17mcd | 2:8382613c86a0 | 25 | }; |
| el17mcd | 4:3b3a7f102250 | 26 | const int proj[5][5] = { |
| el17mcd | 4:3b3a7f102250 | 27 | { 0,0,1,0,0 }, |
| el17mcd | 4:3b3a7f102250 | 28 | { 0,0,1,0,0 }, |
| el17mcd | 4:3b3a7f102250 | 29 | { 1,1,1,1,1 }, |
| el17mcd | 4:3b3a7f102250 | 30 | { 0,0,1,0,0 }, |
| el17mcd | 4:3b3a7f102250 | 31 | { 0,0,1,0,0 }, |
| el17mcd | 4:3b3a7f102250 | 32 | }; |
| el17mcd | 4:3b3a7f102250 | 33 | // Spawning tank and projectile at random position |
| el17mcd | 4:3b3a7f102250 | 34 | // with visual feedback to build grid and hitbox system |
| el17mcd | 2:8382613c86a0 | 35 | void welcome() |
| el17mcd | 2:8382613c86a0 | 36 | { |
| el17mcd | 2:8382613c86a0 | 37 | lcd.clear(); |
| el17mcd | 2:8382613c86a0 | 38 | lcd.printString(" ELEC 2645",0,0); |
| el17mcd | 2:8382613c86a0 | 39 | lcd.printString(" Game ",0,1); |
| el17mcd | 2:8382613c86a0 | 40 | lcd.printString(" Project",0,2); |
| el17mcd | 2:8382613c86a0 | 41 | lcd.printString("Max C. Delacoe",0,4); |
| el17mcd | 2:8382613c86a0 | 42 | lcd.printString(" 2011 58344",0,5); |
| el17mcd | 2:8382613c86a0 | 43 | lcd.refresh(); |
| el17mcd | 2:8382613c86a0 | 44 | wait(0.2); |
| el17mcd | 2:8382613c86a0 | 45 | } |
| el17mcd | 2:8382613c86a0 | 46 | |
| el17mcd | 2:8382613c86a0 | 47 | int main() |
| el17mcd | 2:8382613c86a0 | 48 | { |
| el17mcd | 4:3b3a7f102250 | 49 | int tank_hb[40]; |
| el17mcd | 2:8382613c86a0 | 50 | lcd.init(); |
| el17mcd | 3:087b28bf8b96 | 51 | // welcome(); // display welcome message |
| el17mcd | 2:8382613c86a0 | 52 | |
| el17mcd | 4:3b3a7f102250 | 53 | // while(1) { // infinite loop |
| el17mcd | 4:3b3a7f102250 | 54 | |
| el17mcd | 4:3b3a7f102250 | 55 | srand(time(NULL)); |
| el17mcd | 4:3b3a7f102250 | 56 | char buffer[14]; |
| el17mcd | 4:3b3a7f102250 | 57 | int t_pos_x = rand() % 77; |
| el17mcd | 4:3b3a7f102250 | 58 | int t_pos_y = rand() % 37; |
| el17mcd | 4:3b3a7f102250 | 59 | int i = 0; |
| el17mcd | 4:3b3a7f102250 | 60 | |
| el17mcd | 4:3b3a7f102250 | 61 | for (int i0 = 0; i0 < 6; i0++) { |
| el17mcd | 4:3b3a7f102250 | 62 | |
| el17mcd | 4:3b3a7f102250 | 63 | for (int i1 = 1; i1 < 11; i1++) { |
| el17mcd | 4:3b3a7f102250 | 64 | tank_hb[i] = (i0 + t_pos_y) * 84 + t_pos_x + i1; |
| el17mcd | 4:3b3a7f102250 | 65 | i++; |
| el17mcd | 4:3b3a7f102250 | 66 | } |
| el17mcd | 4:3b3a7f102250 | 67 | } |
| el17mcd | 4:3b3a7f102250 | 68 | |
| el17mcd | 4:3b3a7f102250 | 69 | int p_pos_x = rand() % 84; |
| el17mcd | 4:3b3a7f102250 | 70 | int p_pos_y = rand() % 48; |
| el17mcd | 4:3b3a7f102250 | 71 | int proj_hb = p_pos_y * 84 + p_pos_x + 1; |
| el17mcd | 4:3b3a7f102250 | 72 | |
| el17mcd | 4:3b3a7f102250 | 73 | //sprintf(buffer,"t_pos_x = %d ",t_pos_x); |
| el17mcd | 4:3b3a7f102250 | 74 | lcd.clear(); |
| el17mcd | 4:3b3a7f102250 | 75 | lcd.drawSprite(t_pos_x,42 - t_pos_y,6,10,(int *)tank_left); |
| el17mcd | 4:3b3a7f102250 | 76 | lcd.drawSprite(p_pos_x - 2 ,44 - p_pos_y,5,5,(int *)proj); |
| el17mcd | 4:3b3a7f102250 | 77 | //lcd.printString(buffer,0,1); |
| el17mcd | 4:3b3a7f102250 | 78 | lcd.refresh(); |
| el17mcd | 4:3b3a7f102250 | 79 | wait(1); |
| el17mcd | 4:3b3a7f102250 | 80 | // } |
| el17mcd | 2:8382613c86a0 | 81 | } |
| el17mcd | 2:8382613c86a0 | 82 |