Faizan and Pages fun little game
Dependencies: 4DGL-uLCD-SE mbed SDFileSystem wave_player
Diff: main.cpp
- Revision:
- 2:4c5f409d6bb8
- Parent:
- 1:9eeeb0d8f036
- Child:
- 3:058e10b8ecf6
--- a/main.cpp Sat Oct 29 19:35:46 2016 +0000 +++ b/main.cpp Mon Oct 31 00:59:12 2016 +0000 @@ -4,6 +4,7 @@ #include "stack.h" #include <ctime> #include <cstdlib> +#include <vector> #define BREAD 1 #define LETTUCE 2 @@ -15,25 +16,32 @@ uLCD_4DGL lcd(p9,p10,p11); vector<Food> foods; -Food collidedFood; +Food collided(&lcd); Stack sandwich(64,&lcd); -BusIn left(p7); -BusIn right(p5); -int score; +DigitalIn right(p19); +DigitalIn left(p20); +int score, lives; +float clk, clk2; +Timer t; + +bool collisionCheck(); int main() { score = 0; + lives = 3; left.mode(PullUp); right.mode(PullUp); + t.start(); srand(time(NULL)); + clk = clk2 = 0; + lcd.line(1, 112, 126, 112, WHITE); - while(1) { + while(lives) { if (!left) { sandwich.move(-1); - } - if (!right) { + } else if (!right) { sandwich.move(+1); } if (collisionCheck()) { @@ -45,8 +53,29 @@ // add to stack, remove from falling object list, redraw } // every 3 seconds add new food! use timer. + float curr = t.read(); + if (curr - clk >= 3.0) { + clk = curr; + // lcd.printf(" new "); + int x = rand()%110+1; + int type = rand()%7+1; + Food item(type, x, &lcd); + foods.push_back(item); + // add new food + } // every .2 second each food should fall a lil bit! use timer. + if (curr - clk2 >= 0.2) { + clk2 = curr; + // lcd.printf(" fall "); + for (int i = 0; i < foods.size(); i++) { + Food * f = &foods[i]; + f->fall(); + } + // each food should fall a lil bit! + } } + + lcd.printf("Your score is: %i", score); } bool collisionCheck() { @@ -59,5 +88,6 @@ // if something found // collidedFood = that food item // return true -} + return NULL; +}