Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
nasiromar
Date:
Thu Dec 02 06:24:22 2021 +0000
Revision:
11:6cd02a8539d1
Parent:
10:e18685911e84
Child:
14:7225da81314a
almost;

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 7:862062ffca62 63 uLCD.locate(6,6);
nasiromar 7:862062ffca62 64 uLCD.printf("GAME OVER");
nasiromar 7:862062ffca62 65 }
nasiromar 7:862062ffca62 66
nasiromar 7:862062ffca62 67
rconnorlawson 0:35660d7952f7 68 void draw_nothing(int u, int v)
rconnorlawson 0:35660d7952f7 69 {
rconnorlawson 0:35660d7952f7 70 // Fill a tile with blackness
rconnorlawson 0:35660d7952f7 71 uLCD.filled_rectangle(u, v, u+10, v+10, BLACK);
rconnorlawson 0:35660d7952f7 72 }
rconnorlawson 0:35660d7952f7 73
rconnorlawson 0:35660d7952f7 74 void draw_wall(int u, int v)
rconnorlawson 0:35660d7952f7 75 {
rconnorlawson 0:35660d7952f7 76 uLCD.filled_rectangle(u, v, u+10, v+10, BROWN);
rconnorlawson 0:35660d7952f7 77 }
rconnorlawson 0:35660d7952f7 78
rconnorlawson 0:35660d7952f7 79 void draw_plant(int u, int v)
rconnorlawson 0:35660d7952f7 80 {
nasiromar 6:c9695079521d 81 uLCD.BLIT(u,v,11,11,tree_arr);
nasiromar 6:c9695079521d 82 }
nasiromar 6:c9695079521d 83
nasiromar 6:c9695079521d 84 void draw_key(int u, int v)
nasiromar 6:c9695079521d 85 {
nasiromar 6:c9695079521d 86 uLCD.BLIT(u,v,11,11,key_arr);
nasiromar 6:c9695079521d 87 }
nasiromar 6:c9695079521d 88
nasiromar 11:6cd02a8539d1 89 void draw_fire(int u, int v)
nasiromar 11:6cd02a8539d1 90 {
nasiromar 11:6cd02a8539d1 91 uLCD.BLIT(u,v,11,11,fire_arr);
nasiromar 11:6cd02a8539d1 92 }
nasiromar 11:6cd02a8539d1 93
nasiromar 6:c9695079521d 94 void draw_npc(int u, int v)
nasiromar 6:c9695079521d 95 {
nasiromar 6:c9695079521d 96 uLCD.BLIT(u,v,11,11,npc_arr);
nasiromar 6:c9695079521d 97 }
nasiromar 6:c9695079521d 98
nasiromar 11:6cd02a8539d1 99 void draw_npc2(int u, int v)
nasiromar 11:6cd02a8539d1 100 {
nasiromar 11:6cd02a8539d1 101 uLCD.BLIT(u,v,11,11,npc2_arr);
nasiromar 11:6cd02a8539d1 102 }
nasiromar 11:6cd02a8539d1 103
nasiromar 11:6cd02a8539d1 104 void draw_goblin(int u, int v)
nasiromar 11:6cd02a8539d1 105 {
nasiromar 11:6cd02a8539d1 106 uLCD.BLIT(u,v,11,11,goblin_arr);
nasiromar 11:6cd02a8539d1 107 }
nasiromar 11:6cd02a8539d1 108
nasiromar 11:6cd02a8539d1 109 void draw_eye(int u, int v)
nasiromar 11:6cd02a8539d1 110 {
nasiromar 11:6cd02a8539d1 111 uLCD.BLIT(u,v,11,11,eye_arr);
nasiromar 11:6cd02a8539d1 112 }
nasiromar 11:6cd02a8539d1 113
nasiromar 11:6cd02a8539d1 114 void draw_store(int u, int v)
nasiromar 11:6cd02a8539d1 115 {
nasiromar 11:6cd02a8539d1 116 uLCD.BLIT(u,v,11,11,store_arr);
nasiromar 11:6cd02a8539d1 117 }
nasiromar 11:6cd02a8539d1 118
nasiromar 11:6cd02a8539d1 119 void draw_merch(int u, int v)
nasiromar 11:6cd02a8539d1 120 {
nasiromar 11:6cd02a8539d1 121 uLCD.BLIT(u,v,11,11,merch_arr);
nasiromar 11:6cd02a8539d1 122 }
nasiromar 11:6cd02a8539d1 123
nasiromar 11:6cd02a8539d1 124
nasiromar 6:c9695079521d 125 void draw_portal(int u, int v)
nasiromar 6:c9695079521d 126 {
nasiromar 6:c9695079521d 127 uLCD.BLIT(u,v,11,11,portal_arr);
rconnorlawson 0:35660d7952f7 128 }
rconnorlawson 0:35660d7952f7 129
nasiromar 7:862062ffca62 130 void draw_portal2(int u, int v)
nasiromar 7:862062ffca62 131 {
nasiromar 7:862062ffca62 132 uLCD.BLIT(u,v,11,11,portal2_arr);
nasiromar 7:862062ffca62 133 }
nasiromar 7:862062ffca62 134
nasiromar 6:c9695079521d 135 void draw_castle(int u, int v)
rconnorlawson 0:35660d7952f7 136 {
nasiromar 6:c9695079521d 137 uLCD.BLIT(u,v,11,11,castle_arr);
nasiromar 6:c9695079521d 138 }
nasiromar 6:c9695079521d 139
nasiromar 7:862062ffca62 140 void draw_kindom(int u, int v)
nasiromar 7:862062ffca62 141 {
nasiromar 7:862062ffca62 142 uLCD.BLIT(u,v,11,11,kindom_arr);
nasiromar 7:862062ffca62 143 }
nasiromar 7:862062ffca62 144
nasiromar 7:862062ffca62 145
nasiromar 7:862062ffca62 146 void draw_door(int u, int v){
nasiromar 7:862062ffca62 147 uLCD.BLIT(u,v,11,11,door_arr);
nasiromar 7:862062ffca62 148 }
nasiromar 7:862062ffca62 149
nasiromar 7:862062ffca62 150 void draw_dragon(int u, int v){
nasiromar 7:862062ffca62 151 uLCD.BLIT(u,v,11,11,dragon_arr);
nasiromar 7:862062ffca62 152 }
nasiromar 7:862062ffca62 153
nasiromar 6:c9695079521d 154 void draw_chest(int u, int v){
nasiromar 6:c9695079521d 155 uLCD.BLIT(u,v,11,11,chest);
nasiromar 6:c9695079521d 156 }
nasiromar 6:c9695079521d 157
nasiromar 7:862062ffca62 158
nasiromar 6:c9695079521d 159 void draw_upper_status(int player_x, int player_y)
nasiromar 6:c9695079521d 160 {
nasiromar 6:c9695079521d 161 uLCD.locate(0,0);
nasiromar 6:c9695079521d 162 uLCD.text_width(1);
nasiromar 6:c9695079521d 163 uLCD.text_height(1);
nasiromar 6:c9695079521d 164 uLCD.color(GREEN);
nasiromar 6:c9695079521d 165 uLCD.printf("X: [%2i] Y: [%2i]",player_x,player_y);
nasiromar 6:c9695079521d 166
rconnorlawson 0:35660d7952f7 167 // Draw bottom border of status bar
rconnorlawson 0:35660d7952f7 168
rconnorlawson 0:35660d7952f7 169 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 170 }
rconnorlawson 0:35660d7952f7 171
nasiromar 6:c9695079521d 172 void draw_lower_status(int hp, int mp)
nasiromar 6:c9695079521d 173 {
rconnorlawson 0:35660d7952f7 174 // Draw top border of status bar
nasiromar 6:c9695079521d 175 uLCD.locate(0,15);
nasiromar 6:c9695079521d 176 uLCD.text_width(1);
nasiromar 6:c9695079521d 177 uLCD.text_height(1);
nasiromar 6:c9695079521d 178 uLCD.color(GREEN);
nasiromar 6:c9695079521d 179 uLCD.printf("HP: %3i MP: %3i",hp,mp);
rconnorlawson 0:35660d7952f7 180
rconnorlawson 0:35660d7952f7 181 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 182 }
rconnorlawson 0:35660d7952f7 183
rconnorlawson 0:35660d7952f7 184 void draw_border()
rconnorlawson 0:35660d7952f7 185 {
rconnorlawson 0:35660d7952f7 186 uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top
rconnorlawson 0:35660d7952f7 187 uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left
rconnorlawson 0:35660d7952f7 188 uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom
rconnorlawson 0:35660d7952f7 189 uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right
rconnorlawson 0:35660d7952f7 190 }
rconnorlawson 0:35660d7952f7 191
nasiromar 9:cbb9cfb1f6c5 192 void draw_start(){
nasiromar 9:cbb9cfb1f6c5 193 uLCD.text_width(2);
nasiromar 9:cbb9cfb1f6c5 194 uLCD.text_height(2);
nasiromar 9:cbb9cfb1f6c5 195 uLCD.color(BLUE);
nasiromar 10:e18685911e84 196 uLCD.locate(1,1);
nasiromar 9:cbb9cfb1f6c5 197 uLCD.printf("NASLAND");
nasiromar 9:cbb9cfb1f6c5 198 uLCD.color(YELLOW);
nasiromar 9:cbb9cfb1f6c5 199 uLCD.locate(2,2);
nasiromar 9:cbb9cfb1f6c5 200 uLCD.printf("QUEST");
nasiromar 6:c9695079521d 201
nasiromar 10:e18685911e84 202 uLCD.filled_rectangle(31,75,92,80,YELLOW);
nasiromar 10:e18685911e84 203 uLCD.filled_rectangle(35,70,88,75,RED);
nasiromar 10:e18685911e84 204 uLCD.filled_rectangle(38,65,85,70,YELLOW);
nasiromar 10:e18685911e84 205 uLCD.filled_rectangle(42,60,81,65,YELLOW);
nasiromar 10:e18685911e84 206 uLCD.filled_rectangle(49,55,74,60,YELLOW);
nasiromar 9:cbb9cfb1f6c5 207
nasiromar 9:cbb9cfb1f6c5 208
nasiromar 9:cbb9cfb1f6c5 209 uLCD.text_width(1);
nasiromar 9:cbb9cfb1f6c5 210 uLCD.text_height(1);
nasiromar 10:e18685911e84 211 uLCD.locate(4,12);
nasiromar 9:cbb9cfb1f6c5 212 uLCD.printf("Press action");
nasiromar 10:e18685911e84 213 uLCD.locate(2,13);
nasiromar 9:cbb9cfb1f6c5 214 uLCD.printf("button to begin");
nasiromar 9:cbb9cfb1f6c5 215 }