Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
graphics.cpp@4:37d3935365f8, 2021-09-28 (annotated)
- Committer:
- lballard9
- Date:
- Tue Sep 28 13:52:11 2021 +0000
- Revision:
- 4:37d3935365f8
- Parent:
- 0:35660d7952f7
- Child:
- 6:c9695079521d
Fall 2021 notes added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:35660d7952f7 | 1 | #include "graphics.h" |
rconnorlawson | 0:35660d7952f7 | 2 | |
rconnorlawson | 0:35660d7952f7 | 3 | #include "globals.h" |
rconnorlawson | 0:35660d7952f7 | 4 | |
lballard9 | 4:37d3935365f8 | 5 | /* |
lballard9 | 4:37d3935365f8 | 6 | In this file put all your graphical functions (don't forget to declare them first |
lballard9 | 4:37d3935365f8 | 7 | in graphics.h). So when you want to draw something use this file. One cool function |
lballard9 | 4:37d3935365f8 | 8 | to look at would be uLCD.blit() there are more like filled_rectangle etc... |
lballard9 | 4:37d3935365f8 | 9 | https://os.mbed.com/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ |
lballard9 | 4:37d3935365f8 | 10 | This website is a good resource. |
lballard9 | 4:37d3935365f8 | 11 | */ |
rconnorlawson | 0:35660d7952f7 | 12 | |
rconnorlawson | 0:35660d7952f7 | 13 | void draw_player(int u, int v, int key) |
rconnorlawson | 0:35660d7952f7 | 14 | { |
rconnorlawson | 0:35660d7952f7 | 15 | uLCD.filled_rectangle(u, v, u+11, v+11, RED); |
rconnorlawson | 0:35660d7952f7 | 16 | } |
rconnorlawson | 0:35660d7952f7 | 17 | |
rconnorlawson | 0:35660d7952f7 | 18 | #define YELLOW 0xFFFF00 |
rconnorlawson | 0:35660d7952f7 | 19 | #define BROWN 0xD2691E |
rconnorlawson | 0:35660d7952f7 | 20 | #define DIRT BROWN |
rconnorlawson | 0:35660d7952f7 | 21 | void draw_img(int u, int v, const char* img) |
rconnorlawson | 0:35660d7952f7 | 22 | { |
rconnorlawson | 0:35660d7952f7 | 23 | int colors[11*11]; |
rconnorlawson | 0:35660d7952f7 | 24 | for (int i = 0; i < 11*11; i++) |
rconnorlawson | 0:35660d7952f7 | 25 | { |
rconnorlawson | 0:35660d7952f7 | 26 | if (img[i] == 'R') colors[i] = RED; |
rconnorlawson | 0:35660d7952f7 | 27 | else if (img[i] == 'Y') colors[i] = YELLOW; |
rconnorlawson | 0:35660d7952f7 | 28 | else if (img[i] == 'G') colors[i] = GREEN; |
rconnorlawson | 0:35660d7952f7 | 29 | else if (img[i] == 'D') colors[i] = DIRT; |
rconnorlawson | 0:35660d7952f7 | 30 | else if (img[i] == '5') colors[i] = LGREY; |
rconnorlawson | 0:35660d7952f7 | 31 | else if (img[i] == '3') colors[i] = DGREY; |
rconnorlawson | 0:35660d7952f7 | 32 | else colors[i] = BLACK; |
rconnorlawson | 0:35660d7952f7 | 33 | } |
rconnorlawson | 0:35660d7952f7 | 34 | uLCD.BLIT(u, v, 11, 11, colors); |
rconnorlawson | 0:35660d7952f7 | 35 | wait_us(250); // Recovery time! |
rconnorlawson | 0:35660d7952f7 | 36 | } |
rconnorlawson | 0:35660d7952f7 | 37 | |
rconnorlawson | 0:35660d7952f7 | 38 | void draw_nothing(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 39 | { |
rconnorlawson | 0:35660d7952f7 | 40 | // Fill a tile with blackness |
rconnorlawson | 0:35660d7952f7 | 41 | uLCD.filled_rectangle(u, v, u+10, v+10, BLACK); |
rconnorlawson | 0:35660d7952f7 | 42 | } |
rconnorlawson | 0:35660d7952f7 | 43 | |
rconnorlawson | 0:35660d7952f7 | 44 | void draw_wall(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 45 | { |
rconnorlawson | 0:35660d7952f7 | 46 | uLCD.filled_rectangle(u, v, u+10, v+10, BROWN); |
rconnorlawson | 0:35660d7952f7 | 47 | } |
rconnorlawson | 0:35660d7952f7 | 48 | |
rconnorlawson | 0:35660d7952f7 | 49 | void draw_plant(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 50 | { |
rconnorlawson | 0:35660d7952f7 | 51 | uLCD.filled_rectangle(u, v, u+10, v+10, GREEN); |
rconnorlawson | 0:35660d7952f7 | 52 | } |
rconnorlawson | 0:35660d7952f7 | 53 | |
rconnorlawson | 0:35660d7952f7 | 54 | void draw_upper_status() |
rconnorlawson | 0:35660d7952f7 | 55 | { |
rconnorlawson | 0:35660d7952f7 | 56 | // Draw bottom border of status bar |
rconnorlawson | 0:35660d7952f7 | 57 | uLCD.line(0, 9, 127, 9, GREEN); |
rconnorlawson | 0:35660d7952f7 | 58 | |
rconnorlawson | 0:35660d7952f7 | 59 | // Add other status info drawing code here |
rconnorlawson | 0:35660d7952f7 | 60 | } |
rconnorlawson | 0:35660d7952f7 | 61 | |
rconnorlawson | 0:35660d7952f7 | 62 | void draw_lower_status() |
rconnorlawson | 0:35660d7952f7 | 63 | { |
rconnorlawson | 0:35660d7952f7 | 64 | // Draw top border of status bar |
rconnorlawson | 0:35660d7952f7 | 65 | uLCD.line(0, 118, 127, 118, GREEN); |
rconnorlawson | 0:35660d7952f7 | 66 | |
rconnorlawson | 0:35660d7952f7 | 67 | // Add other status info drawing code here |
rconnorlawson | 0:35660d7952f7 | 68 | } |
rconnorlawson | 0:35660d7952f7 | 69 | |
rconnorlawson | 0:35660d7952f7 | 70 | void draw_border() |
rconnorlawson | 0:35660d7952f7 | 71 | { |
rconnorlawson | 0:35660d7952f7 | 72 | uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top |
rconnorlawson | 0:35660d7952f7 | 73 | uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left |
rconnorlawson | 0:35660d7952f7 | 74 | uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom |
rconnorlawson | 0:35660d7952f7 | 75 | uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right |
rconnorlawson | 0:35660d7952f7 | 76 | } |
rconnorlawson | 0:35660d7952f7 | 77 | |
rconnorlawson | 0:35660d7952f7 | 78 |