Game For ECE 2035

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
nasiromar
Date:
Fri Nov 19 22:03:25 2021 +0000
Revision:
6:c9695079521d
Parent:
4:37d3935365f8
Child:
7:862062ffca62
Basics

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"
lballard9 4:37d3935365f8 11 /*
lballard9 4:37d3935365f8 12 In this file put all your graphical functions (don't forget to declare them first
lballard9 4:37d3935365f8 13 in graphics.h). So when you want to draw something use this file. One cool function
lballard9 4:37d3935365f8 14 to look at would be uLCD.blit() there are more like filled_rectangle etc...
lballard9 4:37d3935365f8 15 https://os.mbed.com/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/
lballard9 4:37d3935365f8 16 This website is a good resource.
lballard9 4:37d3935365f8 17 */
rconnorlawson 0:35660d7952f7 18
rconnorlawson 0:35660d7952f7 19 void draw_player(int u, int v, int key)
rconnorlawson 0:35660d7952f7 20 {
nasiromar 6:c9695079521d 21
nasiromar 6:c9695079521d 22 uLCD.BLIT(u,v,11,11,main_char_arr);
nasiromar 6:c9695079521d 23 //.filled_rectangle(u, v, u+11, v+11, RED);
rconnorlawson 0:35660d7952f7 24 }
rconnorlawson 0:35660d7952f7 25
rconnorlawson 0:35660d7952f7 26 #define YELLOW 0xFFFF00
rconnorlawson 0:35660d7952f7 27 #define BROWN 0xD2691E
rconnorlawson 0:35660d7952f7 28 #define DIRT BROWN
rconnorlawson 0:35660d7952f7 29 void draw_img(int u, int v, const char* img)
rconnorlawson 0:35660d7952f7 30 {
rconnorlawson 0:35660d7952f7 31 int colors[11*11];
rconnorlawson 0:35660d7952f7 32 for (int i = 0; i < 11*11; i++)
rconnorlawson 0:35660d7952f7 33 {
rconnorlawson 0:35660d7952f7 34 if (img[i] == 'R') colors[i] = RED;
rconnorlawson 0:35660d7952f7 35 else if (img[i] == 'Y') colors[i] = YELLOW;
rconnorlawson 0:35660d7952f7 36 else if (img[i] == 'G') colors[i] = GREEN;
rconnorlawson 0:35660d7952f7 37 else if (img[i] == 'D') colors[i] = DIRT;
rconnorlawson 0:35660d7952f7 38 else if (img[i] == '5') colors[i] = LGREY;
rconnorlawson 0:35660d7952f7 39 else if (img[i] == '3') colors[i] = DGREY;
rconnorlawson 0:35660d7952f7 40 else colors[i] = BLACK;
rconnorlawson 0:35660d7952f7 41 }
rconnorlawson 0:35660d7952f7 42 uLCD.BLIT(u, v, 11, 11, colors);
rconnorlawson 0:35660d7952f7 43 wait_us(250); // Recovery time!
rconnorlawson 0:35660d7952f7 44 }
rconnorlawson 0:35660d7952f7 45
rconnorlawson 0:35660d7952f7 46 void draw_nothing(int u, int v)
rconnorlawson 0:35660d7952f7 47 {
rconnorlawson 0:35660d7952f7 48 // Fill a tile with blackness
rconnorlawson 0:35660d7952f7 49 uLCD.filled_rectangle(u, v, u+10, v+10, BLACK);
rconnorlawson 0:35660d7952f7 50 }
rconnorlawson 0:35660d7952f7 51
rconnorlawson 0:35660d7952f7 52 void draw_wall(int u, int v)
rconnorlawson 0:35660d7952f7 53 {
rconnorlawson 0:35660d7952f7 54 uLCD.filled_rectangle(u, v, u+10, v+10, BROWN);
rconnorlawson 0:35660d7952f7 55 }
rconnorlawson 0:35660d7952f7 56
rconnorlawson 0:35660d7952f7 57 void draw_plant(int u, int v)
rconnorlawson 0:35660d7952f7 58 {
nasiromar 6:c9695079521d 59 uLCD.BLIT(u,v,11,11,tree_arr);
nasiromar 6:c9695079521d 60 }
nasiromar 6:c9695079521d 61
nasiromar 6:c9695079521d 62 void draw_key(int u, int v)
nasiromar 6:c9695079521d 63 {
nasiromar 6:c9695079521d 64 uLCD.BLIT(u,v,11,11,key_arr);
nasiromar 6:c9695079521d 65 }
nasiromar 6:c9695079521d 66
nasiromar 6:c9695079521d 67 void draw_npc(int u, int v)
nasiromar 6:c9695079521d 68 {
nasiromar 6:c9695079521d 69 uLCD.BLIT(u,v,11,11,npc_arr);
nasiromar 6:c9695079521d 70 }
nasiromar 6:c9695079521d 71
nasiromar 6:c9695079521d 72 void draw_portal(int u, int v)
nasiromar 6:c9695079521d 73 {
nasiromar 6:c9695079521d 74 uLCD.BLIT(u,v,11,11,portal_arr);
rconnorlawson 0:35660d7952f7 75 }
rconnorlawson 0:35660d7952f7 76
nasiromar 6:c9695079521d 77 void draw_castle(int u, int v)
rconnorlawson 0:35660d7952f7 78 {
nasiromar 6:c9695079521d 79 uLCD.BLIT(u,v,11,11,castle_arr);
nasiromar 6:c9695079521d 80 }
nasiromar 6:c9695079521d 81
nasiromar 6:c9695079521d 82 void draw_chest(int u, int v){
nasiromar 6:c9695079521d 83 uLCD.BLIT(u,v,11,11,chest);
nasiromar 6:c9695079521d 84 }
nasiromar 6:c9695079521d 85
nasiromar 6:c9695079521d 86 void draw_upper_status(int player_x, int player_y)
nasiromar 6:c9695079521d 87 {
nasiromar 6:c9695079521d 88 uLCD.locate(0,0);
nasiromar 6:c9695079521d 89 uLCD.text_width(1);
nasiromar 6:c9695079521d 90 uLCD.text_height(1);
nasiromar 6:c9695079521d 91 uLCD.color(GREEN);
nasiromar 6:c9695079521d 92 uLCD.printf("X: [%2i] Y: [%2i]",player_x,player_y);
nasiromar 6:c9695079521d 93
rconnorlawson 0:35660d7952f7 94 // Draw bottom border of status bar
rconnorlawson 0:35660d7952f7 95
rconnorlawson 0:35660d7952f7 96 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 97 }
rconnorlawson 0:35660d7952f7 98
nasiromar 6:c9695079521d 99 void draw_lower_status(int hp, int mp)
nasiromar 6:c9695079521d 100 {
rconnorlawson 0:35660d7952f7 101 // Draw top border of status bar
nasiromar 6:c9695079521d 102 uLCD.locate(0,15);
nasiromar 6:c9695079521d 103 uLCD.text_width(1);
nasiromar 6:c9695079521d 104 uLCD.text_height(1);
nasiromar 6:c9695079521d 105 uLCD.color(GREEN);
nasiromar 6:c9695079521d 106 uLCD.printf("HP: %3i MP: %3i",hp,mp);
rconnorlawson 0:35660d7952f7 107
rconnorlawson 0:35660d7952f7 108 // Add other status info drawing code here
rconnorlawson 0:35660d7952f7 109 }
rconnorlawson 0:35660d7952f7 110
rconnorlawson 0:35660d7952f7 111 void draw_border()
rconnorlawson 0:35660d7952f7 112 {
rconnorlawson 0:35660d7952f7 113 uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top
rconnorlawson 0:35660d7952f7 114 uLCD.filled_rectangle(0, 13, 2, 114, WHITE); // Left
rconnorlawson 0:35660d7952f7 115 uLCD.filled_rectangle(0, 114, 127, 117, WHITE); // Bottom
rconnorlawson 0:35660d7952f7 116 uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right
rconnorlawson 0:35660d7952f7 117 }
rconnorlawson 0:35660d7952f7 118
nasiromar 6:c9695079521d 119
nasiromar 6:c9695079521d 120