
hgftf
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
graphics.cpp@9:d09b96b6c39c, 2020-11-20 (annotated)
- Committer:
- ajorgih3
- Date:
- Fri Nov 20 21:58:45 2020 +0000
- Revision:
- 9:d09b96b6c39c
- Parent:
- 7:7ab2f4b09196
yes;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DCchico | 2:4947d6a82971 | 1 | // Copyright 2020 Georgia Tech. All rights reserved. |
DCchico | 2:4947d6a82971 | 2 | // The materials provided by the instructor in this course are for |
DCchico | 2:4947d6a82971 | 3 | // the use of the students currently enrolled in the course. |
DCchico | 2:4947d6a82971 | 4 | // Copyrighted course materials may not be further disseminated. |
DCchico | 2:4947d6a82971 | 5 | // This file must not be made publicly available anywhere. |
DCchico | 2:4947d6a82971 | 6 | |
DCchico | 1:10330bce85cb | 7 | #include "graphics.h" |
DCchico | 1:10330bce85cb | 8 | |
DCchico | 1:10330bce85cb | 9 | #include "globals.h" |
DCchico | 1:10330bce85cb | 10 | |
DCchico | 1:10330bce85cb | 11 | void draw_nothing(int u, int v) |
DCchico | 1:10330bce85cb | 12 | { |
DCchico | 1:10330bce85cb | 13 | uLCD.filled_rectangle(u, v, u+10, v+10, BLACK); |
DCchico | 1:10330bce85cb | 14 | } |
DCchico | 1:10330bce85cb | 15 | |
DCchico | 1:10330bce85cb | 16 | void draw_img(int u, int v, const char* img) |
DCchico | 1:10330bce85cb | 17 | { |
DCchico | 1:10330bce85cb | 18 | int colors[11*11]; |
DCchico | 1:10330bce85cb | 19 | for (int i = 0; i < 11*11; i++) |
DCchico | 1:10330bce85cb | 20 | { |
DCchico | 1:10330bce85cb | 21 | if (img[i] == 'R') colors[i] = RED; |
DCchico | 1:10330bce85cb | 22 | else if (img[i] == 'Y') colors[i] = 0xFFFF00; // Yellow |
DCchico | 1:10330bce85cb | 23 | else if (img[i] == 'G') colors[i] = GREEN; |
ajorgih3 | 3:bb6f73642f01 | 24 | else if (img[i] == 'T') colors[i] = 0x008080; |
ajorgih3 | 3:bb6f73642f01 | 25 | else if (img[i] == 'Q') colors[i] = 0xFFFFFF; |
ajorgih3 | 3:bb6f73642f01 | 26 | else if (img[i] == 'S') colors[i] = 0x0000FF; |
ajorgih3 | 3:bb6f73642f01 | 27 | else if (img[i] == 'M') colors[i] = 0xFFD700; |
DCchico | 1:10330bce85cb | 28 | else if (img[i] == 'D') colors[i] = 0xD2691E; // "Dirt" |
ajorgih3 | 3:bb6f73642f01 | 29 | else if (img[i] == 'C') colors[i] = 0x84563C; |
ajorgih3 | 9:d09b96b6c39c | 30 | else if (img[i] == 'L') colors[i] = 0xADD8E6; |
DCchico | 1:10330bce85cb | 31 | else if (img[i] == '5') colors[i] = LGREY; // 50% grey |
DCchico | 1:10330bce85cb | 32 | else if (img[i] == '3') colors[i] = DGREY; |
DCchico | 1:10330bce85cb | 33 | else colors[i] = BLACK; |
DCchico | 1:10330bce85cb | 34 | } |
DCchico | 1:10330bce85cb | 35 | uLCD.BLIT(u, v, 11, 11, colors); |
DCchico | 1:10330bce85cb | 36 | wait_us(250); // Recovery time! |
DCchico | 1:10330bce85cb | 37 | } |
DCchico | 1:10330bce85cb | 38 | |
DCchico | 1:10330bce85cb | 39 | void draw_wall(int u, int v) |
DCchico | 1:10330bce85cb | 40 | { |
ajorgih3 | 3:bb6f73642f01 | 41 | uLCD.filled_rectangle(u, v, u+10, v+10, LGREY); |
ajorgih3 | 3:bb6f73642f01 | 42 | uLCD.filled_rectangle(u, v, u+1, v, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 43 | uLCD.filled_rectangle(u+3, v, u+4, v, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 44 | uLCD.filled_rectangle(u+6, v, u+7, v, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 45 | uLCD.filled_rectangle(u+9, v, u+10, v, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 46 | uLCD.filled_rectangle(u, v+2, u+1, v+2, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 47 | uLCD.filled_rectangle(u+3, v+2, u+4, v+2, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 48 | uLCD.filled_rectangle(u+6, v+2, u+7, v+2, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 49 | uLCD.filled_rectangle(u+9, v+2, u+10, v+2, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 50 | uLCD.filled_rectangle(u, v+4, u+1, v+4, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 51 | uLCD.filled_rectangle(u+3, v+4, u+4, v+4, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 52 | uLCD.filled_rectangle(u+6, v+4, u+7, v+4, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 53 | uLCD.filled_rectangle(u+9, v+4, u+10, v+4, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 54 | uLCD.filled_rectangle(u, v+6, u+1, v+6, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 55 | uLCD.filled_rectangle(u+3, v+6, u+4, v+6, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 56 | uLCD.filled_rectangle(u+6, v+6, u+7, v+6, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 57 | uLCD.filled_rectangle(u+9, v+6, u+10, v+6, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 58 | uLCD.filled_rectangle(u, v+8, u+1, v+8, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 59 | uLCD.filled_rectangle(u+3, v+8, u+4, v+8, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 60 | uLCD.filled_rectangle(u+6, v+8, u+7, v+8, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 61 | uLCD.filled_rectangle(u+9, v+8, u+10, v+8, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 62 | uLCD.filled_rectangle(u, v+10, u+1, v+10, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 63 | uLCD.filled_rectangle(u+3, v+10, u+4, v+10, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 64 | uLCD.filled_rectangle(u+6, v+10, u+7, v+10, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 65 | uLCD.filled_rectangle(u+9, v+10, u+10, v+10, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 66 | |
DCchico | 1:10330bce85cb | 67 | } |
DCchico | 1:10330bce85cb | 68 | |
DCchico | 1:10330bce85cb | 69 | void draw_plant(int u, int v) |
DCchico | 1:10330bce85cb | 70 | { |
ajorgih3 | 3:bb6f73642f01 | 71 | char plant[122] = "BGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGBGGGGGGGGGBBBGGGGGGGBBBBBBMMMBBBBBBBBMMMBBBBBDDDDDDDDDBBBDDDDDDDBBBBBDDDDDBBBBBBBDDDBBBB"; |
ajorgih3 | 3:bb6f73642f01 | 72 | draw_img(u, v, plant); |
DCchico | 1:10330bce85cb | 73 | } |
DCchico | 1:10330bce85cb | 74 | |
DCchico | 1:10330bce85cb | 75 | void draw_goodie(int u, int v) |
DCchico | 1:10330bce85cb | 76 | { |
ajorgih3 | 3:bb6f73642f01 | 77 | uLCD.filled_rectangle(u, v, u+10, v+10, 0xD9BE91); |
ajorgih3 | 3:bb6f73642f01 | 78 | //uLCD.filled_rectangle(u, v, u, v, 0xFFFF00);zzzz |
ajorgih3 | 3:bb6f73642f01 | 79 | uLCD.filled_rectangle(u+1, v+1, u+4, v+3, 0xFFD700); |
ajorgih3 | 3:bb6f73642f01 | 80 | uLCD.filled_rectangle(u+6, v+1, u+9, v+3, 0xFFD700); |
ajorgih3 | 3:bb6f73642f01 | 81 | uLCD.filled_rectangle(u+1, v+7, u+4, v+9, 0xFFD700); |
ajorgih3 | 3:bb6f73642f01 | 82 | uLCD.filled_rectangle(u+6, v+7, u+9, v+9, 0xFFD700); |
ajorgih3 | 3:bb6f73642f01 | 83 | //uLCD.filled_rectangle(u+4, v+4, u+2, v+2, 0xFFFFFF); |
DCchico | 1:10330bce85cb | 84 | } |
DCchico | 1:10330bce85cb | 85 | |
DCchico | 1:10330bce85cb | 86 | void draw_snake_body(int u, int v) |
DCchico | 1:10330bce85cb | 87 | { |
DCchico | 1:10330bce85cb | 88 | uLCD.filled_rectangle(u, v, u+10, v+10, GREEN); |
DCchico | 1:10330bce85cb | 89 | } |
DCchico | 1:10330bce85cb | 90 | |
DCchico | 1:10330bce85cb | 91 | void draw_snake_head(int u, int v) |
DCchico | 1:10330bce85cb | 92 | { |
DCchico | 1:10330bce85cb | 93 | //May need to design a snake head sprite |
DCchico | 1:10330bce85cb | 94 | //Tile still need to be designed on paper |
DCchico | 1:10330bce85cb | 95 | |
DCchico | 1:10330bce85cb | 96 | uLCD.filled_rectangle(u, v, u+10, v+10, GREEN); |
ajorgih3 | 3:bb6f73642f01 | 97 | uLCD.filled_rectangle(u+1, v+1, u+3, v+1, RED); |
ajorgih3 | 3:bb6f73642f01 | 98 | uLCD.filled_rectangle(u+7, v+1, u+9, v+1, RED); |
ajorgih3 | 3:bb6f73642f01 | 99 | uLCD.filled_rectangle(u+1, v+3, u+3, v+4, RED); |
ajorgih3 | 3:bb6f73642f01 | 100 | uLCD.filled_rectangle(u+7, v+3, u+9, v+4, RED); |
ajorgih3 | 3:bb6f73642f01 | 101 | uLCD.filled_rectangle(u+1, v+7, u+3, v+9, RED); |
ajorgih3 | 3:bb6f73642f01 | 102 | uLCD.filled_rectangle(u+7, v+7, u+9, v+9, RED); |
DCchico | 1:10330bce85cb | 103 | } |
DCchico | 1:10330bce85cb | 104 | |
DCchico | 1:10330bce85cb | 105 | void draw_snake_tail(int u, int v) |
DCchico | 1:10330bce85cb | 106 | { |
DCchico | 1:10330bce85cb | 107 | //May need to design a snake tail sprite |
DCchico | 1:10330bce85cb | 108 | //Tile still need to be designed on paper |
DCchico | 1:10330bce85cb | 109 | uLCD.filled_rectangle(u, v, u+10, v+10, GREEN); |
ajorgih3 | 3:bb6f73642f01 | 110 | uLCD.filled_rectangle(u+1, v+1, u+3, v+3, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 111 | uLCD.filled_rectangle(u+7, v+1, u+9, v+3, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 112 | uLCD.filled_rectangle(u+1, v+7, u+3, v+9, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 113 | uLCD.filled_rectangle(u+7, v+7, u+9, v+9, 0xFFFF00); |
ajorgih3 | 3:bb6f73642f01 | 114 | |
ajorgih3 | 3:bb6f73642f01 | 115 | } |
ajorgih3 | 3:bb6f73642f01 | 116 | |
ajorgih3 | 3:bb6f73642f01 | 117 | void draw_shield(int u, int v) |
ajorgih3 | 3:bb6f73642f01 | 118 | { |
ajorgih3 | 3:bb6f73642f01 | 119 | char shield[122] = "QQQQQQQQQQQQBBBBBBBBBQQBSSSSSSSBQQBQBBBBBQBQQBQBQQQBQBQQBBQBBBQBBQBQBBQQQBBQBBBQBBBBBQBBBBBQQQQQBBBBBBBBBBBBBBBBBBBBBBBBB"; |
ajorgih3 | 3:bb6f73642f01 | 120 | draw_img(u, v, shield); |
ajorgih3 | 3:bb6f73642f01 | 121 | } |
ajorgih3 | 3:bb6f73642f01 | 122 | |
ajorgih3 | 3:bb6f73642f01 | 123 | void draw_life(int u, int v) { |
ajorgih3 | 3:bb6f73642f01 | 124 | char life[122] = "BBBBBBBBBBBBBRRRBBRRRBBRRRRBRRRRRBRRRRRRRRRRBRRRRRRRRRRBRRRRRRRRRBBBRRRRRRRBBBBBRRRRRBBBBBBBRRRBBBBBBBBBBBBBBBBBBBBBBBBBB"; |
ajorgih3 | 3:bb6f73642f01 | 125 | draw_img(u, v, life); |
ajorgih3 | 3:bb6f73642f01 | 126 | } |
ajorgih3 | 3:bb6f73642f01 | 127 | |
ajorgih3 | 3:bb6f73642f01 | 128 | void draw_snowflake(int u, int v) { |
ajorgih3 | 3:bb6f73642f01 | 129 | char snowflake[122] = "BBBBBQBBBBBQBBBBQBBBBQBBQBBQBBQBBBQQBQBQBQQBBBBQQQQQBBBQQQBQBQBQQQBBBQQQQQBBBBQQBQBQBQQBBBQBBQBBQBBQBBBBQBBBBQBBBBBQBBBBB"; |
ajorgih3 | 3:bb6f73642f01 | 130 | draw_img(u, v, snowflake); |
ajorgih3 | 3:bb6f73642f01 | 131 | } |
ajorgih3 | 3:bb6f73642f01 | 132 | void draw_sword(int u, int v) { |
ajorgih3 | 3:bb6f73642f01 | 133 | char sword[122] = "BBBBBBBBBBB55BBBBBBBBB5Q5BBBBBBBBB5Q5BBBBBBBBB5Q5BBBBBBBBB5Q5DDBBBBBBB33DBBBBBBBBDDMBBBBBBBBDBBMBBBBBBBBBBBMBB"; |
ajorgih3 | 3:bb6f73642f01 | 134 | draw_img(u, v, sword); |
DCchico | 1:10330bce85cb | 135 | } |
ajorgih3 | 4:697e1120f821 | 136 | void draw_arrow_up(int u, int v) { |
ajorgih3 | 4:697e1120f821 | 137 | char arrowup[122] = "BBBBRRBBBBBBBBRRRRBBBBBBRRRRRRBBBBRRRRRRRRBBRRRRRRRRRRBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBB"; |
ajorgih3 | 4:697e1120f821 | 138 | draw_img(u, v, arrowup); |
ajorgih3 | 4:697e1120f821 | 139 | } |
ajorgih3 | 4:697e1120f821 | 140 | void draw_arrow_down(int u, int v) { |
ajorgih3 | 4:697e1120f821 | 141 | char arrowdown[122] = "BBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBBBRRRRRRBBBRRRRRRRRRRBBRRRRRRRRBBBBRRRRRRBBBBBBRRRRBBBBBBBBRRBBBBB"; |
ajorgih3 | 4:697e1120f821 | 142 | draw_img(u, v, arrowdown); |
ajorgih3 | 4:697e1120f821 | 143 | } |
ajorgih3 | 4:697e1120f821 | 144 | |
ajorgih3 | 4:697e1120f821 | 145 | void draw_arrow_right(int u, int v) { |
ajorgih3 | 4:697e1120f821 | 146 | char arrowright[122] = "BBBBBBRBBBBBBBBBBRRBBBRRRRRRRRRBBRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRBRRRRRRRRRBBBBBBBBRRBBBBBBBBBRBBBB"; |
ajorgih3 | 4:697e1120f821 | 147 | draw_img(u, v, arrowright); |
ajorgih3 | 4:697e1120f821 | 148 | } |
ajorgih3 | 4:697e1120f821 | 149 | |
ajorgih3 | 4:697e1120f821 | 150 | void draw_arrow_left(int u, int v) { |
ajorgih3 | 4:697e1120f821 | 151 | char arrowleft[122] = "BBBBRBBBBBBBBBRRBBBBBBBBRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRBBRRRRRRRRRBBBRRBBBBBBBBBBRBBBBBB"; |
ajorgih3 | 4:697e1120f821 | 152 | draw_img(u, v, arrowleft); |
ajorgih3 | 4:697e1120f821 | 153 | } |
ajorgih3 | 5:5953ca12205d | 154 | |
ajorgih3 | 5:5953ca12205d | 155 | void draw_lightspeed(int u, int v) { |
ajorgih3 | 5:5953ca12205d | 156 | char lightspeed[122] = "BBBBBBBBYBBBBBBBBBYYBBBBBBBBYYYBBBBBBBYYYBBBBBBBYYYYYYBBBBYYYYYYBBBBBBBYYYBBBBBBBYYYBBBBBBBYYYBBBBBBBBYBBBBBBB"; |
ajorgih3 | 5:5953ca12205d | 157 | draw_img(u, v, lightspeed); |
ajorgih3 | 5:5953ca12205d | 158 | } |
ajorgih3 | 5:5953ca12205d | 159 | |
ajorgih3 | 5:5953ca12205d | 160 | void draw_blue_wall(int u, int v) { |
ajorgih3 | 5:5953ca12205d | 161 | char bluewall[122] = "SSQSSQSSQSSQQSQQSQQSQQSSQSSQSSQSSQQSQQSQQSQQSSQSSQSSQSSQQSQQSQQSQQSSQSSQSSQSSQQSQQSQQSQQSSQSSQSSQSSQQSQQSQQSQQSSQSSQSSQSS"; |
ajorgih3 | 5:5953ca12205d | 162 | draw_img(u, v, bluewall); |
ajorgih3 | 5:5953ca12205d | 163 | } |
ajorgih3 | 6:fbaee888e5ea | 164 | |
ajorgih3 | 6:fbaee888e5ea | 165 | void draw_reverse(int u, int v) { |
ajorgih3 | 6:fbaee888e5ea | 166 | char reverse[122] = "BBBBBBBBBBBBBBBBBBBBBBBBBYBBBBBBBBBYYYYYYYYBBYYYYYYYYYBBBYYYYYYYYBBBBYBBBGBBBBGGGGGGGGBBBGGGGGGGGGBBGGGGGGGGBBBBBBBBBGBBB"; |
ajorgih3 | 6:fbaee888e5ea | 167 | draw_img(u, v, reverse); |
ajorgih3 | 6:fbaee888e5ea | 168 | } |
ajorgih3 | 7:7ab2f4b09196 | 169 | |
ajorgih3 | 7:7ab2f4b09196 | 170 | void draw_blue_potion(int u, int v) { |
ajorgih3 | 7:7ab2f4b09196 | 171 | char bluepotion[122] = "BBBBBBBBBBBBBBBDDDBBBBBBBQDDDQBBBBBBQBBBQBBBBBBQBBBQBBBBBQBBBBBQBBBQBBBBBBBQBBQSSSSSSSQBBQSSSSSSSQBBBQSSSSSQBBBBBQQQQQBBB"; |
ajorgih3 | 7:7ab2f4b09196 | 172 | draw_img(u, v, bluepotion); |
ajorgih3 | 7:7ab2f4b09196 | 173 | } |
ajorgih3 | 7:7ab2f4b09196 | 174 | |
ajorgih3 | 7:7ab2f4b09196 | 175 | void draw_red_potion(int u, int v) { |
ajorgih3 | 7:7ab2f4b09196 | 176 | char redpotion[122] = "BBBBBBBBBBBBBBBDDDBBBBBBBQDDDQBBBBBBQBBBQBBBBBBQBBBQBBBBBQBBBBBQBBBQBBBBBBBQBBQRRRRRRRQBBQRRRRRRRQBBBQRRRRRQBBBBBQQQQQBBB"; |
ajorgih3 | 7:7ab2f4b09196 | 177 | draw_img(u, v, redpotion); |
ajorgih3 | 7:7ab2f4b09196 | 178 | } |
DCchico | 1:10330bce85cb | 179 | |
ajorgih3 | 9:d09b96b6c39c | 180 | void draw_portal(int u, int v) { |
ajorgih3 | 9:d09b96b6c39c | 181 | char portal[122] = "BBBBSSSBBBBBBBSLLLSBBBBBSLLLLLSBBBSLLLLLLLSBBSLLLLLLLSBBSLLLLLLLSBBSLLLLLLLSBBSLLLLLLLSBBBSLLLLLSBBBBBSLLLSBBBBBBBSSSBBB"; |
ajorgih3 | 9:d09b96b6c39c | 182 | draw_img(u, v, portal); |
ajorgih3 | 9:d09b96b6c39c | 183 | |
ajorgih3 | 9:d09b96b6c39c | 184 | } |
DCchico | 1:10330bce85cb | 185 | |
ajorgih3 | 3:bb6f73642f01 | 186 | |
ajorgih3 | 3:bb6f73642f01 | 187 | |
ajorgih3 | 3:bb6f73642f01 | 188 | |
ajorgih3 | 3:bb6f73642f01 | 189 | |
ajorgih3 | 9:d09b96b6c39c | 190 |