Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
speech.cpp@18:760dd68e939e, 2021-12-03 (annotated)
- Committer:
- nasiromar
- Date:
- Fri Dec 03 19:12:50 2021 +0000
- Revision:
- 18:760dd68e939e
- Parent:
- 14:7225da81314a
New Update;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:35660d7952f7 | 1 | #include "speech.h" |
nasiromar | 6:c9695079521d | 2 | #include "spells.h" |
rconnorlawson | 0:35660d7952f7 | 3 | #include "globals.h" |
rconnorlawson | 0:35660d7952f7 | 4 | #include "hardware.h" |
rconnorlawson | 0:35660d7952f7 | 5 | |
rconnorlawson | 0:35660d7952f7 | 6 | /** |
rconnorlawson | 0:35660d7952f7 | 7 | * Draw the speech bubble background. |
lballard9 | 4:37d3935365f8 | 8 | * Use this file to draw speech bubbles, look at the uLCD libraries for printing |
lballard9 | 4:37d3935365f8 | 9 | * text to the uLCD (see graphics.cpp note for link) |
rconnorlawson | 0:35660d7952f7 | 10 | */ |
nasiromar | 6:c9695079521d | 11 | static void draw_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 12 | static void draw_vertical_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 13 | /** |
rconnorlawson | 0:35660d7952f7 | 14 | * Erase the speech bubble. |
rconnorlawson | 0:35660d7952f7 | 15 | */ |
nasiromar | 6:c9695079521d | 16 | void erase_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 17 | void erase_vertical_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 18 | /** |
rconnorlawson | 0:35660d7952f7 | 19 | * Draw a single line of the speech bubble. |
rconnorlawson | 0:35660d7952f7 | 20 | * @param line The text to display |
rconnorlawson | 0:35660d7952f7 | 21 | * @param which If TOP, the first line; if BOTTOM, the second line. |
rconnorlawson | 0:35660d7952f7 | 22 | */ |
rconnorlawson | 0:35660d7952f7 | 23 | #define TOP 0 |
nasiromar | 6:c9695079521d | 24 | #define MID1 1 |
nasiromar | 6:c9695079521d | 25 | #define BOTTOM 3 |
nasiromar | 6:c9695079521d | 26 | static void draw_horizontal_speech_line(const char* line, int which); |
nasiromar | 6:c9695079521d | 27 | static void draw_vertical_speech_line(const char* line, int which); |
nasiromar | 6:c9695079521d | 28 | #define SPEECH_X 10 |
nasiromar | 6:c9695079521d | 29 | #define SPEECH_Y 80 |
nasiromar | 6:c9695079521d | 30 | #define BLACK 0x000000 |
nasiromar | 6:c9695079521d | 31 | #define WHITE 0xFFFFFF |
rconnorlawson | 0:35660d7952f7 | 32 | |
rconnorlawson | 0:35660d7952f7 | 33 | /** |
rconnorlawson | 0:35660d7952f7 | 34 | * Delay until it is time to scroll. |
rconnorlawson | 0:35660d7952f7 | 35 | */ |
nasiromar | 6:c9695079521d | 36 | static void horizontal_speech_bubble_wait(); |
nasiromar | 6:c9695079521d | 37 | static void vertical_speech_bubble_wait(); |
nasiromar | 6:c9695079521d | 38 | |
nasiromar | 6:c9695079521d | 39 | |
nasiromar | 6:c9695079521d | 40 | void draw_horizontal_speech_bubble() |
nasiromar | 6:c9695079521d | 41 | { |
nasiromar | 6:c9695079521d | 42 | uLCD.rectangle(SPEECH_X,SPEECH_Y,SPEECH_X+110,SPEECH_Y+30,WHITE); //border |
nasiromar | 6:c9695079521d | 43 | uLCD.filled_rectangle(SPEECH_X+1,SPEECH_Y+1,SPEECH_X+109,SPEECH_Y+29,BLACK); |
nasiromar | 6:c9695079521d | 44 | |
nasiromar | 6:c9695079521d | 45 | } |
rconnorlawson | 0:35660d7952f7 | 46 | |
nasiromar | 6:c9695079521d | 47 | void draw_vertical_speech_bubble() |
rconnorlawson | 0:35660d7952f7 | 48 | { |
nasiromar | 6:c9695079521d | 49 | uLCD.rectangle(SPEECH_Y,SPEECH_X+10,SPEECH_Y+40,SPEECH_X+70,WHITE); //border |
nasiromar | 6:c9695079521d | 50 | uLCD.filled_rectangle(SPEECH_Y+1,SPEECH_X+11,SPEECH_Y+39,SPEECH_X+69,BLACK); |
nasiromar | 6:c9695079521d | 51 | |
nasiromar | 6:c9695079521d | 52 | } |
nasiromar | 6:c9695079521d | 53 | |
nasiromar | 6:c9695079521d | 54 | void erase_horizontal_speech_bubble() |
nasiromar | 6:c9695079521d | 55 | { |
nasiromar | 6:c9695079521d | 56 | uLCD.filled_rectangle(SPEECH_X,SPEECH_Y,SPEECH_X+110,SPEECH_Y+30,BLACK); |
nasiromar | 6:c9695079521d | 57 | wait(.3); |
rconnorlawson | 0:35660d7952f7 | 58 | } |
rconnorlawson | 0:35660d7952f7 | 59 | |
nasiromar | 6:c9695079521d | 60 | void erase_vertical_speech_bubble() |
nasiromar | 6:c9695079521d | 61 | { |
nasiromar | 6:c9695079521d | 62 | uLCD.filled_rectangle(SPEECH_Y,SPEECH_X+10,SPEECH_Y+40,SPEECH_X+70,BLACK); |
nasiromar | 6:c9695079521d | 63 | wait(.3); |
nasiromar | 6:c9695079521d | 64 | } |
nasiromar | 6:c9695079521d | 65 | |
nasiromar | 6:c9695079521d | 66 | |
nasiromar | 6:c9695079521d | 67 | void draw_horizontal_speech_line(const char* line, int which) |
rconnorlawson | 0:35660d7952f7 | 68 | { |
nasiromar | 6:c9695079521d | 69 | int text_x = 2; |
nasiromar | 6:c9695079521d | 70 | int text_y; |
nasiromar | 6:c9695079521d | 71 | if(which == TOP){ |
nasiromar | 6:c9695079521d | 72 | text_y = 11; |
nasiromar | 6:c9695079521d | 73 | } |
nasiromar | 6:c9695079521d | 74 | if(which == BOTTOM){ |
nasiromar | 6:c9695079521d | 75 | text_y = 12; |
nasiromar | 6:c9695079521d | 76 | } |
nasiromar | 6:c9695079521d | 77 | |
nasiromar | 6:c9695079521d | 78 | uLCD.color(GREEN); |
nasiromar | 6:c9695079521d | 79 | uLCD.textbackground_color(BLACK); |
nasiromar | 6:c9695079521d | 80 | uLCD.text_mode(OPAQUE); |
nasiromar | 6:c9695079521d | 81 | uLCD.color(GREEN); |
nasiromar | 6:c9695079521d | 82 | |
nasiromar | 6:c9695079521d | 83 | while(*line){ |
nasiromar | 6:c9695079521d | 84 | pc.printf("%c\n", *line); |
nasiromar | 6:c9695079521d | 85 | uLCD.locate(text_x,text_y); |
nasiromar | 6:c9695079521d | 86 | uLCD.printf("%c\n",*line); |
nasiromar | 6:c9695079521d | 87 | text_x++; |
nasiromar | 6:c9695079521d | 88 | line = line + 1; |
nasiromar | 6:c9695079521d | 89 | } |
nasiromar | 6:c9695079521d | 90 | |
rconnorlawson | 0:35660d7952f7 | 91 | } |
rconnorlawson | 0:35660d7952f7 | 92 | |
nasiromar | 6:c9695079521d | 93 | void draw_vertical_speech_line(const char* line, int which) |
rconnorlawson | 0:35660d7952f7 | 94 | { |
nasiromar | 6:c9695079521d | 95 | int text_x = 12; |
nasiromar | 6:c9695079521d | 96 | int text_y; |
nasiromar | 6:c9695079521d | 97 | if(which == TOP){ |
nasiromar | 6:c9695079521d | 98 | text_y = 4; |
nasiromar | 6:c9695079521d | 99 | } |
nasiromar | 6:c9695079521d | 100 | |
nasiromar | 6:c9695079521d | 101 | if(which == MID1){ |
nasiromar | 6:c9695079521d | 102 | text_y = 6; |
nasiromar | 6:c9695079521d | 103 | } |
nasiromar | 6:c9695079521d | 104 | |
nasiromar | 6:c9695079521d | 105 | |
nasiromar | 6:c9695079521d | 106 | if(which == BOTTOM){ |
nasiromar | 6:c9695079521d | 107 | text_y = 8; |
nasiromar | 6:c9695079521d | 108 | } |
nasiromar | 6:c9695079521d | 109 | |
nasiromar | 6:c9695079521d | 110 | uLCD.color(GREEN); |
nasiromar | 6:c9695079521d | 111 | uLCD.textbackground_color(BLACK); |
nasiromar | 6:c9695079521d | 112 | uLCD.text_mode(OPAQUE); |
nasiromar | 6:c9695079521d | 113 | uLCD.color(GREEN); |
nasiromar | 6:c9695079521d | 114 | |
nasiromar | 6:c9695079521d | 115 | while(*line){ |
nasiromar | 6:c9695079521d | 116 | pc.printf("%c\n", *line); |
nasiromar | 6:c9695079521d | 117 | uLCD.locate(text_x,text_y); |
nasiromar | 6:c9695079521d | 118 | uLCD.printf("%c\n",*line); |
nasiromar | 6:c9695079521d | 119 | uLCD.locate(text_x,text_y); |
nasiromar | 6:c9695079521d | 120 | uLCD.printf("%c\n",*line); |
nasiromar | 6:c9695079521d | 121 | uLCD.locate(text_x,text_y); |
nasiromar | 6:c9695079521d | 122 | uLCD.printf("%c\n",*line); |
nasiromar | 6:c9695079521d | 123 | text_x++; |
nasiromar | 6:c9695079521d | 124 | line = line + 1; |
nasiromar | 6:c9695079521d | 125 | } |
nasiromar | 6:c9695079521d | 126 | |
rconnorlawson | 0:35660d7952f7 | 127 | } |
rconnorlawson | 0:35660d7952f7 | 128 | |
nasiromar | 6:c9695079521d | 129 | |
nasiromar | 6:c9695079521d | 130 | void horizontal_speech_bubble_wait1() |
rconnorlawson | 0:35660d7952f7 | 131 | { |
nasiromar | 6:c9695079521d | 132 | GameInputs inputs = read_inputs(); |
nasiromar | 6:c9695079521d | 133 | while(inputs.b1){ |
nasiromar | 6:c9695079521d | 134 | wait(.1); |
nasiromar | 6:c9695079521d | 135 | inputs = read_inputs(); |
nasiromar | 6:c9695079521d | 136 | } |
rconnorlawson | 0:35660d7952f7 | 137 | } |
rconnorlawson | 0:35660d7952f7 | 138 | |
nasiromar | 6:c9695079521d | 139 | void horizontal_speech_bubble_wait2() |
nasiromar | 6:c9695079521d | 140 | { |
nasiromar | 6:c9695079521d | 141 | GameInputs inputs = read_inputs(); |
nasiromar | 6:c9695079521d | 142 | while(inputs.b2&&inputs.b1&&inputs.b3){ |
nasiromar | 6:c9695079521d | 143 | wait(.1); |
nasiromar | 6:c9695079521d | 144 | inputs = read_inputs(); |
nasiromar | 6:c9695079521d | 145 | } |
nasiromar | 6:c9695079521d | 146 | } |
nasiromar | 6:c9695079521d | 147 | |
nasiromar | 14:7225da81314a | 148 | void vertical_speech_bubble_wait1() |
nasiromar | 6:c9695079521d | 149 | { |
nasiromar | 6:c9695079521d | 150 | GameInputs inputs = read_inputs(); |
nasiromar | 6:c9695079521d | 151 | |
nasiromar | 6:c9695079521d | 152 | int magic; |
nasiromar | 6:c9695079521d | 153 | |
nasiromar | 6:c9695079521d | 154 | while(inputs.b2&&inputs.b1&&inputs.b3){ |
nasiromar | 6:c9695079521d | 155 | wait(.1); |
nasiromar | 6:c9695079521d | 156 | inputs = read_inputs(); |
nasiromar | 6:c9695079521d | 157 | magic = spell(); |
nasiromar | 6:c9695079521d | 158 | |
nasiromar | 6:c9695079521d | 159 | } |
nasiromar | 6:c9695079521d | 160 | } |
nasiromar | 6:c9695079521d | 161 | |
nasiromar | 14:7225da81314a | 162 | void vertical_speech_bubble_wait2() |
nasiromar | 14:7225da81314a | 163 | { |
nasiromar | 14:7225da81314a | 164 | GameInputs inputs = read_inputs(); |
nasiromar | 14:7225da81314a | 165 | |
nasiromar | 14:7225da81314a | 166 | int money; |
nasiromar | 14:7225da81314a | 167 | |
nasiromar | 14:7225da81314a | 168 | while(inputs.b2&&inputs.b1&&inputs.b3){ |
nasiromar | 14:7225da81314a | 169 | wait(.1); |
nasiromar | 14:7225da81314a | 170 | inputs = read_inputs(); |
nasiromar | 14:7225da81314a | 171 | money = store(); |
nasiromar | 14:7225da81314a | 172 | |
nasiromar | 14:7225da81314a | 173 | } |
nasiromar | 14:7225da81314a | 174 | } |
nasiromar | 14:7225da81314a | 175 | |
nasiromar | 6:c9695079521d | 176 | |
nasiromar | 6:c9695079521d | 177 | void horizontal_speech1(const char* line1, const char* line2) |
rconnorlawson | 0:35660d7952f7 | 178 | { |
nasiromar | 6:c9695079521d | 179 | draw_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 180 | draw_horizontal_speech_line(line1, TOP); |
nasiromar | 6:c9695079521d | 181 | draw_horizontal_speech_line(line2, BOTTOM); |
nasiromar | 6:c9695079521d | 182 | horizontal_speech_bubble_wait1(); |
nasiromar | 6:c9695079521d | 183 | erase_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 184 | } |
nasiromar | 6:c9695079521d | 185 | |
nasiromar | 6:c9695079521d | 186 | void horizontal_speech2(const char* line1, const char* line2) |
nasiromar | 6:c9695079521d | 187 | { |
nasiromar | 6:c9695079521d | 188 | draw_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 189 | draw_horizontal_speech_line(line1, TOP); |
nasiromar | 6:c9695079521d | 190 | draw_horizontal_speech_line(line2, BOTTOM); |
nasiromar | 6:c9695079521d | 191 | horizontal_speech_bubble_wait2(); |
nasiromar | 6:c9695079521d | 192 | erase_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 193 | } |
nasiromar | 6:c9695079521d | 194 | |
nasiromar | 6:c9695079521d | 195 | //const char* line1, const char* line2 |
nasiromar | 14:7225da81314a | 196 | void vertical_speech1(const char* line1, const char* line2, const char* line3) |
nasiromar | 6:c9695079521d | 197 | { |
nasiromar | 6:c9695079521d | 198 | draw_vertical_speech_bubble(); |
nasiromar | 6:c9695079521d | 199 | draw_vertical_speech_line(line1, TOP); |
nasiromar | 6:c9695079521d | 200 | draw_vertical_speech_line(line2, MID1); |
nasiromar | 6:c9695079521d | 201 | draw_vertical_speech_line(line3, BOTTOM); |
nasiromar | 14:7225da81314a | 202 | vertical_speech_bubble_wait1(); |
nasiromar | 14:7225da81314a | 203 | erase_vertical_speech_bubble(); |
nasiromar | 14:7225da81314a | 204 | } |
nasiromar | 14:7225da81314a | 205 | |
nasiromar | 14:7225da81314a | 206 | void vertical_speech2(const char* line1, const char* line2, const char* line3) |
nasiromar | 14:7225da81314a | 207 | { |
nasiromar | 14:7225da81314a | 208 | draw_vertical_speech_bubble(); |
nasiromar | 14:7225da81314a | 209 | draw_vertical_speech_line(line1, TOP); |
nasiromar | 14:7225da81314a | 210 | draw_vertical_speech_line(line2, MID1); |
nasiromar | 14:7225da81314a | 211 | draw_vertical_speech_line(line3, BOTTOM); |
nasiromar | 14:7225da81314a | 212 | vertical_speech_bubble_wait2(); |
nasiromar | 6:c9695079521d | 213 | erase_vertical_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 214 | } |
rconnorlawson | 0:35660d7952f7 | 215 | |
rconnorlawson | 0:35660d7952f7 | 216 | void long_speech(const char* lines[], int n) |
rconnorlawson | 0:35660d7952f7 | 217 | { |
rconnorlawson | 0:35660d7952f7 | 218 | } |