![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ECE 4180 Final
Dependencies: mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem
main.cpp@19:d65f9fb1023b, 2019-12-06 (annotated)
- Committer:
- jcrane32
- Date:
- Fri Dec 06 15:46:16 2019 +0000
- Revision:
- 19:d65f9fb1023b
- Parent:
- 11:362e25f659a5
- Child:
- 20:7d56cdcbc9a5
Added lanes, bubbles, and all the other stuff required for there to be the actual game.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yqin70 | 0:4f77ae831ee7 | 1 | #include "mbed.h" |
jcrane32 | 7:15fdc55dbf66 | 2 | #include "rtos.h" |
jcrane32 | 19:d65f9fb1023b | 3 | #include "stdio.h" |
yqin70 | 0:4f77ae831ee7 | 4 | #include "SDFileSystem.h" |
yqin70 | 0:4f77ae831ee7 | 5 | #include "wave_player.h" |
jcrane32 | 19:d65f9fb1023b | 6 | |
yqin70 | 0:4f77ae831ee7 | 7 | #include "uLCD_4DGL.h" |
yqin70 | 0:4f77ae831ee7 | 8 | #include "Small_6.h" |
yqin70 | 0:4f77ae831ee7 | 9 | #include "Small_7.h" |
yqin70 | 0:4f77ae831ee7 | 10 | #include "Arial_9.h" |
yqin70 | 0:4f77ae831ee7 | 11 | #include "C12832_lcd.h" |
yqin70 | 0:4f77ae831ee7 | 12 | |
jcrane32 | 19:d65f9fb1023b | 13 | #include "globals.h" |
jcrane32 | 19:d65f9fb1023b | 14 | |
jcrane32 | 6:cd24147b5e50 | 15 | #include "bubbles.h" |
yqin70 | 11:362e25f659a5 | 16 | #include "stacys_mom.h" |
jcrane32 | 19:d65f9fb1023b | 17 | //#include "the_middle.h" |
yqin70 | 11:362e25f659a5 | 18 | #include "fireflies.h" |
yqin70 | 11:362e25f659a5 | 19 | #include "sins.h" |
jcrane32 | 7:15fdc55dbf66 | 20 | #include "LED.hpp" |
jcrane32 | 6:cd24147b5e50 | 21 | |
jcrane32 | 19:d65f9fb1023b | 22 | #include "Lane.hpp" |
jcrane32 | 19:d65f9fb1023b | 23 | #include "Bubble.hpp" |
jcrane32 | 19:d65f9fb1023b | 24 | |
jcrane32 | 19:d65f9fb1023b | 25 | |
yqin70 | 0:4f77ae831ee7 | 26 | //Setup RGB led using PWM pins and class |
ShelbyC22 | 4:59b73f321c0e | 27 | RGBLed myRGBled(p24,p23,p22); //RGB PWM pins |
yqin70 | 0:4f77ae831ee7 | 28 | char bred=0; |
yqin70 | 0:4f77ae831ee7 | 29 | char bgreen=0; |
yqin70 | 0:4f77ae831ee7 | 30 | char bblue=0; |
yqin70 | 0:4f77ae831ee7 | 31 | |
yqin70 | 0:4f77ae831ee7 | 32 | volatile bool songselect = false; |
yqin70 | 0:4f77ae831ee7 | 33 | volatile bool homescreen = true; |
ShelbyC22 | 5:b2cf15651d4e | 34 | volatile bool songchange = false; |
jcrane32 | 7:15fdc55dbf66 | 35 | volatile bool playing = false; |
jcrane32 | 7:15fdc55dbf66 | 36 | uLCD_4DGL uLCD(p28,p27,p30); |
yqin70 | 0:4f77ae831ee7 | 37 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
jcrane32 | 19:d65f9fb1023b | 38 | AnalogIn joy_pot(p16); |
yqin70 | 0:4f77ae831ee7 | 39 | DigitalOut myled(LED1); |
yqin70 | 0:4f77ae831ee7 | 40 | DigitalIn pb1(p20); |
yqin70 | 0:4f77ae831ee7 | 41 | DigitalIn pb2(p19); |
yqin70 | 1:a1aa9a79070a | 42 | AnalogOut DACout(p18); |
yqin70 | 1:a1aa9a79070a | 43 | wave_player waver(&DACout); |
jcrane32 | 19:d65f9fb1023b | 44 | Thread thread1, thread2, thread3, thread4; |
jcrane32 | 19:d65f9fb1023b | 45 | |
jcrane32 | 7:15fdc55dbf66 | 46 | Ticker nextsample; |
jcrane32 | 19:d65f9fb1023b | 47 | volatile int songNdx = 0; |
jcrane32 | 19:d65f9fb1023b | 48 | unsigned char *playingSong = NULL; |
yqin70 | 0:4f77ae831ee7 | 49 | |
yqin70 | 0:4f77ae831ee7 | 50 | // mutex to make the lcd lib thread safe |
yqin70 | 0:4f77ae831ee7 | 51 | Mutex lcd_mutex; |
yqin70 | 0:4f77ae831ee7 | 52 | int songnum = 1; |
jcrane32 | 19:d65f9fb1023b | 53 | |
jcrane32 | 19:d65f9fb1023b | 54 | unsigned short **currentBubbles = NULL; |
jcrane32 | 19:d65f9fb1023b | 55 | int bubbleNdx = 0; |
jcrane32 | 19:d65f9fb1023b | 56 | int bubblesDrawn = 0; |
jcrane32 | 19:d65f9fb1023b | 57 | int bubblesMissed = 0; |
jcrane32 | 19:d65f9fb1023b | 58 | |
jcrane32 | 19:d65f9fb1023b | 59 | |
jcrane32 | 6:cd24147b5e50 | 60 | |
yqin70 | 0:4f77ae831ee7 | 61 | // Thread 1 |
yqin70 | 1:a1aa9a79070a | 62 | // print homescreen to LCD |
jcrane32 | 6:cd24147b5e50 | 63 | void homescreen_thread() |
yqin70 | 0:4f77ae831ee7 | 64 | { |
jcrane32 | 19:d65f9fb1023b | 65 | while (true) { // thread loop |
ShelbyC22 | 5:b2cf15651d4e | 66 | lcd_mutex.lock(); |
yqin70 | 0:4f77ae831ee7 | 67 | if (homescreen){ |
yqin70 | 0:4f77ae831ee7 | 68 | uLCD.cls(); |
ShelbyC22 | 5:b2cf15651d4e | 69 | uLCD.text_height(1.3); |
yqin70 | 2:765774781bb1 | 70 | uLCD.text_width(1.9); |
yqin70 | 0:4f77ae831ee7 | 71 | uLCD.color(WHITE); |
ShelbyC22 | 5:b2cf15651d4e | 72 | uLCD.locate(5,0); |
ShelbyC22 | 5:b2cf15651d4e | 73 | uLCD.printf("Tap Tap"); |
ShelbyC22 | 5:b2cf15651d4e | 74 | uLCD.locate(4,1); |
ShelbyC22 | 5:b2cf15651d4e | 75 | uLCD.printf("Revolution"); |
ShelbyC22 | 5:b2cf15651d4e | 76 | uLCD.locate(0,3); |
jcrane32 | 7:15fdc55dbf66 | 77 | uLCD.printf("Pick a song!"); |
ShelbyC22 | 5:b2cf15651d4e | 78 | uLCD.text_height(1.3); |
yqin70 | 2:765774781bb1 | 79 | uLCD.text_width(1.9); |
ShelbyC22 | 5:b2cf15651d4e | 80 | uLCD.locate(3,5); |
ShelbyC22 | 4:59b73f321c0e | 81 | uLCD.printf("Fireflies"); |
ShelbyC22 | 5:b2cf15651d4e | 82 | uLCD.locate(3,7); |
jcrane32 | 19:d65f9fb1023b | 83 | uLCD.printf("Stacy's Mom"); |
ShelbyC22 | 5:b2cf15651d4e | 84 | uLCD.locate(3,9); |
jcrane32 | 7:15fdc55dbf66 | 85 | uLCD.printf("I Write Sins \n \t Not Tragedies"); |
jcrane32 | 19:d65f9fb1023b | 86 | uLCD.filled_circle(6, 43, 4, WHITE); //new selection with circle instead of rectangle |
jcrane32 | 19:d65f9fb1023b | 87 | homescreen = false; |
jcrane32 | 19:d65f9fb1023b | 88 | } |
jcrane32 | 19:d65f9fb1023b | 89 | if (songchange) { |
jcrane32 | 19:d65f9fb1023b | 90 | for (int i = 0; i < 3; i++){ |
jcrane32 | 19:d65f9fb1023b | 91 | uLCD.filled_circle(6, i*15+43, 4,BLACK); |
ShelbyC22 | 5:b2cf15651d4e | 92 | } |
jcrane32 | 19:d65f9fb1023b | 93 | uLCD.filled_circle(6, (songnum-1)*15+43, 4,WHITE); |
ShelbyC22 | 5:b2cf15651d4e | 94 | songchange = false; |
jcrane32 | 19:d65f9fb1023b | 95 | } |
jcrane32 | 19:d65f9fb1023b | 96 | |
jcrane32 | 19:d65f9fb1023b | 97 | lcd_mutex.unlock(); |
jcrane32 | 19:d65f9fb1023b | 98 | Thread::wait(200); |
yqin70 | 0:4f77ae831ee7 | 99 | } |
yqin70 | 0:4f77ae831ee7 | 100 | } |
yqin70 | 0:4f77ae831ee7 | 101 | |
jcrane32 | 6:cd24147b5e50 | 102 | // Thread 2 |
jcrane32 | 7:15fdc55dbf66 | 103 | // joystick control for song selection during homescreen |
jcrane32 | 19:d65f9fb1023b | 104 | void joystick_thread() { |
jcrane32 | 19:d65f9fb1023b | 105 | while (true) { |
jcrane32 | 19:d65f9fb1023b | 106 | if (!playing) { // we dont want to be able to change the song if we're playing |
yqin70 | 0:4f77ae831ee7 | 107 | if ((joy_pot <= (1.4/3.3)) && songnum>1) { |
jcrane32 | 19:d65f9fb1023b | 108 | songnum--; |
jcrane32 | 19:d65f9fb1023b | 109 | songchange = true; |
jcrane32 | 19:d65f9fb1023b | 110 | } else if ((joy_pot >= (1.8/3.3)) && songnum<3){ |
yqin70 | 0:4f77ae831ee7 | 111 | songnum++; |
ShelbyC22 | 5:b2cf15651d4e | 112 | songchange = true; |
jcrane32 | 19:d65f9fb1023b | 113 | } |
jcrane32 | 19:d65f9fb1023b | 114 | Thread::wait(250); |
jcrane32 | 19:d65f9fb1023b | 115 | } |
jcrane32 | 19:d65f9fb1023b | 116 | |
yqin70 | 0:4f77ae831ee7 | 117 | } |
yqin70 | 0:4f77ae831ee7 | 118 | } |
yqin70 | 0:4f77ae831ee7 | 119 | |
yqin70 | 0:4f77ae831ee7 | 120 | // Thread 3 |
jcrane32 | 19:d65f9fb1023b | 121 | // reads pushbuttons to control menu |
jcrane32 | 6:cd24147b5e50 | 122 | void pbcontrol_thread() |
yqin70 | 0:4f77ae831ee7 | 123 | { |
jcrane32 | 19:d65f9fb1023b | 124 | // The pb variables will be zero when the pushbutton is pressed |
jcrane32 | 19:d65f9fb1023b | 125 | pb1.mode(PullUp); //pb1 is to select song |
jcrane32 | 19:d65f9fb1023b | 126 | pb2.mode(PullUp); //pb2 is to return to homescreen |
yqin70 | 0:4f77ae831ee7 | 127 | while(true) { // thread loop |
jcrane32 | 19:d65f9fb1023b | 128 | if (!pb2) { |
yqin70 | 0:4f77ae831ee7 | 129 | homescreen = true; |
yqin70 | 0:4f77ae831ee7 | 130 | songselect = false; |
jcrane32 | 19:d65f9fb1023b | 131 | playing = false; |
jcrane32 | 19:d65f9fb1023b | 132 | } |
jcrane32 | 19:d65f9fb1023b | 133 | if (!pb1) { |
yqin70 | 0:4f77ae831ee7 | 134 | songselect = true; |
jcrane32 | 19:d65f9fb1023b | 135 | } |
jcrane32 | 19:d65f9fb1023b | 136 | Thread::wait(100); |
yqin70 | 0:4f77ae831ee7 | 137 | } |
yqin70 | 0:4f77ae831ee7 | 138 | } |
yqin70 | 0:4f77ae831ee7 | 139 | |
jcrane32 | 7:15fdc55dbf66 | 140 | // Thread 4 |
jcrane32 | 19:d65f9fb1023b | 141 | // control LED effects |
jcrane32 | 19:d65f9fb1023b | 142 | void LED_thread() { |
jcrane32 | 19:d65f9fb1023b | 143 | while (true) { |
jcrane32 | 19:d65f9fb1023b | 144 | if (!playing) { //spin LED colors at start menu |
jcrane32 | 19:d65f9fb1023b | 145 | myRGBled = red; |
jcrane32 | 19:d65f9fb1023b | 146 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 147 | myRGBled = yellow; |
jcrane32 | 19:d65f9fb1023b | 148 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 149 | myRGBled = orange; |
jcrane32 | 19:d65f9fb1023b | 150 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 151 | myRGBled = blue; |
jcrane32 | 19:d65f9fb1023b | 152 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 153 | myRGBled = green; |
jcrane32 | 19:d65f9fb1023b | 154 | Thread::wait(200); |
jcrane32 | 19:d65f9fb1023b | 155 | } else if (playing) { |
jcrane32 | 19:d65f9fb1023b | 156 | |
jcrane32 | 19:d65f9fb1023b | 157 | if (bubblesMissed <= 3) { |
jcrane32 | 19:d65f9fb1023b | 158 | myRGBled = green; |
jcrane32 | 19:d65f9fb1023b | 159 | } else if (bubblesMissed <= 5) { |
jcrane32 | 19:d65f9fb1023b | 160 | myRGBled = yellow; |
jcrane32 | 19:d65f9fb1023b | 161 | } else { |
jcrane32 | 19:d65f9fb1023b | 162 | myRGBled = red; |
jcrane32 | 19:d65f9fb1023b | 163 | } |
jcrane32 | 19:d65f9fb1023b | 164 | |
jcrane32 | 19:d65f9fb1023b | 165 | Thread::wait(300); |
jcrane32 | 19:d65f9fb1023b | 166 | |
jcrane32 | 19:d65f9fb1023b | 167 | } |
jcrane32 | 19:d65f9fb1023b | 168 | } |
jcrane32 | 19:d65f9fb1023b | 169 | } |
jcrane32 | 19:d65f9fb1023b | 170 | |
jcrane32 | 19:d65f9fb1023b | 171 | // Thread 5 |
jcrane32 | 7:15fdc55dbf66 | 172 | // this thread plays music using the ticker class |
jcrane32 | 7:15fdc55dbf66 | 173 | void playsound() { |
jcrane32 | 7:15fdc55dbf66 | 174 | if (playing) { |
jcrane32 | 19:d65f9fb1023b | 175 | DACout.write(playingSong[songNdx++] / 255.0); |
jcrane32 | 19:d65f9fb1023b | 176 | if (songNdx>120000) { |
jcrane32 | 19:d65f9fb1023b | 177 | playing = false; |
jcrane32 | 19:d65f9fb1023b | 178 | songNdx = 0; |
jcrane32 | 19:d65f9fb1023b | 179 | } |
jcrane32 | 7:15fdc55dbf66 | 180 | } else { |
jcrane32 | 19:d65f9fb1023b | 181 | DACout.write(0.0); |
jcrane32 | 7:15fdc55dbf66 | 182 | songNdx = 0; |
jcrane32 | 7:15fdc55dbf66 | 183 | } |
jcrane32 | 7:15fdc55dbf66 | 184 | } |
jcrane32 | 7:15fdc55dbf66 | 185 | |
jcrane32 | 19:d65f9fb1023b | 186 | void pickSong() { |
jcrane32 | 19:d65f9fb1023b | 187 | switch (songnum) { |
jcrane32 | 19:d65f9fb1023b | 188 | case 1: |
jcrane32 | 19:d65f9fb1023b | 189 | { |
jcrane32 | 19:d65f9fb1023b | 190 | playingSong = (unsigned char *) fireflies; |
jcrane32 | 19:d65f9fb1023b | 191 | playing = true; |
jcrane32 | 19:d65f9fb1023b | 192 | break; |
jcrane32 | 19:d65f9fb1023b | 193 | } |
jcrane32 | 19:d65f9fb1023b | 194 | |
jcrane32 | 19:d65f9fb1023b | 195 | case 2: |
jcrane32 | 19:d65f9fb1023b | 196 | { |
jcrane32 | 19:d65f9fb1023b | 197 | playingSong = (unsigned char *) stacys_mom; |
jcrane32 | 19:d65f9fb1023b | 198 | playing = true; |
jcrane32 | 19:d65f9fb1023b | 199 | break; |
jcrane32 | 19:d65f9fb1023b | 200 | } |
jcrane32 | 19:d65f9fb1023b | 201 | case 3: |
jcrane32 | 19:d65f9fb1023b | 202 | { |
jcrane32 | 19:d65f9fb1023b | 203 | playingSong = (unsigned char *) sins; |
jcrane32 | 19:d65f9fb1023b | 204 | playing = true; |
jcrane32 | 19:d65f9fb1023b | 205 | break; |
jcrane32 | 19:d65f9fb1023b | 206 | } |
jcrane32 | 19:d65f9fb1023b | 207 | default: |
jcrane32 | 19:d65f9fb1023b | 208 | break; |
jcrane32 | 19:d65f9fb1023b | 209 | } |
jcrane32 | 19:d65f9fb1023b | 210 | } |
jcrane32 | 19:d65f9fb1023b | 211 | |
jcrane32 | 19:d65f9fb1023b | 212 | |
jcrane32 | 19:d65f9fb1023b | 213 | |
jcrane32 | 19:d65f9fb1023b | 214 | void showScore () { |
jcrane32 | 19:d65f9fb1023b | 215 | uLCD.color(0x00FF00); // Change text color and set up menu |
jcrane32 | 19:d65f9fb1023b | 216 | uLCD.text_bold(ON); |
jcrane32 | 19:d65f9fb1023b | 217 | uLCD.locate(1,1); |
jcrane32 | 19:d65f9fb1023b | 218 | uLCD.text_width(2); //4X size text |
jcrane32 | 19:d65f9fb1023b | 219 | uLCD.text_height(2); |
jcrane32 | 19:d65f9fb1023b | 220 | uLCD.printf("Thanks for playing Tap Tap Revolution!"); |
jcrane32 | 19:d65f9fb1023b | 221 | // winSound(); |
jcrane32 | 19:d65f9fb1023b | 222 | wait(1.5); |
jcrane32 | 19:d65f9fb1023b | 223 | |
jcrane32 | 19:d65f9fb1023b | 224 | uLCD.text_width(1); //4X size text |
jcrane32 | 19:d65f9fb1023b | 225 | uLCD.text_height(1); |
jcrane32 | 19:d65f9fb1023b | 226 | uLCD.text_bold(OFF); |
jcrane32 | 19:d65f9fb1023b | 227 | uLCD.color(0xFFFFFF); |
jcrane32 | 19:d65f9fb1023b | 228 | uLCD.locate(2,8); |
jcrane32 | 19:d65f9fb1023b | 229 | uLCD.printf("Your Score:"); |
jcrane32 | 19:d65f9fb1023b | 230 | uLCD.color(0x00FF00); |
jcrane32 | 19:d65f9fb1023b | 231 | uLCD.locate(2,10); |
jcrane32 | 19:d65f9fb1023b | 232 | |
jcrane32 | 19:d65f9fb1023b | 233 | float scorePercent = ((bubblesDrawn - bubblesMissed) / bubblesDrawn) * 100; |
jcrane32 | 19:d65f9fb1023b | 234 | uLCD.printf("%d %", scorePercent); |
jcrane32 | 19:d65f9fb1023b | 235 | wait(1.2); |
jcrane32 | 19:d65f9fb1023b | 236 | uLCD.cls(); |
jcrane32 | 19:d65f9fb1023b | 237 | uLCD.locate(5,0); |
jcrane32 | 19:d65f9fb1023b | 238 | |
jcrane32 | 19:d65f9fb1023b | 239 | Thread::wait(2000); |
jcrane32 | 19:d65f9fb1023b | 240 | } |
jcrane32 | 19:d65f9fb1023b | 241 | |
jcrane32 | 19:d65f9fb1023b | 242 | |
jcrane32 | 19:d65f9fb1023b | 243 | void play() { |
jcrane32 | 19:d65f9fb1023b | 244 | Lane *bubbleLanes[3]; |
jcrane32 | 19:d65f9fb1023b | 245 | // these positions may need to be adjusted as I assume they're positioned incorrectly... |
jcrane32 | 19:d65f9fb1023b | 246 | bubbleLanes[0] = new Lane(3,3); |
jcrane32 | 19:d65f9fb1023b | 247 | bubbleLanes[1] = new Lane(3,6); |
jcrane32 | 19:d65f9fb1023b | 248 | bubbleLanes[2] = new Lane(3,9); |
jcrane32 | 19:d65f9fb1023b | 249 | |
jcrane32 | 19:d65f9fb1023b | 250 | while (playing && !bubbleLanes[0]->isEmpty() && !bubbleLanes[1]->isEmpty() && !bubbleLanes[2]->isEmpty()) { |
jcrane32 | 19:d65f9fb1023b | 251 | |
jcrane32 | 19:d65f9fb1023b | 252 | } |
jcrane32 | 19:d65f9fb1023b | 253 | |
jcrane32 | 19:d65f9fb1023b | 254 | // return to homescreen when |
jcrane32 | 19:d65f9fb1023b | 255 | homescreen = true; |
jcrane32 | 19:d65f9fb1023b | 256 | } |
jcrane32 | 19:d65f9fb1023b | 257 | |
jcrane32 | 19:d65f9fb1023b | 258 | |
jcrane32 | 19:d65f9fb1023b | 259 | |
jcrane32 | 7:15fdc55dbf66 | 260 | int main() { |
yqin70 | 3:431877852f14 | 261 | |
jcrane32 | 19:d65f9fb1023b | 262 | uLCD.baudrate(3000000); // set baud rate to max |
jcrane32 | 19:d65f9fb1023b | 263 | |
jcrane32 | 6:cd24147b5e50 | 264 | thread1.start(homescreen_thread); |
jcrane32 | 7:15fdc55dbf66 | 265 | thread2.start(joystick_thread); |
jcrane32 | 6:cd24147b5e50 | 266 | thread3.start(pbcontrol_thread); |
jcrane32 | 19:d65f9fb1023b | 267 | thread4.start(LED_thread); |
jcrane32 | 19:d65f9fb1023b | 268 | nextsample.attach(&playsound, 1.0/8000.0); |
jcrane32 | 19:d65f9fb1023b | 269 | |
jcrane32 | 19:d65f9fb1023b | 270 | Lane *bubbleLanes[3]; |
jcrane32 | 19:d65f9fb1023b | 271 | // these positions may need to be adjusted as I assume they're positioned incorrectly... |
jcrane32 | 19:d65f9fb1023b | 272 | bubbleLanes[0] = new Lane(15,15); |
jcrane32 | 19:d65f9fb1023b | 273 | bubbleLanes[1] = new Lane(40,15); |
jcrane32 | 19:d65f9fb1023b | 274 | bubbleLanes[2] = new Lane(80,15); |
jcrane32 | 19:d65f9fb1023b | 275 | |
jcrane32 | 19:d65f9fb1023b | 276 | //startup sound? |
jcrane32 | 19:d65f9fb1023b | 277 | |
jcrane32 | 19:d65f9fb1023b | 278 | while(true) { |
jcrane32 | 19:d65f9fb1023b | 279 | if (songselect) { |
jcrane32 | 19:d65f9fb1023b | 280 | homescreen = false; |
jcrane32 | 19:d65f9fb1023b | 281 | // lcd_mutex.lock(); |
jcrane32 | 19:d65f9fb1023b | 282 | // uLCD.cls(); |
jcrane32 | 19:d65f9fb1023b | 283 | // uLCD.printf("You selected song %2d", songnum); |
jcrane32 | 19:d65f9fb1023b | 284 | // lcd_mutex.unlock(); |
jcrane32 | 19:d65f9fb1023b | 285 | pickSong(); |
jcrane32 | 19:d65f9fb1023b | 286 | |
jcrane32 | 19:d65f9fb1023b | 287 | // "playing" is updated by playsound() thread |
jcrane32 | 19:d65f9fb1023b | 288 | while (playing && !bubbleLanes[0]->isEmpty() && !bubbleLanes[1]->isEmpty() && !bubbleLanes[2]->isEmpty()) { |
jcrane32 | 19:d65f9fb1023b | 289 | // draw unufilled circles at the bottom of the screen where the user should "tap" |
jcrane32 | 19:d65f9fb1023b | 290 | uLCD.circle(15,110, 30, GREEN); |
jcrane32 | 19:d65f9fb1023b | 291 | uLCD.circle(40,110, 30, GREEN); |
jcrane32 | 19:d65f9fb1023b | 292 | uLCD.circle(80,110, 30, GREEN); |
jcrane32 | 19:d65f9fb1023b | 293 | |
jcrane32 | 19:d65f9fb1023b | 294 | // add bubbles to lanes |
jcrane32 | 19:d65f9fb1023b | 295 | if (fireflies_bubbles[bubbleNdx][0] > songNdx) { // check if it's time to load a bubble |
jcrane32 | 19:d65f9fb1023b | 296 | bool addedbubbles = false; |
jcrane32 | 19:d65f9fb1023b | 297 | if (fireflies_bubbles[bubbleNdx][2] > songNdx) { // check if add bubble at ndx |
jcrane32 | 19:d65f9fb1023b | 298 | bubbleLanes[0]->add(); |
jcrane32 | 19:d65f9fb1023b | 299 | addedbubbles = true; |
jcrane32 | 19:d65f9fb1023b | 300 | } |
jcrane32 | 19:d65f9fb1023b | 301 | |
jcrane32 | 19:d65f9fb1023b | 302 | if (fireflies_bubbles[bubbleNdx][3] > songNdx) { // check if add bubble at ndx |
jcrane32 | 19:d65f9fb1023b | 303 | bubbleLanes[1]->add(); |
jcrane32 | 19:d65f9fb1023b | 304 | addedbubbles = true; |
jcrane32 | 19:d65f9fb1023b | 305 | } |
jcrane32 | 19:d65f9fb1023b | 306 | |
jcrane32 | 19:d65f9fb1023b | 307 | if (fireflies_bubbles[bubbleNdx][4] > songNdx) { // check if add bubble at ndx |
jcrane32 | 19:d65f9fb1023b | 308 | bubbleLanes[2]->add(); |
jcrane32 | 19:d65f9fb1023b | 309 | addedbubbles = true; |
jcrane32 | 19:d65f9fb1023b | 310 | } |
jcrane32 | 19:d65f9fb1023b | 311 | |
jcrane32 | 19:d65f9fb1023b | 312 | if (addedbubbles) ++songNdx; |
ShelbyC22 | 4:59b73f321c0e | 313 | } |
jcrane32 | 19:d65f9fb1023b | 314 | |
jcrane32 | 19:d65f9fb1023b | 315 | // draw all bubbles |
jcrane32 | 19:d65f9fb1023b | 316 | bubbleLanes[0]->draw(); |
jcrane32 | 19:d65f9fb1023b | 317 | bubbleLanes[1]->draw(); |
jcrane32 | 19:d65f9fb1023b | 318 | bubbleLanes[2]->draw(); |
jcrane32 | 19:d65f9fb1023b | 319 | |
jcrane32 | 19:d65f9fb1023b | 320 | // TODO: check for hits with capacitive touchpad |
jcrane32 | 19:d65f9fb1023b | 321 | // if there is a hit, delete the bubble from the dynamic array |
jcrane32 | 19:d65f9fb1023b | 322 | if (true) bubbleLanes[0]->checkHit(); |
jcrane32 | 19:d65f9fb1023b | 323 | if (true) bubbleLanes[1]->checkHit(); |
jcrane32 | 19:d65f9fb1023b | 324 | if (true) bubbleLanes[2]->checkHit(); |
jcrane32 | 19:d65f9fb1023b | 325 | |
jcrane32 | 19:d65f9fb1023b | 326 | // move down all the bubbles, deleting bubbles that are out of bounds if required |
jcrane32 | 19:d65f9fb1023b | 327 | bubbleLanes[0]->moveDown(); |
jcrane32 | 19:d65f9fb1023b | 328 | bubbleLanes[1]->moveDown(); |
jcrane32 | 19:d65f9fb1023b | 329 | bubbleLanes[2]->moveDown(); |
jcrane32 | 19:d65f9fb1023b | 330 | |
jcrane32 | 19:d65f9fb1023b | 331 | //this wait delay may need to be tuned |
jcrane32 | 19:d65f9fb1023b | 332 | Thread::wait(100); |
ShelbyC22 | 4:59b73f321c0e | 333 | } |
jcrane32 | 19:d65f9fb1023b | 334 | |
jcrane32 | 19:d65f9fb1023b | 335 | // uncomment this when gameplay works |
jcrane32 | 19:d65f9fb1023b | 336 | //showScore(); |
jcrane32 | 19:d65f9fb1023b | 337 | |
jcrane32 | 19:d65f9fb1023b | 338 | // return to homescreen when |
jcrane32 | 19:d65f9fb1023b | 339 | songselect = false; |
jcrane32 | 19:d65f9fb1023b | 340 | homescreen = true; |
yqin70 | 0:4f77ae831ee7 | 341 | } |
jcrane32 | 19:d65f9fb1023b | 342 | Thread::wait(100); |
jcrane32 | 19:d65f9fb1023b | 343 | } |
yqin70 | 0:4f77ae831ee7 | 344 | } |