Faizan and Pages fun little game
Dependencies: 4DGL-uLCD-SE mbed SDFileSystem wave_player
Diff: stack.cpp
- Revision:
- 3:058e10b8ecf6
- Parent:
- 2:4c5f409d6bb8
- Child:
- 4:c00da0b158c4
diff -r 4c5f409d6bb8 -r 058e10b8ecf6 stack.cpp --- a/stack.cpp Mon Oct 31 00:59:12 2016 +0000 +++ b/stack.cpp Mon Oct 31 02:53:59 2016 +0000 @@ -22,10 +22,48 @@ Food bread(uLCD); stackOfFood.push_back(bread); lcd = uLCD; + top = 4; } void Stack::move(int dx) { // constrain if (dx < 0) x = MAX(x + dx); else x = MIN(x + dx); +} + +int Stack::size() { + return stackOfFood.size(); +} + +void Stack::clear() { + erase(); + stackOfFood.clear(); + Food bread(lcd); + stackOfFood.push_back(bread); + draw(); +} + +void Stack::erase() { + // ERASE + lcd->filled_rectangle(x, 4, x + 16, top - 1, BLACK); +} + +void Stack::draw() { + // DRAW (loop thru food vector) + lcd->filled_rectangle(x - 1, 1, x + 17, 3, WHITE); + int j = 4; + for (int i = 0; i < stackOfFood.size(); i++) { + stackOfFood[i].x = x; + stackOfFood[i].y = j; + stackOfFood[i].draw(); + j += 4; + } +} + +void Stack::add(Food * collided) { + collided->x = x; + collided->y = top; + top += 4; + stackOfFood.push_back(*collided); + draw(); } \ No newline at end of file