ECE 2035 final project
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
speech.cpp@2:22d36e7740f1, 2019-04-15 (annotated)
- Committer:
- npatel387
- Date:
- Mon Apr 15 12:25:08 2019 +0000
- Revision:
- 2:22d36e7740f1
- Parent:
- 0:35660d7952f7
final;
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 | |
rconnorlawson | 0:35660d7952f7 | 30 | void draw_speech_bubble() |
rconnorlawson | 0:35660d7952f7 | 31 | { |
npatel387 | 2:22d36e7740f1 | 32 | //draw speech bubble borders |
npatel387 | 2:22d36e7740f1 | 33 | uLCD.line(0, 114, 127, 114, GREEN); // Bottom |
npatel387 | 2:22d36e7740f1 | 34 | uLCD.line(0, 70, 127, 70, GREEN); // Top |
npatel387 | 2:22d36e7740f1 | 35 | uLCD.line(0, 71, 0, 113, GREEN); // Left |
npatel387 | 2:22d36e7740f1 | 36 | uLCD.line(127, 71, 127, 113, GREEN); // Right |
npatel387 | 2:22d36e7740f1 | 37 | |
npatel387 | 2:22d36e7740f1 | 38 | //fill speech bubble borders |
npatel387 | 2:22d36e7740f1 | 39 | uLCD.filled_rectangle(1, 71, 126, 113, 5); |
rconnorlawson | 0:35660d7952f7 | 40 | } |
rconnorlawson | 0:35660d7952f7 | 41 | |
rconnorlawson | 0:35660d7952f7 | 42 | void erase_speech_bubble() |
rconnorlawson | 0:35660d7952f7 | 43 | { |
npatel387 | 2:22d36e7740f1 | 44 | //restore original color at speech bubble borders |
npatel387 | 2:22d36e7740f1 | 45 | uLCD.line(0, 114, 127, 114, WHITE); // Bottom |
npatel387 | 2:22d36e7740f1 | 46 | uLCD.line(0, 94, 127, 94, BLACK); // Top |
npatel387 | 2:22d36e7740f1 | 47 | uLCD.line(0, 95, 0, 113, WHITE); // Left |
npatel387 | 2:22d36e7740f1 | 48 | uLCD.line(127, 95, 127, 113, WHITE); // Right |
npatel387 | 2:22d36e7740f1 | 49 | |
npatel387 | 2:22d36e7740f1 | 50 | uLCD.filled_rectangle(1, 95, 126, 113, BLACK); |
npatel387 | 2:22d36e7740f1 | 51 | |
rconnorlawson | 0:35660d7952f7 | 52 | } |
rconnorlawson | 0:35660d7952f7 | 53 | |
rconnorlawson | 0:35660d7952f7 | 54 | void draw_speech_line(const char* line, int which) |
rconnorlawson | 0:35660d7952f7 | 55 | { |
npatel387 | 2:22d36e7740f1 | 56 | if(which == TOP) |
npatel387 | 2:22d36e7740f1 | 57 | { |
npatel387 | 2:22d36e7740f1 | 58 | uLCD.locate(1,9); |
npatel387 | 2:22d36e7740f1 | 59 | uLCD.printf(line); |
npatel387 | 2:22d36e7740f1 | 60 | } |
npatel387 | 2:22d36e7740f1 | 61 | else if(which == BOTTOM) |
npatel387 | 2:22d36e7740f1 | 62 | { |
npatel387 | 2:22d36e7740f1 | 63 | uLCD.locate(1,10); |
npatel387 | 2:22d36e7740f1 | 64 | uLCD.printf(line); |
npatel387 | 2:22d36e7740f1 | 65 | } |
npatel387 | 2:22d36e7740f1 | 66 | else if(which == 3) |
npatel387 | 2:22d36e7740f1 | 67 | { |
npatel387 | 2:22d36e7740f1 | 68 | uLCD.locate(1,11); |
npatel387 | 2:22d36e7740f1 | 69 | uLCD.printf(line); |
npatel387 | 2:22d36e7740f1 | 70 | } |
npatel387 | 2:22d36e7740f1 | 71 | else |
npatel387 | 2:22d36e7740f1 | 72 | { |
npatel387 | 2:22d36e7740f1 | 73 | uLCD.locate(1,12); |
npatel387 | 2:22d36e7740f1 | 74 | uLCD.printf(line); |
npatel387 | 2:22d36e7740f1 | 75 | } |
npatel387 | 2:22d36e7740f1 | 76 | |
rconnorlawson | 0:35660d7952f7 | 77 | } |
rconnorlawson | 0:35660d7952f7 | 78 | |
rconnorlawson | 0:35660d7952f7 | 79 | void speech_bubble_wait() |
rconnorlawson | 0:35660d7952f7 | 80 | { |
npatel387 | 2:22d36e7740f1 | 81 | GameInputs inputs; |
npatel387 | 2:22d36e7740f1 | 82 | inputs = read_inputs(); |
npatel387 | 2:22d36e7740f1 | 83 | int blink = 1; |
npatel387 | 2:22d36e7740f1 | 84 | while(inputs.b1) |
npatel387 | 2:22d36e7740f1 | 85 | { |
npatel387 | 2:22d36e7740f1 | 86 | blink = !blink; |
npatel387 | 2:22d36e7740f1 | 87 | wait_ms(200); |
npatel387 | 2:22d36e7740f1 | 88 | if(blink) |
npatel387 | 2:22d36e7740f1 | 89 | uLCD.filled_circle(123, 114, 3, GREEN); |
npatel387 | 2:22d36e7740f1 | 90 | else |
npatel387 | 2:22d36e7740f1 | 91 | uLCD.filled_circle(123, 114, 3, BLACK); |
npatel387 | 2:22d36e7740f1 | 92 | inputs = read_inputs(); |
npatel387 | 2:22d36e7740f1 | 93 | |
npatel387 | 2:22d36e7740f1 | 94 | } |
rconnorlawson | 0:35660d7952f7 | 95 | } |
rconnorlawson | 0:35660d7952f7 | 96 | |
npatel387 | 2:22d36e7740f1 | 97 | void speech(const char* line1, const char* line2, const char* line3, const char* line4) |
rconnorlawson | 0:35660d7952f7 | 98 | { |
rconnorlawson | 0:35660d7952f7 | 99 | draw_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 100 | draw_speech_line(line1, TOP); |
rconnorlawson | 0:35660d7952f7 | 101 | draw_speech_line(line2, BOTTOM); |
npatel387 | 2:22d36e7740f1 | 102 | draw_speech_line(line3, 3); |
npatel387 | 2:22d36e7740f1 | 103 | draw_speech_line(line4, 4); |
rconnorlawson | 0:35660d7952f7 | 104 | speech_bubble_wait(); |
rconnorlawson | 0:35660d7952f7 | 105 | erase_speech_bubble(); |
rconnorlawson | 0:35660d7952f7 | 106 | } |
rconnorlawson | 0:35660d7952f7 | 107 | |
rconnorlawson | 0:35660d7952f7 | 108 | void long_speech(const char* lines[], int n) |
rconnorlawson | 0:35660d7952f7 | 109 | { |
rconnorlawson | 0:35660d7952f7 | 110 | } |