Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
nasiromar
Date:
Wed Dec 01 22:07:24 2021 +0000
Revision:
10:e18685911e84
Parent:
9:cbb9cfb1f6c5
Child:
11:6cd02a8539d1
Walk;

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 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
nasiromar 9:cbb9cfb1f6c5 33 #define BLUE 0x0000FF
rconnorlawson 0:35660d7952f7 34 #define DIRT BROWN
rconnorlawson 0:35660d7952f7 35 void draw_img(int u, int v, const char* img)
rconnorlawson 0:35660d7952f7 36 {
rconnorlawson 0:35660d7952f7 37 int colors[11*11];
rconnorlawson 0:35660d7952f7 38 for (int i = 0; i < 11*11; i++)
rconnorlawson 0:35660d7952f7 39 {
rconnorlawson 0:35660d7952f7 40 if (img[i] == 'R') colors[i] = RED;
rconnorlawson 0:35660d7952f7 41 else if (img[i] == 'Y') colors[i] = YELLOW;
rconnorlawson 0:35660d7952f7 42 else if (img[i] == 'G') colors[i] = GREEN;
rconnorlawson 0:35660d7952f7 43 else if (img[i] == 'D') colors[i] = DIRT;
rconnorlawson 0:35660d7952f7 44 else if (img[i] == '5') colors[i] = LGREY;
rconnorlawson 0:35660d7952f7 45 else if (img[i] == '3') colors[i] = DGREY;
rconnorlawson 0:35660d7952f7 46 else colors[i] = BLACK;
rconnorlawson 0:35660d7952f7 47 }
rconnorlawson 0:35660d7952f7 48 uLCD.BLIT(u, v, 11, 11, colors);
rconnorlawson 0:35660d7952f7 49 wait_us(250); // Recovery time!
rconnorlawson 0:35660d7952f7 50 }
rconnorlawson 0:35660d7952f7 51
nasiromar 7:862062ffca62 52
nasiromar 7:862062ffca62 53 void draw_gameover(){
nasiromar 7:862062ffca62 54 uLCD.filled_rectangle(0,0,127,127, BLACK);
nasiromar 7:862062ffca62 55 uLCD.set_font(FONT_8X8);
nasiromar 7:862062ffca62 56 uLCD.text_mode(OPAQUE);
nasiromar 7:862062ffca62 57 uLCD.locate(6,6);
nasiromar 7:862062ffca62 58 uLCD.printf("GAME OVER");
nasiromar 7:862062ffca62 59 }
nasiromar 7:862062ffca62 60
nasiromar 7:862062ffca62 61
rconnorlawson 0:35660d7952f7 62 void draw_nothing(int u, int v)
rconnorlawson 0:35660d7952f7 63 {
rconnorlawson 0:35660d7952f7 64 // Fill a tile with blackness
rconnorlawson 0:35660d7952f7 65 uLCD.filled_rectangle(u, v, u+10, v+10, BLACK);
rconnorlawson 0:35660d7952f7 66 }
rconnorlawson 0:35660d7952f7 67
rconnorlawson 0:35660d7952f7 68 void draw_wall(int u, int v)
rconnorlawson 0:35660d7952f7 69 {
rconnorlawson 0:35660d7952f7 70 uLCD.filled_rectangle(u, v, u+10, v+10, BROWN);
rconnorlawson 0:35660d7952f7 71 }
rconnorlawson 0:35660d7952f7 72
rconnorlawson 0:35660d7952f7 73 void draw_plant(int u, int v)
rconnorlawson 0:35660d7952f7 74 {
nasiromar 6:c9695079521d 75 uLCD.BLIT(u,v,11,11,tree_arr);
nasiromar 6:c9695079521d 76 }
nasiromar 6:c9695079521d 77
nasiromar 6:c9695079521d 78 void draw_key(int u, int v)
nasiromar 6:c9695079521d 79 {
nasiromar 6:c9695079521d 80 uLCD.BLIT(u,v,11,11,key_arr);
nasiromar 6:c9695079521d 81 }
nasiromar 6:c9695079521d 82
nasiromar 6:c9695079521d 83 void draw_npc(int u, int v)
nasiromar 6:c9695079521d 84 {
nasiromar 6:c9695079521d 85 uLCD.BLIT(u,v,11,11,npc_arr);
nasiromar 6:c9695079521d 86 }
nasiromar 6:c9695079521d 87
nasiromar 6:c9695079521d 88 void draw_portal(int u, int v)
nasiromar 6:c9695079521d 89 {
nasiromar 6:c9695079521d 90 uLCD.BLIT(u,v,11,11,portal_arr);
rconnorlawson 0:35660d7952f7 91 }
rconnorlawson 0:35660d7952f7 92
nasiromar 7:862062ffca62 93 void draw_portal2(int u, int v)
nasiromar 7:862062ffca62 94 {
nasiromar 7:862062ffca62 95 uLCD.BLIT(u,v,11,11,portal2_arr);
nasiromar 7:862062ffca62 96 }
nasiromar 7:862062ffca62 97
nasiromar 6:c9695079521d 98 void draw_castle(int u, int v)
rconnorlawson 0:35660d7952f7 99 {
nasiromar 6:c9695079521d 100 uLCD.BLIT(u,v,11,11,castle_arr);
nasiromar 6:c9695079521d 101 }
nasiromar 6:c9695079521d 102
nasiromar 7:862062ffca62 103 void draw_kindom(int u, int v)
nasiromar 7:862062ffca62 104 {
nasiromar 7:862062ffca62 105 uLCD.BLIT(u,v,11,11,kindom_arr);
nasiromar 7:862062ffca62 106 }
nasiromar 7:862062ffca62 107
nasiromar 7:862062ffca62 108
nasiromar 7:862062ffca62 109 void draw_door(int u, int v){
nasiromar 7:862062ffca62 110 uLCD.BLIT(u,v,11,11,door_arr);
nasiromar 7:862062ffca62 111 }
nasiromar 7:862062ffca62 112
nasiromar 7:862062ffca62 113 void draw_dragon(int u, int v){
nasiromar 7:862062ffca62 114 uLCD.BLIT(u,v,11,11,dragon_arr);
nasiromar 7:862062ffca62 115 }
nasiromar 7:862062ffca62 116
nasiromar 6:c9695079521d 117 void draw_chest(int u, int v){
nasiromar 6:c9695079521d 118 uLCD.BLIT(u,v,11,11,chest);
nasiromar 6:c9695079521d 119 }
nasiromar 6:c9695079521d 120
nasiromar 7:862062ffca62 121
nasiromar 6:c9695079521d 122 void draw_upper_status(int player_x, int player_y)
nasiromar 6:c9695079521d 123 {
nasiromar 6:c9695079521d 124 uLCD.locate(0,0);
nasiromar 6:c9695079521d 125 uLCD.text_width(1);
nasiromar 6:c9695079521d 126 uLCD.text_height(1);
nasiromar 6:c9695079521d 127 uLCD.color(GREEN);
nasiromar 6:c9695079521d 128 uLCD.printf("X: [%2i] Y: [%2i]",player_x,player_y);
nasiromar 6:c9695079521d 129
rconnorlawson 0:35660d7952f7 130 // Draw bottom border of status bar
rconnorlawson 0:35660d7952f7 131
rconnorlawson 0:35660d7952f7 132 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 133 }
rconnorlawson 0:35660d7952f7 134
nasiromar 6:c9695079521d 135 void draw_lower_status(int hp, int mp)
nasiromar 6:c9695079521d 136 {
rconnorlawson 0:35660d7952f7 137 // Draw top border of status bar
nasiromar 6:c9695079521d 138 uLCD.locate(0,15);
nasiromar 6:c9695079521d 139 uLCD.text_width(1);
nasiromar 6:c9695079521d 140 uLCD.text_height(1);
nasiromar 6:c9695079521d 141 uLCD.color(GREEN);
nasiromar 6:c9695079521d 142 uLCD.printf("HP: %3i MP: %3i",hp,mp);
rconnorlawson 0:35660d7952f7 143
rconnorlawson 0:35660d7952f7 144 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 145 }
rconnorlawson 0:35660d7952f7 146
rconnorlawson 0:35660d7952f7 147 void draw_border()
rconnorlawson 0:35660d7952f7 148 {
rconnorlawson 0:35660d7952f7 149 uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top
rconnorlawson 0:35660d7952f7 150 uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left
rconnorlawson 0:35660d7952f7 151 uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom
rconnorlawson 0:35660d7952f7 152 uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right
rconnorlawson 0:35660d7952f7 153 }
rconnorlawson 0:35660d7952f7 154
nasiromar 9:cbb9cfb1f6c5 155 void draw_start(){
nasiromar 9:cbb9cfb1f6c5 156 uLCD.text_width(2);
nasiromar 9:cbb9cfb1f6c5 157 uLCD.text_height(2);
nasiromar 9:cbb9cfb1f6c5 158 uLCD.color(BLUE);
nasiromar 10:e18685911e84 159 uLCD.locate(1,1);
nasiromar 9:cbb9cfb1f6c5 160 uLCD.printf("NASLAND");
nasiromar 9:cbb9cfb1f6c5 161 uLCD.color(YELLOW);
nasiromar 9:cbb9cfb1f6c5 162 uLCD.locate(2,2);
nasiromar 9:cbb9cfb1f6c5 163 uLCD.printf("QUEST");
nasiromar 6:c9695079521d 164
nasiromar 10:e18685911e84 165 uLCD.filled_rectangle(31,75,92,80,YELLOW);
nasiromar 10:e18685911e84 166 uLCD.filled_rectangle(35,70,88,75,RED);
nasiromar 10:e18685911e84 167 uLCD.filled_rectangle(38,65,85,70,YELLOW);
nasiromar 10:e18685911e84 168 uLCD.filled_rectangle(42,60,81,65,YELLOW);
nasiromar 10:e18685911e84 169 uLCD.filled_rectangle(49,55,74,60,YELLOW);
nasiromar 9:cbb9cfb1f6c5 170
nasiromar 9:cbb9cfb1f6c5 171
nasiromar 9:cbb9cfb1f6c5 172 uLCD.text_width(1);
nasiromar 9:cbb9cfb1f6c5 173 uLCD.text_height(1);
nasiromar 10:e18685911e84 174 uLCD.locate(4,12);
nasiromar 9:cbb9cfb1f6c5 175 uLCD.printf("Press action");
nasiromar 10:e18685911e84 176 uLCD.locate(2,13);
nasiromar 9:cbb9cfb1f6c5 177 uLCD.printf("button to begin");
nasiromar 9:cbb9cfb1f6c5 178 }