ECE 4180 Final

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

Committer:
yqin70
Date:
Sun Dec 08 02:18:30 2019 +0000
Revision:
21:cbcbb3480cad
Parent:
20:7d56cdcbc9a5
somewhat done(pushbutton added, has an issue where if you spam the touchpad, it'll increase your score even if there is no bubble).

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