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 wave_player 4DGL-uLCD-SE MMA8452
graphics.cpp
00001 #include "graphics.h" 00002 00003 #include "globals.h" 00004 #include "main_char.cpp" 00005 #include "chest.cpp" 00006 #include "castle.cpp" 00007 #include "key.cpp" 00008 #include "portal.cpp" 00009 #include "tree.cpp" 00010 #include "npc.cpp" 00011 #include "door.cpp" 00012 #include "dragon.cpp" 00013 #include "portal2.cpp" 00014 #include "kindom.cpp" 00015 #include "eye.cpp" 00016 #include "merch.cpp" 00017 #include "goblin.cpp" 00018 #include "store.cpp" 00019 #include "npc2.cpp" 00020 #include "fire.cpp" 00021 00022 /* 00023 In this file put all your graphical functions (don't forget to declare them first 00024 in graphics.h). So when you want to draw something use this file. One cool function 00025 to look at would be uLCD.blit() there are more like filled_rectangle etc... 00026 https://os.mbed.com/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ 00027 This website is a good resource. 00028 */ 00029 00030 void draw_player(int u, int v, int key) 00031 { 00032 00033 uLCD.BLIT(u,v,11,11,main_char_arr); 00034 //.filled_rectangle(u, v, u+11, v+11, RED); 00035 } 00036 00037 #define YELLOW 0xFFFF00 00038 #define BROWN 0xD2691E 00039 #define BLUE 0x0000FF 00040 #define DIRT BROWN 00041 void draw_img(int u, int v, const char* img) 00042 { 00043 int colors[11*11]; 00044 for (int i = 0; i < 11*11; i++) 00045 { 00046 if (img[i] == 'R') colors[i] = RED; 00047 else if (img[i] == 'Y') colors[i] = YELLOW; 00048 else if (img[i] == 'G') colors[i] = GREEN; 00049 else if (img[i] == 'D') colors[i] = DIRT; 00050 else if (img[i] == '5') colors[i] = LGREY; 00051 else if (img[i] == '3') colors[i] = DGREY; 00052 else colors[i] = BLACK; 00053 } 00054 uLCD.BLIT(u, v, 11, 11, colors); 00055 wait_us(250); // Recovery time! 00056 } 00057 00058 00059 void draw_gameover(){ 00060 uLCD.filled_rectangle(0,0,127,127, BLACK); 00061 uLCD.set_font(FONT_8X8); 00062 uLCD.text_mode(OPAQUE); 00063 uLCD.locate(5,6); 00064 uLCD.printf("GAME OVER"); 00065 } 00066 00067 void draw_win(){ 00068 uLCD.filled_rectangle(0,0,127,127, BLACK); 00069 uLCD.set_font(FONT_8X8); 00070 uLCD.text_mode(OPAQUE); 00071 uLCD.color(BLUE); 00072 uLCD.locate(5,6); 00073 uLCD.printf("YOU WIN"); 00074 } 00075 00076 00077 void draw_nothing(int u, int v) 00078 { 00079 // Fill a tile with blackness 00080 uLCD.filled_rectangle(u, v, u+10, v+10, BLACK); 00081 } 00082 00083 void draw_wall(int u, int v) 00084 { 00085 uLCD.filled_rectangle(u, v, u+10, v+10, BROWN); 00086 } 00087 00088 void draw_plant(int u, int v) 00089 { 00090 uLCD.BLIT(u,v,11,11,tree_arr); 00091 } 00092 00093 void draw_key(int u, int v) 00094 { 00095 uLCD.BLIT(u,v,11,11,key_arr); 00096 } 00097 00098 void draw_fire(int u, int v) 00099 { 00100 uLCD.BLIT(u,v,11,11,fire_arr); 00101 } 00102 00103 void draw_npc(int u, int v) 00104 { 00105 uLCD.BLIT(u,v,11,11,npc_arr); 00106 } 00107 00108 void draw_npc2(int u, int v) 00109 { 00110 uLCD.BLIT(u,v,11,11,npc2_arr); 00111 } 00112 00113 void draw_goblin(int u, int v) 00114 { 00115 uLCD.BLIT(u,v,11,11,goblin_arr); 00116 } 00117 00118 void draw_eye(int u, int v) 00119 { 00120 uLCD.BLIT(u,v,11,11,eye_arr); 00121 } 00122 00123 void draw_store(int u, int v) 00124 { 00125 uLCD.BLIT(u,v,11,11,store_arr); 00126 } 00127 00128 void draw_merch(int u, int v) 00129 { 00130 uLCD.BLIT(u,v,11,11,merch_arr); 00131 } 00132 00133 00134 void draw_portal(int u, int v) 00135 { 00136 uLCD.BLIT(u,v,11,11,portal_arr); 00137 } 00138 00139 void draw_portal2(int u, int v) 00140 { 00141 uLCD.BLIT(u,v,11,11,portal2_arr); 00142 } 00143 00144 void draw_castle(int u, int v) 00145 { 00146 uLCD.BLIT(u,v,11,11,castle_arr); 00147 } 00148 00149 void draw_kindom(int u, int v) 00150 { 00151 uLCD.BLIT(u,v,11,11,kindom_arr); 00152 } 00153 00154 00155 void draw_door(int u, int v){ 00156 uLCD.BLIT(u,v,11,11,door_arr); 00157 } 00158 00159 void draw_dragon(int u, int v){ 00160 uLCD.BLIT(u,v,11,11,dragon_arr); 00161 } 00162 00163 void draw_chest(int u, int v){ 00164 uLCD.BLIT(u,v,11,11,chest); 00165 } 00166 00167 00168 void draw_upper_status(int player_x, int player_y, int coin) 00169 { 00170 uLCD.locate(0,0); 00171 uLCD.text_width(1); 00172 uLCD.text_height(1); 00173 uLCD.color(GREEN); 00174 uLCD.printf("X:[%2i] Y:[%2i] $:%1i",player_x,player_y,coin); 00175 00176 // Draw bottom border of status bar 00177 00178 // Add other status info drawing code here 00179 } 00180 00181 void draw_lower_status(int hp, int mp) 00182 { 00183 // Draw top border of status bar 00184 uLCD.locate(0,15); 00185 uLCD.text_width(1); 00186 uLCD.text_height(1); 00187 uLCD.color(GREEN); 00188 uLCD.printf("HP:%3i MP:%3i",hp,mp); 00189 00190 // Add other status info drawing code here 00191 } 00192 00193 void draw_spell(char spell) 00194 { 00195 // Draw top border of status bar 00196 uLCD.locate(16,15); 00197 uLCD.text_width(1); 00198 uLCD.text_height(1); 00199 uLCD.color(GREEN); 00200 uLCD.printf("%c",spell); 00201 00202 // Add other status info drawing code here 00203 } 00204 00205 void draw_border() 00206 { 00207 uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top 00208 uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left 00209 uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom 00210 uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right 00211 } 00212 00213 void draw_start(){ 00214 uLCD.text_width(2); 00215 uLCD.text_height(2); 00216 uLCD.color(BLUE); 00217 uLCD.locate(1,1); 00218 uLCD.printf("NASLAND"); 00219 uLCD.color(YELLOW); 00220 uLCD.locate(2,2); 00221 uLCD.printf("QUEST"); 00222 00223 uLCD.filled_rectangle(31,75,92,80,YELLOW); 00224 uLCD.filled_rectangle(35,70,88,75,RED); 00225 uLCD.filled_rectangle(38,65,85,70,YELLOW); 00226 uLCD.filled_rectangle(42,60,81,65,YELLOW); 00227 uLCD.filled_rectangle(49,55,74,60,YELLOW); 00228 00229 00230 uLCD.text_width(1); 00231 uLCD.text_height(1); 00232 uLCD.locate(4,12); 00233 uLCD.printf("Press action"); 00234 uLCD.locate(2,13); 00235 uLCD.printf("button to begin"); 00236 }
Generated on Wed Jul 27 2022 10:35:26 by
