Game For ECE 2035
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
speech.cpp@6:c9695079521d, 2021-11-19 (annotated)
- Committer:
- nasiromar
- Date:
- Fri Nov 19 22:03:25 2021 +0000
- Revision:
- 6:c9695079521d
- Parent:
- 4:37d3935365f8
- Child:
- 14:7225da81314a
Basics
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 | 6:c9695079521d | 148 | void vertical_speech_bubble_wait() |
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 | 6:c9695079521d | 162 | |
nasiromar | 6:c9695079521d | 163 | void horizontal_speech1(const char* line1, const char* line2) |
rconnorlawson | 0:35660d7952f7 | 164 | { |
nasiromar | 6:c9695079521d | 165 | draw_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 166 | draw_horizontal_speech_line(line1, TOP); |
nasiromar | 6:c9695079521d | 167 | draw_horizontal_speech_line(line2, BOTTOM); |
nasiromar | 6:c9695079521d | 168 | horizontal_speech_bubble_wait1(); |
nasiromar | 6:c9695079521d | 169 | erase_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 170 | } |
nasiromar | 6:c9695079521d | 171 | |
nasiromar | 6:c9695079521d | 172 | void horizontal_speech2(const char* line1, const char* line2) |
nasiromar | 6:c9695079521d | 173 | { |
nasiromar | 6:c9695079521d | 174 | draw_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 175 | draw_horizontal_speech_line(line1, TOP); |
nasiromar | 6:c9695079521d | 176 | draw_horizontal_speech_line(line2, BOTTOM); |
nasiromar | 6:c9695079521d | 177 | horizontal_speech_bubble_wait2(); |
nasiromar | 6:c9695079521d | 178 | erase_horizontal_speech_bubble(); |
nasiromar | 6:c9695079521d | 179 | } |
nasiromar | 6:c9695079521d | 180 | |
nasiromar | 6:c9695079521d | 181 | //const char* line1, const char* line2 |
nasiromar | 6:c9695079521d | 182 | void vertical_speech(const char* line1, const char* line2, const char* line3) |
nasiromar | 6:c9695079521d | 183 | { |
nasiromar | 6:c9695079521d | 184 | draw_vertical_speech_bubble(); |
nasiromar | 6:c9695079521d | 185 | draw_vertical_speech_line(line1, TOP); |
nasiromar | 6:c9695079521d | 186 | draw_vertical_speech_line(line2, MID1); |
nasiromar | 6:c9695079521d | 187 | draw_vertical_speech_line(line3, BOTTOM); |
nasiromar | 6:c9695079521d | 188 | vertical_speech_bubble_wait(); |
nasiromar | 6:c9695079521d | 189 | erase_vertical_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 190 | } |
rconnorlawson | 0:35660d7952f7 | 191 | |
rconnorlawson | 0:35660d7952f7 | 192 | void long_speech(const char* lines[], int n) |
rconnorlawson | 0:35660d7952f7 | 193 | { |
rconnorlawson | 0:35660d7952f7 | 194 | } |