Adventure game written for ECE2035 at the Georgia Institute of Technology
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
speech.cpp@4:cdc54191ff07, 2018-05-22 (annotated)
- Committer:
- trmontgomery
- Date:
- Tue May 22 19:13:03 2018 +0000
- Revision:
- 4:cdc54191ff07
- Parent:
- 2:0876296d9473
Menu class complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rconnorlawson | 0:35660d7952f7 | 1 | #include "speech.h" |
rconnorlawson | 0:35660d7952f7 | 2 | |
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. |
rconnorlawson | 0:35660d7952f7 | 8 | */ |
rconnorlawson | 0:35660d7952f7 | 9 | static void draw_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 10 | |
rconnorlawson | 0:35660d7952f7 | 11 | /** |
rconnorlawson | 0:35660d7952f7 | 12 | * Erase the speech bubble. |
rconnorlawson | 0:35660d7952f7 | 13 | */ |
rconnorlawson | 0:35660d7952f7 | 14 | static void erase_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 15 | |
rconnorlawson | 0:35660d7952f7 | 16 | /** |
rconnorlawson | 0:35660d7952f7 | 17 | * Draw a single line of the speech bubble. |
rconnorlawson | 0:35660d7952f7 | 18 | * @param line The text to display |
rconnorlawson | 0:35660d7952f7 | 19 | * @param which If TOP, the first line; if BOTTOM, the second line. |
rconnorlawson | 0:35660d7952f7 | 20 | */ |
rconnorlawson | 0:35660d7952f7 | 21 | #define TOP 0 |
rconnorlawson | 0:35660d7952f7 | 22 | #define BOTTOM 1 |
rconnorlawson | 0:35660d7952f7 | 23 | static void draw_speech_line(const char* line, int which); |
rconnorlawson | 0:35660d7952f7 | 24 | |
rconnorlawson | 0:35660d7952f7 | 25 | /** |
rconnorlawson | 0:35660d7952f7 | 26 | * Delay until it is time to scroll. |
rconnorlawson | 0:35660d7952f7 | 27 | */ |
rconnorlawson | 0:35660d7952f7 | 28 | static void speech_bubble_wait(); |
rconnorlawson | 0:35660d7952f7 | 29 | |
trmontgomery | 4:cdc54191ff07 | 30 | int get_bubble_action(GameInputs inputs) |
trmontgomery | 4:cdc54191ff07 | 31 | { |
trmontgomery | 4:cdc54191ff07 | 32 | if(!inputs.b2){ |
trmontgomery | 4:cdc54191ff07 | 33 | //return BUTTON2; |
trmontgomery | 4:cdc54191ff07 | 34 | } |
trmontgomery | 4:cdc54191ff07 | 35 | } |
rconnorlawson | 0:35660d7952f7 | 36 | void draw_speech_bubble() |
rconnorlawson | 0:35660d7952f7 | 37 | { |
trmontgomery | 2:0876296d9473 | 38 | uLCD.filled_rectangle(0, 128, 128, 90, 0xFFFFFF); //(x1, y1, x2, y2) where (x1, y1) is bottom left corner and (x2, y2) is upper right corner |
rconnorlawson | 0:35660d7952f7 | 39 | } |
rconnorlawson | 0:35660d7952f7 | 40 | |
rconnorlawson | 0:35660d7952f7 | 41 | void erase_speech_bubble() |
rconnorlawson | 0:35660d7952f7 | 42 | { |
trmontgomery | 2:0876296d9473 | 43 | uLCD.filled_rectangle(0, 128, 128, 90, 0x000000); |
trmontgomery | 2:0876296d9473 | 44 | //uLCD.filled_rectangle(0, 128, 128, 90, 0x000000); |
rconnorlawson | 0:35660d7952f7 | 45 | } |
rconnorlawson | 0:35660d7952f7 | 46 | |
rconnorlawson | 0:35660d7952f7 | 47 | void draw_speech_line(const char* line, int which) |
rconnorlawson | 0:35660d7952f7 | 48 | { |
trmontgomery | 2:0876296d9473 | 49 | if (which == TOP){ |
trmontgomery | 2:0876296d9473 | 50 | uLCD.locate(1,12); //TO DO: the line overlaps with second line if too long |
trmontgomery | 2:0876296d9473 | 51 | } else if (which == BOTTOM){ |
trmontgomery | 2:0876296d9473 | 52 | uLCD.locate(1,13); |
trmontgomery | 2:0876296d9473 | 53 | } |
trmontgomery | 2:0876296d9473 | 54 | // basic printf demo = 16 by 18 characters on screen |
trmontgomery | 2:0876296d9473 | 55 | uLCD.text_mode(TRANSPARENT); |
trmontgomery | 2:0876296d9473 | 56 | uLCD.color(BLACK); |
trmontgomery | 2:0876296d9473 | 57 | uLCD.printf(line); |
rconnorlawson | 0:35660d7952f7 | 58 | } |
rconnorlawson | 0:35660d7952f7 | 59 | |
rconnorlawson | 0:35660d7952f7 | 60 | void speech_bubble_wait() |
rconnorlawson | 0:35660d7952f7 | 61 | { |
trmontgomery | 2:0876296d9473 | 62 | wait(2); |
rconnorlawson | 0:35660d7952f7 | 63 | } |
rconnorlawson | 0:35660d7952f7 | 64 | |
trmontgomery | 4:cdc54191ff07 | 65 | void speech(const char* line1, const char* line2, const char* line3, const char* line4) |
rconnorlawson | 0:35660d7952f7 | 66 | { |
rconnorlawson | 0:35660d7952f7 | 67 | draw_speech_bubble(); |
trmontgomery | 4:cdc54191ff07 | 68 | //long_speech(line2, 1); |
rconnorlawson | 0:35660d7952f7 | 69 | draw_speech_line(line1, TOP); |
rconnorlawson | 0:35660d7952f7 | 70 | draw_speech_line(line2, BOTTOM); |
rconnorlawson | 0:35660d7952f7 | 71 | speech_bubble_wait(); |
rconnorlawson | 0:35660d7952f7 | 72 | erase_speech_bubble(); |
trmontgomery | 4:cdc54191ff07 | 73 | draw_speech_bubble(); |
trmontgomery | 4:cdc54191ff07 | 74 | draw_speech_line(line3, TOP); |
trmontgomery | 4:cdc54191ff07 | 75 | draw_speech_line(line4, BOTTOM); |
trmontgomery | 4:cdc54191ff07 | 76 | speech_bubble_wait(); |
trmontgomery | 4:cdc54191ff07 | 77 | erase_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 78 | } |
rconnorlawson | 0:35660d7952f7 | 79 | |
trmontgomery | 4:cdc54191ff07 | 80 | void long_speech(const char* lines, int n) |
rconnorlawson | 0:35660d7952f7 | 81 | { |
trmontgomery | 4:cdc54191ff07 | 82 | //start off by displaying 4 lines |
trmontgomery | 4:cdc54191ff07 | 83 | char p[17]; |
trmontgomery | 4:cdc54191ff07 | 84 | for (int k = 0; k < 4; k++){ |
trmontgomery | 4:cdc54191ff07 | 85 | for (int i = 0; i < 17; i++){ |
trmontgomery | 4:cdc54191ff07 | 86 | p[i] = lines[i+(k*17)]; |
trmontgomery | 4:cdc54191ff07 | 87 | } |
trmontgomery | 4:cdc54191ff07 | 88 | uLCD.text_mode(TRANSPARENT); |
trmontgomery | 4:cdc54191ff07 | 89 | uLCD.color(BLACK); |
trmontgomery | 4:cdc54191ff07 | 90 | uLCD.locate(1,k+12); |
trmontgomery | 4:cdc54191ff07 | 91 | uLCD.printf(p); |
trmontgomery | 4:cdc54191ff07 | 92 | } |
rconnorlawson | 0:35660d7952f7 | 93 | } |