ECE 4180 Final

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

Committer:
jcrane32
Date:
Fri Dec 06 15:46:16 2019 +0000
Revision:
19:d65f9fb1023b
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?

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 19:d65f9fb1023b 16 for (pops_ptr = pops.begin(); pops_ptr < pops.end(); pops_ptr++) {
jcrane32 19:d65f9fb1023b 17 (*pops_ptr).draw();
jcrane32 19:d65f9fb1023b 18 }
jcrane32 19:d65f9fb1023b 19 }
jcrane32 19:d65f9fb1023b 20
jcrane32 19:d65f9fb1023b 21 void Lane::moveDown() {
jcrane32 19:d65f9fb1023b 22 // move each bubble
jcrane32 19:d65f9fb1023b 23 //if they're past a certain horizontal limit, remove them from the dynamic array
jcrane32 19:d65f9fb1023b 24 if ((pops.begin())->getYpos() >= 110+20) {
jcrane32 19:d65f9fb1023b 25 // black out the bubble and remove it from the lane's vector
jcrane32 19:d65f9fb1023b 26 (pops.begin())->clear();
jcrane32 19:d65f9fb1023b 27 pops.erase(pops.begin());
jcrane32 19:d65f9fb1023b 28 }
jcrane32 19:d65f9fb1023b 29
jcrane32 19:d65f9fb1023b 30 for (pops_ptr = pops.begin(); pops_ptr < pops.end(); pops_ptr++) {
jcrane32 19:d65f9fb1023b 31 (*pops_ptr).moveDown();
jcrane32 19:d65f9fb1023b 32 }
jcrane32 19:d65f9fb1023b 33 }
jcrane32 19:d65f9fb1023b 34
jcrane32 19:d65f9fb1023b 35 bool Lane::isEmpty() {
jcrane32 19:d65f9fb1023b 36 return pops.empty();
jcrane32 19:d65f9fb1023b 37 }
jcrane32 19:d65f9fb1023b 38
jcrane32 19:d65f9fb1023b 39 void Lane::checkHit() {
jcrane32 19:d65f9fb1023b 40 if ((pops.begin())->getYpos() <= 110+20 && (pops.begin())->getYpos() >= 110-20) {
jcrane32 19:d65f9fb1023b 41 // black out the bubble and remove it from the lane's vector
jcrane32 19:d65f9fb1023b 42 (pops.begin())->clear();
jcrane32 19:d65f9fb1023b 43 pops.erase(pops.begin());
jcrane32 19:d65f9fb1023b 44 }
jcrane32 19:d65f9fb1023b 45 }