ECE 4180 Final

Dependencies:   mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem

Committer:
jcrane32
Date:
Fri Dec 06 18:00:11 2019 +0000
Revision:
20:7d56cdcbc9a5
Parent:
19:d65f9fb1023b
Child:
21:cbcbb3480cad
TODO: fix status LED (tracks bubblesMissed) and add in scoreboard at the end.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jcrane32 19:d65f9fb1023b 1 #include "Lane.hpp"
jcrane32 19:d65f9fb1023b 2 #include "globals.h"
jcrane32 19:d65f9fb1023b 3
jcrane32 19:d65f9fb1023b 4 Lane::Lane(int x, int y) {
jcrane32 19:d65f9fb1023b 5 xpos = x;
jcrane32 19:d65f9fb1023b 6 ypos = y;
jcrane32 19:d65f9fb1023b 7 empty = false;
jcrane32 19:d65f9fb1023b 8 }
jcrane32 19:d65f9fb1023b 9
jcrane32 19:d65f9fb1023b 10 void Lane::add() {
jcrane32 19:d65f9fb1023b 11 ++bubblesDrawn;
jcrane32 19:d65f9fb1023b 12 pops.push_back(Bubble(xpos, ypos));
jcrane32 19:d65f9fb1023b 13 }
jcrane32 19:d65f9fb1023b 14
jcrane32 19:d65f9fb1023b 15 void Lane::draw() {
jcrane32 20:7d56cdcbc9a5 16 if (!pops.empty()){
jcrane32 20:7d56cdcbc9a5 17 for (pops_ptr = pops.begin(); pops_ptr < pops.end(); pops_ptr++) {
jcrane32 20:7d56cdcbc9a5 18 (*pops_ptr).draw();
jcrane32 20:7d56cdcbc9a5 19 }
jcrane32 19:d65f9fb1023b 20 }
jcrane32 19:d65f9fb1023b 21 }
jcrane32 19:d65f9fb1023b 22
jcrane32 19:d65f9fb1023b 23 void Lane::moveDown() {
jcrane32 19:d65f9fb1023b 24 // move each bubble
jcrane32 19:d65f9fb1023b 25 //if they're past a certain horizontal limit, remove them from the dynamic array
jcrane32 19:d65f9fb1023b 26 if ((pops.begin())->getYpos() >= 110+20) {
jcrane32 19:d65f9fb1023b 27 // black out the bubble and remove it from the lane's vector
jcrane32 19:d65f9fb1023b 28 (pops.begin())->clear();
jcrane32 19:d65f9fb1023b 29 pops.erase(pops.begin());
jcrane32 20:7d56cdcbc9a5 30 ++bubblesMissed;
jcrane32 19:d65f9fb1023b 31 }
jcrane32 19:d65f9fb1023b 32
jcrane32 19:d65f9fb1023b 33 for (pops_ptr = pops.begin(); pops_ptr < pops.end(); pops_ptr++) {
jcrane32 19:d65f9fb1023b 34 (*pops_ptr).moveDown();
jcrane32 19:d65f9fb1023b 35 }
jcrane32 19:d65f9fb1023b 36 }
jcrane32 19:d65f9fb1023b 37
jcrane32 19:d65f9fb1023b 38 bool Lane::isEmpty() {
jcrane32 19:d65f9fb1023b 39 return pops.empty();
jcrane32 19:d65f9fb1023b 40 }
jcrane32 19:d65f9fb1023b 41
jcrane32 19:d65f9fb1023b 42 void Lane::checkHit() {
jcrane32 19:d65f9fb1023b 43 if ((pops.begin())->getYpos() <= 110+20 && (pops.begin())->getYpos() >= 110-20) {
jcrane32 19:d65f9fb1023b 44 // black out the bubble and remove it from the lane's vector
jcrane32 19:d65f9fb1023b 45 (pops.begin())->clear();
jcrane32 19:d65f9fb1023b 46 pops.erase(pops.begin());
jcrane32 19:d65f9fb1023b 47 }
jcrane32 19:d65f9fb1023b 48 }