Carter Montgomery / Mbed 2 deprecated 2035_Final_Project

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers speech.cpp Source File

speech.cpp

00001 #include "speech.h"
00002 
00003 #include "globals.h"
00004 #include "hardware.h"
00005 
00006 /**
00007  * Draw the speech bubble background.
00008  */
00009 static void draw_speech_bubble();
00010 
00011 /**
00012  * Erase the speech bubble.
00013  */
00014 static void erase_speech_bubble();
00015 
00016 /**
00017  * Draw a single line of the speech bubble.
00018  * @param line The text to display
00019  * @param which If TOP, the first line; if BOTTOM, the second line.
00020  */
00021 #define TOP    0
00022 #define BOTTOM 1
00023 static void draw_speech_line(const char* line, int which);
00024 
00025 /**
00026  * Delay until it is time to scroll.
00027  */
00028 static void speech_bubble_wait();
00029 
00030 int get_bubble_action(GameInputs inputs)
00031 {
00032     if(!inputs.b2){
00033         //return BUTTON2;
00034     }
00035 }
00036 void draw_speech_bubble()
00037 {
00038     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
00039 }
00040 
00041 void erase_speech_bubble()
00042 {
00043     uLCD.filled_rectangle(0, 128, 128, 90, 0x000000);
00044     //uLCD.filled_rectangle(0, 128, 128, 90, 0x000000);
00045 }
00046 
00047 void draw_speech_line(const char* line, int which)
00048 {
00049     if (which == TOP){
00050      uLCD.locate(1,12); //TO DO: the line overlaps with second line if too long
00051     } else if (which == BOTTOM){
00052          uLCD.locate(1,13);
00053     } 
00054      // basic printf demo = 16 by 18 characters on screen
00055     uLCD.text_mode(TRANSPARENT);
00056     uLCD.color(BLACK);
00057     uLCD.printf(line);
00058 }
00059 
00060 void speech_bubble_wait()
00061 {
00062     wait(2);
00063 }
00064 
00065 void speech(const char* line1, const char* line2, const char* line3, const char* line4)
00066 {
00067     draw_speech_bubble();
00068     //long_speech(line2, 1);
00069     draw_speech_line(line1, TOP);
00070     draw_speech_line(line2, BOTTOM);
00071     speech_bubble_wait();
00072     erase_speech_bubble();
00073     draw_speech_bubble();
00074     draw_speech_line(line3, TOP);
00075     draw_speech_line(line4, BOTTOM);
00076     speech_bubble_wait();
00077     erase_speech_bubble();
00078 }
00079 
00080 void long_speech(const char* lines, int n)
00081 {
00082     //start off by displaying 4 lines
00083     char p[17];
00084     for (int k = 0; k < 4; k++){
00085         for (int i = 0; i < 17; i++){
00086             p[i] = lines[i+(k*17)];
00087         }
00088         uLCD.text_mode(TRANSPARENT);
00089         uLCD.color(BLACK);
00090         uLCD.locate(1,k+12);
00091         uLCD.printf(p);
00092     }
00093 }