Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
nasiromar
Date:
Fri Dec 03 19:12:50 2021 +0000
Revision:
18:760dd68e939e
Parent:
17:4abe3fba3471
New Update;

Who changed what in which revision?

UserRevisionLine numberNew 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 11:6cd02a8539d1 15 #include "eye.cpp"
nasiromar 11:6cd02a8539d1 16 #include "merch.cpp"
nasiromar 11:6cd02a8539d1 17 #include "goblin.cpp"
nasiromar 11:6cd02a8539d1 18 #include "store.cpp"
nasiromar 11:6cd02a8539d1 19 #include "npc2.cpp"
nasiromar 11:6cd02a8539d1 20 #include "fire.cpp"
nasiromar 7:862062ffca62 21
lballard9 4:37d3935365f8 22 /*
lballard9 4:37d3935365f8 23 In this file put all your graphical functions (don't forget to declare them first
lballard9 4:37d3935365f8 24 in graphics.h). So when you want to draw something use this file. One cool function
lballard9 4:37d3935365f8 25 to look at would be uLCD.blit() there are more like filled_rectangle etc...
lballard9 4:37d3935365f8 26 https://os.mbed.com/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/
lballard9 4:37d3935365f8 27 This website is a good resource.
lballard9 4:37d3935365f8 28 */
rconnorlawson 0:35660d7952f7 29
rconnorlawson 0:35660d7952f7 30 void draw_player(int u, int v, int key)
rconnorlawson 0:35660d7952f7 31 {
nasiromar 6:c9695079521d 32
nasiromar 6:c9695079521d 33 uLCD.BLIT(u,v,11,11,main_char_arr);
nasiromar 6:c9695079521d 34 //.filled_rectangle(u, v, u+11, v+11, RED);
rconnorlawson 0:35660d7952f7 35 }
rconnorlawson 0:35660d7952f7 36
rconnorlawson 0:35660d7952f7 37 #define YELLOW 0xFFFF00
rconnorlawson 0:35660d7952f7 38 #define BROWN 0xD2691E
nasiromar 9:cbb9cfb1f6c5 39 #define BLUE 0x0000FF
rconnorlawson 0:35660d7952f7 40 #define DIRT BROWN
rconnorlawson 0:35660d7952f7 41 void draw_img(int u, int v, const char* img)
rconnorlawson 0:35660d7952f7 42 {
rconnorlawson 0:35660d7952f7 43 int colors[11*11];
rconnorlawson 0:35660d7952f7 44 for (int i = 0; i < 11*11; i++)
rconnorlawson 0:35660d7952f7 45 {
rconnorlawson 0:35660d7952f7 46 if (img[i] == 'R') colors[i] = RED;
rconnorlawson 0:35660d7952f7 47 else if (img[i] == 'Y') colors[i] = YELLOW;
rconnorlawson 0:35660d7952f7 48 else if (img[i] == 'G') colors[i] = GREEN;
rconnorlawson 0:35660d7952f7 49 else if (img[i] == 'D') colors[i] = DIRT;
rconnorlawson 0:35660d7952f7 50 else if (img[i] == '5') colors[i] = LGREY;
rconnorlawson 0:35660d7952f7 51 else if (img[i] == '3') colors[i] = DGREY;
rconnorlawson 0:35660d7952f7 52 else colors[i] = BLACK;
rconnorlawson 0:35660d7952f7 53 }
rconnorlawson 0:35660d7952f7 54 uLCD.BLIT(u, v, 11, 11, colors);
rconnorlawson 0:35660d7952f7 55 wait_us(250); // Recovery time!
rconnorlawson 0:35660d7952f7 56 }
rconnorlawson 0:35660d7952f7 57
nasiromar 7:862062ffca62 58
nasiromar 7:862062ffca62 59 void draw_gameover(){
nasiromar 7:862062ffca62 60 uLCD.filled_rectangle(0,0,127,127, BLACK);
nasiromar 7:862062ffca62 61 uLCD.set_font(FONT_8X8);
nasiromar 7:862062ffca62 62 uLCD.text_mode(OPAQUE);
nasiromar 16:06a88c0110ff 63 uLCD.locate(5,6);
nasiromar 7:862062ffca62 64 uLCD.printf("GAME OVER");
nasiromar 7:862062ffca62 65 }
nasiromar 7:862062ffca62 66
nasiromar 16:06a88c0110ff 67 void draw_win(){
nasiromar 16:06a88c0110ff 68 uLCD.filled_rectangle(0,0,127,127, BLACK);
nasiromar 16:06a88c0110ff 69 uLCD.set_font(FONT_8X8);
nasiromar 16:06a88c0110ff 70 uLCD.text_mode(OPAQUE);
nasiromar 17:4abe3fba3471 71 uLCD.color(BLUE);
nasiromar 16:06a88c0110ff 72 uLCD.locate(5,6);
nasiromar 16:06a88c0110ff 73 uLCD.printf("YOU WIN");
nasiromar 16:06a88c0110ff 74 }
nasiromar 16:06a88c0110ff 75
nasiromar 7:862062ffca62 76
rconnorlawson 0:35660d7952f7 77 void draw_nothing(int u, int v)
rconnorlawson 0:35660d7952f7 78 {
rconnorlawson 0:35660d7952f7 79 // Fill a tile with blackness
rconnorlawson 0:35660d7952f7 80 uLCD.filled_rectangle(u, v, u+10, v+10, BLACK);
rconnorlawson 0:35660d7952f7 81 }
rconnorlawson 0:35660d7952f7 82
rconnorlawson 0:35660d7952f7 83 void draw_wall(int u, int v)
rconnorlawson 0:35660d7952f7 84 {
rconnorlawson 0:35660d7952f7 85 uLCD.filled_rectangle(u, v, u+10, v+10, BROWN);
rconnorlawson 0:35660d7952f7 86 }
rconnorlawson 0:35660d7952f7 87
rconnorlawson 0:35660d7952f7 88 void draw_plant(int u, int v)
rconnorlawson 0:35660d7952f7 89 {
nasiromar 6:c9695079521d 90 uLCD.BLIT(u,v,11,11,tree_arr);
nasiromar 6:c9695079521d 91 }
nasiromar 6:c9695079521d 92
nasiromar 6:c9695079521d 93 void draw_key(int u, int v)
nasiromar 6:c9695079521d 94 {
nasiromar 6:c9695079521d 95 uLCD.BLIT(u,v,11,11,key_arr);
nasiromar 6:c9695079521d 96 }
nasiromar 6:c9695079521d 97
nasiromar 11:6cd02a8539d1 98 void draw_fire(int u, int v)
nasiromar 11:6cd02a8539d1 99 {
nasiromar 11:6cd02a8539d1 100 uLCD.BLIT(u,v,11,11,fire_arr);
nasiromar 11:6cd02a8539d1 101 }
nasiromar 11:6cd02a8539d1 102
nasiromar 6:c9695079521d 103 void draw_npc(int u, int v)
nasiromar 6:c9695079521d 104 {
nasiromar 6:c9695079521d 105 uLCD.BLIT(u,v,11,11,npc_arr);
nasiromar 6:c9695079521d 106 }
nasiromar 6:c9695079521d 107
nasiromar 11:6cd02a8539d1 108 void draw_npc2(int u, int v)
nasiromar 11:6cd02a8539d1 109 {
nasiromar 11:6cd02a8539d1 110 uLCD.BLIT(u,v,11,11,npc2_arr);
nasiromar 11:6cd02a8539d1 111 }
nasiromar 11:6cd02a8539d1 112
nasiromar 11:6cd02a8539d1 113 void draw_goblin(int u, int v)
nasiromar 11:6cd02a8539d1 114 {
nasiromar 11:6cd02a8539d1 115 uLCD.BLIT(u,v,11,11,goblin_arr);
nasiromar 11:6cd02a8539d1 116 }
nasiromar 11:6cd02a8539d1 117
nasiromar 11:6cd02a8539d1 118 void draw_eye(int u, int v)
nasiromar 11:6cd02a8539d1 119 {
nasiromar 11:6cd02a8539d1 120 uLCD.BLIT(u,v,11,11,eye_arr);
nasiromar 11:6cd02a8539d1 121 }
nasiromar 11:6cd02a8539d1 122
nasiromar 11:6cd02a8539d1 123 void draw_store(int u, int v)
nasiromar 11:6cd02a8539d1 124 {
nasiromar 11:6cd02a8539d1 125 uLCD.BLIT(u,v,11,11,store_arr);
nasiromar 11:6cd02a8539d1 126 }
nasiromar 11:6cd02a8539d1 127
nasiromar 11:6cd02a8539d1 128 void draw_merch(int u, int v)
nasiromar 11:6cd02a8539d1 129 {
nasiromar 11:6cd02a8539d1 130 uLCD.BLIT(u,v,11,11,merch_arr);
nasiromar 11:6cd02a8539d1 131 }
nasiromar 11:6cd02a8539d1 132
nasiromar 11:6cd02a8539d1 133
nasiromar 6:c9695079521d 134 void draw_portal(int u, int v)
nasiromar 6:c9695079521d 135 {
nasiromar 6:c9695079521d 136 uLCD.BLIT(u,v,11,11,portal_arr);
rconnorlawson 0:35660d7952f7 137 }
rconnorlawson 0:35660d7952f7 138
nasiromar 7:862062ffca62 139 void draw_portal2(int u, int v)
nasiromar 7:862062ffca62 140 {
nasiromar 7:862062ffca62 141 uLCD.BLIT(u,v,11,11,portal2_arr);
nasiromar 7:862062ffca62 142 }
nasiromar 7:862062ffca62 143
nasiromar 6:c9695079521d 144 void draw_castle(int u, int v)
rconnorlawson 0:35660d7952f7 145 {
nasiromar 6:c9695079521d 146 uLCD.BLIT(u,v,11,11,castle_arr);
nasiromar 6:c9695079521d 147 }
nasiromar 6:c9695079521d 148
nasiromar 7:862062ffca62 149 void draw_kindom(int u, int v)
nasiromar 7:862062ffca62 150 {
nasiromar 7:862062ffca62 151 uLCD.BLIT(u,v,11,11,kindom_arr);
nasiromar 7:862062ffca62 152 }
nasiromar 7:862062ffca62 153
nasiromar 7:862062ffca62 154
nasiromar 7:862062ffca62 155 void draw_door(int u, int v){
nasiromar 7:862062ffca62 156 uLCD.BLIT(u,v,11,11,door_arr);
nasiromar 7:862062ffca62 157 }
nasiromar 7:862062ffca62 158
nasiromar 7:862062ffca62 159 void draw_dragon(int u, int v){
nasiromar 7:862062ffca62 160 uLCD.BLIT(u,v,11,11,dragon_arr);
nasiromar 7:862062ffca62 161 }
nasiromar 7:862062ffca62 162
nasiromar 6:c9695079521d 163 void draw_chest(int u, int v){
nasiromar 6:c9695079521d 164 uLCD.BLIT(u,v,11,11,chest);
nasiromar 6:c9695079521d 165 }
nasiromar 6:c9695079521d 166
nasiromar 7:862062ffca62 167
nasiromar 14:7225da81314a 168 void draw_upper_status(int player_x, int player_y, int coin)
nasiromar 6:c9695079521d 169 {
nasiromar 6:c9695079521d 170 uLCD.locate(0,0);
nasiromar 6:c9695079521d 171 uLCD.text_width(1);
nasiromar 6:c9695079521d 172 uLCD.text_height(1);
nasiromar 6:c9695079521d 173 uLCD.color(GREEN);
nasiromar 14:7225da81314a 174 uLCD.printf("X:[%2i] Y:[%2i] $:%1i",player_x,player_y,coin);
nasiromar 6:c9695079521d 175
rconnorlawson 0:35660d7952f7 176 // Draw bottom border of status bar
rconnorlawson 0:35660d7952f7 177
rconnorlawson 0:35660d7952f7 178 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 179 }
rconnorlawson 0:35660d7952f7 180
nasiromar 6:c9695079521d 181 void draw_lower_status(int hp, int mp)
nasiromar 6:c9695079521d 182 {
rconnorlawson 0:35660d7952f7 183 // Draw top border of status bar
nasiromar 6:c9695079521d 184 uLCD.locate(0,15);
nasiromar 6:c9695079521d 185 uLCD.text_width(1);
nasiromar 6:c9695079521d 186 uLCD.text_height(1);
nasiromar 6:c9695079521d 187 uLCD.color(GREEN);
nasiromar 14:7225da81314a 188 uLCD.printf("HP:%3i MP:%3i",hp,mp);
nasiromar 14:7225da81314a 189
nasiromar 14:7225da81314a 190 // Add other status info drawing code here
nasiromar 14:7225da81314a 191 }
nasiromar 14:7225da81314a 192
nasiromar 14:7225da81314a 193 void draw_spell(char spell)
nasiromar 14:7225da81314a 194 {
nasiromar 14:7225da81314a 195 // Draw top border of status bar
nasiromar 14:7225da81314a 196 uLCD.locate(16,15);
nasiromar 14:7225da81314a 197 uLCD.text_width(1);
nasiromar 14:7225da81314a 198 uLCD.text_height(1);
nasiromar 14:7225da81314a 199 uLCD.color(GREEN);
nasiromar 14:7225da81314a 200 uLCD.printf("%c",spell);
rconnorlawson 0:35660d7952f7 201
rconnorlawson 0:35660d7952f7 202 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 203 }
rconnorlawson 0:35660d7952f7 204
rconnorlawson 0:35660d7952f7 205 void draw_border()
rconnorlawson 0:35660d7952f7 206 {
rconnorlawson 0:35660d7952f7 207 uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top
rconnorlawson 0:35660d7952f7 208 uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left
rconnorlawson 0:35660d7952f7 209 uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom
rconnorlawson 0:35660d7952f7 210 uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right
rconnorlawson 0:35660d7952f7 211 }
rconnorlawson 0:35660d7952f7 212
nasiromar 9:cbb9cfb1f6c5 213 void draw_start(){
nasiromar 9:cbb9cfb1f6c5 214 uLCD.text_width(2);
nasiromar 9:cbb9cfb1f6c5 215 uLCD.text_height(2);
nasiromar 9:cbb9cfb1f6c5 216 uLCD.color(BLUE);
nasiromar 10:e18685911e84 217 uLCD.locate(1,1);
nasiromar 9:cbb9cfb1f6c5 218 uLCD.printf("NASLAND");
nasiromar 9:cbb9cfb1f6c5 219 uLCD.color(YELLOW);
nasiromar 9:cbb9cfb1f6c5 220 uLCD.locate(2,2);
nasiromar 9:cbb9cfb1f6c5 221 uLCD.printf("QUEST");
nasiromar 6:c9695079521d 222
nasiromar 10:e18685911e84 223 uLCD.filled_rectangle(31,75,92,80,YELLOW);
nasiromar 10:e18685911e84 224 uLCD.filled_rectangle(35,70,88,75,RED);
nasiromar 10:e18685911e84 225 uLCD.filled_rectangle(38,65,85,70,YELLOW);
nasiromar 10:e18685911e84 226 uLCD.filled_rectangle(42,60,81,65,YELLOW);
nasiromar 10:e18685911e84 227 uLCD.filled_rectangle(49,55,74,60,YELLOW);
nasiromar 9:cbb9cfb1f6c5 228
nasiromar 9:cbb9cfb1f6c5 229
nasiromar 9:cbb9cfb1f6c5 230 uLCD.text_width(1);
nasiromar 9:cbb9cfb1f6c5 231 uLCD.text_height(1);
nasiromar 10:e18685911e84 232 uLCD.locate(4,12);
nasiromar 9:cbb9cfb1f6c5 233 uLCD.printf("Press action");
nasiromar 10:e18685911e84 234 uLCD.locate(2,13);
nasiromar 9:cbb9cfb1f6c5 235 uLCD.printf("button to begin");
nasiromar 9:cbb9cfb1f6c5 236 }