Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
graphics.cpp@7:862062ffca62, 2021-11-20 (annotated)
- Committer:
- nasiromar
- Date:
- Sat Nov 20 03:37:50 2021 +0000
- Revision:
- 7:862062ffca62
- Parent:
- 6:c9695079521d
- Child:
- 9:cbb9cfb1f6c5
Base Model without game over
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" |
nasiromar | 6:c9695079521d | 4 | #include "main_char.cpp" |
nasiromar | 6:c9695079521d | 5 | #include "chest.cpp" |
nasiromar | 6:c9695079521d | 6 | #include "castle.cpp" |
nasiromar | 6:c9695079521d | 7 | #include "key.cpp" |
nasiromar | 6:c9695079521d | 8 | #include "portal.cpp" |
nasiromar | 6:c9695079521d | 9 | #include "tree.cpp" |
nasiromar | 6:c9695079521d | 10 | #include "npc.cpp" |
nasiromar | 7:862062ffca62 | 11 | #include "door.cpp" |
nasiromar | 7:862062ffca62 | 12 | #include "dragon.cpp" |
nasiromar | 7:862062ffca62 | 13 | #include "portal2.cpp" |
nasiromar | 7:862062ffca62 | 14 | #include "kindom.cpp" |
nasiromar | 7:862062ffca62 | 15 | |
lballard9 | 4:37d3935365f8 | 16 | /* |
lballard9 | 4:37d3935365f8 | 17 | In this file put all your graphical functions (don't forget to declare them first |
lballard9 | 4:37d3935365f8 | 18 | in graphics.h). So when you want to draw something use this file. One cool function |
lballard9 | 4:37d3935365f8 | 19 | to look at would be uLCD.blit() there are more like filled_rectangle etc... |
lballard9 | 4:37d3935365f8 | 20 | https://os.mbed.com/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ |
lballard9 | 4:37d3935365f8 | 21 | This website is a good resource. |
lballard9 | 4:37d3935365f8 | 22 | */ |
rconnorlawson | 0:35660d7952f7 | 23 | |
rconnorlawson | 0:35660d7952f7 | 24 | void draw_player(int u, int v, int key) |
rconnorlawson | 0:35660d7952f7 | 25 | { |
nasiromar | 6:c9695079521d | 26 | |
nasiromar | 6:c9695079521d | 27 | uLCD.BLIT(u,v,11,11,main_char_arr); |
nasiromar | 6:c9695079521d | 28 | //.filled_rectangle(u, v, u+11, v+11, RED); |
rconnorlawson | 0:35660d7952f7 | 29 | } |
rconnorlawson | 0:35660d7952f7 | 30 | |
rconnorlawson | 0:35660d7952f7 | 31 | #define YELLOW 0xFFFF00 |
rconnorlawson | 0:35660d7952f7 | 32 | #define BROWN 0xD2691E |
rconnorlawson | 0:35660d7952f7 | 33 | #define DIRT BROWN |
rconnorlawson | 0:35660d7952f7 | 34 | void draw_img(int u, int v, const char* img) |
rconnorlawson | 0:35660d7952f7 | 35 | { |
rconnorlawson | 0:35660d7952f7 | 36 | int colors[11*11]; |
rconnorlawson | 0:35660d7952f7 | 37 | for (int i = 0; i < 11*11; i++) |
rconnorlawson | 0:35660d7952f7 | 38 | { |
rconnorlawson | 0:35660d7952f7 | 39 | if (img[i] == 'R') colors[i] = RED; |
rconnorlawson | 0:35660d7952f7 | 40 | else if (img[i] == 'Y') colors[i] = YELLOW; |
rconnorlawson | 0:35660d7952f7 | 41 | else if (img[i] == 'G') colors[i] = GREEN; |
rconnorlawson | 0:35660d7952f7 | 42 | else if (img[i] == 'D') colors[i] = DIRT; |
rconnorlawson | 0:35660d7952f7 | 43 | else if (img[i] == '5') colors[i] = LGREY; |
rconnorlawson | 0:35660d7952f7 | 44 | else if (img[i] == '3') colors[i] = DGREY; |
rconnorlawson | 0:35660d7952f7 | 45 | else colors[i] = BLACK; |
rconnorlawson | 0:35660d7952f7 | 46 | } |
rconnorlawson | 0:35660d7952f7 | 47 | uLCD.BLIT(u, v, 11, 11, colors); |
rconnorlawson | 0:35660d7952f7 | 48 | wait_us(250); // Recovery time! |
rconnorlawson | 0:35660d7952f7 | 49 | } |
rconnorlawson | 0:35660d7952f7 | 50 | |
nasiromar | 7:862062ffca62 | 51 | |
nasiromar | 7:862062ffca62 | 52 | void draw_gameover(){ |
nasiromar | 7:862062ffca62 | 53 | uLCD.filled_rectangle(0,0,127,127, BLACK); |
nasiromar | 7:862062ffca62 | 54 | uLCD.set_font(FONT_8X8); |
nasiromar | 7:862062ffca62 | 55 | uLCD.text_mode(OPAQUE); |
nasiromar | 7:862062ffca62 | 56 | uLCD.locate(6,6); |
nasiromar | 7:862062ffca62 | 57 | uLCD.printf("GAME OVER"); |
nasiromar | 7:862062ffca62 | 58 | } |
nasiromar | 7:862062ffca62 | 59 | |
nasiromar | 7:862062ffca62 | 60 | |
rconnorlawson | 0:35660d7952f7 | 61 | void draw_nothing(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 62 | { |
rconnorlawson | 0:35660d7952f7 | 63 | // Fill a tile with blackness |
rconnorlawson | 0:35660d7952f7 | 64 | uLCD.filled_rectangle(u, v, u+10, v+10, BLACK); |
rconnorlawson | 0:35660d7952f7 | 65 | } |
rconnorlawson | 0:35660d7952f7 | 66 | |
rconnorlawson | 0:35660d7952f7 | 67 | void draw_wall(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 68 | { |
rconnorlawson | 0:35660d7952f7 | 69 | uLCD.filled_rectangle(u, v, u+10, v+10, BROWN); |
rconnorlawson | 0:35660d7952f7 | 70 | } |
rconnorlawson | 0:35660d7952f7 | 71 | |
rconnorlawson | 0:35660d7952f7 | 72 | void draw_plant(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 73 | { |
nasiromar | 6:c9695079521d | 74 | uLCD.BLIT(u,v,11,11,tree_arr); |
nasiromar | 6:c9695079521d | 75 | } |
nasiromar | 6:c9695079521d | 76 | |
nasiromar | 6:c9695079521d | 77 | void draw_key(int u, int v) |
nasiromar | 6:c9695079521d | 78 | { |
nasiromar | 6:c9695079521d | 79 | uLCD.BLIT(u,v,11,11,key_arr); |
nasiromar | 6:c9695079521d | 80 | } |
nasiromar | 6:c9695079521d | 81 | |
nasiromar | 6:c9695079521d | 82 | void draw_npc(int u, int v) |
nasiromar | 6:c9695079521d | 83 | { |
nasiromar | 6:c9695079521d | 84 | uLCD.BLIT(u,v,11,11,npc_arr); |
nasiromar | 6:c9695079521d | 85 | } |
nasiromar | 6:c9695079521d | 86 | |
nasiromar | 6:c9695079521d | 87 | void draw_portal(int u, int v) |
nasiromar | 6:c9695079521d | 88 | { |
nasiromar | 6:c9695079521d | 89 | uLCD.BLIT(u,v,11,11,portal_arr); |
rconnorlawson | 0:35660d7952f7 | 90 | } |
rconnorlawson | 0:35660d7952f7 | 91 | |
nasiromar | 7:862062ffca62 | 92 | void draw_portal2(int u, int v) |
nasiromar | 7:862062ffca62 | 93 | { |
nasiromar | 7:862062ffca62 | 94 | uLCD.BLIT(u,v,11,11,portal2_arr); |
nasiromar | 7:862062ffca62 | 95 | } |
nasiromar | 7:862062ffca62 | 96 | |
nasiromar | 6:c9695079521d | 97 | void draw_castle(int u, int v) |
rconnorlawson | 0:35660d7952f7 | 98 | { |
nasiromar | 6:c9695079521d | 99 | uLCD.BLIT(u,v,11,11,castle_arr); |
nasiromar | 6:c9695079521d | 100 | } |
nasiromar | 6:c9695079521d | 101 | |
nasiromar | 7:862062ffca62 | 102 | void draw_kindom(int u, int v) |
nasiromar | 7:862062ffca62 | 103 | { |
nasiromar | 7:862062ffca62 | 104 | uLCD.BLIT(u,v,11,11,kindom_arr); |
nasiromar | 7:862062ffca62 | 105 | } |
nasiromar | 7:862062ffca62 | 106 | |
nasiromar | 7:862062ffca62 | 107 | |
nasiromar | 7:862062ffca62 | 108 | void draw_door(int u, int v){ |
nasiromar | 7:862062ffca62 | 109 | uLCD.BLIT(u,v,11,11,door_arr); |
nasiromar | 7:862062ffca62 | 110 | } |
nasiromar | 7:862062ffca62 | 111 | |
nasiromar | 7:862062ffca62 | 112 | void draw_dragon(int u, int v){ |
nasiromar | 7:862062ffca62 | 113 | uLCD.BLIT(u,v,11,11,dragon_arr); |
nasiromar | 7:862062ffca62 | 114 | } |
nasiromar | 7:862062ffca62 | 115 | |
nasiromar | 6:c9695079521d | 116 | void draw_chest(int u, int v){ |
nasiromar | 6:c9695079521d | 117 | uLCD.BLIT(u,v,11,11,chest); |
nasiromar | 6:c9695079521d | 118 | } |
nasiromar | 6:c9695079521d | 119 | |
nasiromar | 7:862062ffca62 | 120 | |
nasiromar | 6:c9695079521d | 121 | void draw_upper_status(int player_x, int player_y) |
nasiromar | 6:c9695079521d | 122 | { |
nasiromar | 6:c9695079521d | 123 | uLCD.locate(0,0); |
nasiromar | 6:c9695079521d | 124 | uLCD.text_width(1); |
nasiromar | 6:c9695079521d | 125 | uLCD.text_height(1); |
nasiromar | 6:c9695079521d | 126 | uLCD.color(GREEN); |
nasiromar | 6:c9695079521d | 127 | uLCD.printf("X: [%2i] Y: [%2i]",player_x,player_y); |
nasiromar | 6:c9695079521d | 128 | |
rconnorlawson | 0:35660d7952f7 | 129 | // Draw bottom border of status bar |
rconnorlawson | 0:35660d7952f7 | 130 | |
rconnorlawson | 0:35660d7952f7 | 131 | // Add other status info drawing code here |
rconnorlawson | 0:35660d7952f7 | 132 | } |
rconnorlawson | 0:35660d7952f7 | 133 | |
nasiromar | 6:c9695079521d | 134 | void draw_lower_status(int hp, int mp) |
nasiromar | 6:c9695079521d | 135 | { |
rconnorlawson | 0:35660d7952f7 | 136 | // Draw top border of status bar |
nasiromar | 6:c9695079521d | 137 | uLCD.locate(0,15); |
nasiromar | 6:c9695079521d | 138 | uLCD.text_width(1); |
nasiromar | 6:c9695079521d | 139 | uLCD.text_height(1); |
nasiromar | 6:c9695079521d | 140 | uLCD.color(GREEN); |
nasiromar | 6:c9695079521d | 141 | uLCD.printf("HP: %3i MP: %3i",hp,mp); |
rconnorlawson | 0:35660d7952f7 | 142 | |
rconnorlawson | 0:35660d7952f7 | 143 | // Add other status info drawing code here |
rconnorlawson | 0:35660d7952f7 | 144 | } |
rconnorlawson | 0:35660d7952f7 | 145 | |
rconnorlawson | 0:35660d7952f7 | 146 | void draw_border() |
rconnorlawson | 0:35660d7952f7 | 147 | { |
rconnorlawson | 0:35660d7952f7 | 148 | uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top |
rconnorlawson | 0:35660d7952f7 | 149 | uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left |
rconnorlawson | 0:35660d7952f7 | 150 | uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom |
rconnorlawson | 0:35660d7952f7 | 151 | uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right |
rconnorlawson | 0:35660d7952f7 | 152 | } |
rconnorlawson | 0:35660d7952f7 | 153 | |
nasiromar | 6:c9695079521d | 154 | |
nasiromar | 6:c9695079521d | 155 |