diff --git a/Frog.cpp b/Frog.cpp index 13216c3..3b53e1b 100644 --- a/Frog.cpp +++ b/Frog.cpp @@ -86,14 +86,14 @@ bool Frog::collision(Obstacle* other) { return !(positionX + width <= other->getX() || positionX >= other->getX() + other->getWidth() || positionY + 32 <= other->getY() || positionY >= other->getY() + 32); } -void Frog::touchdown() { +bool Frog::touchdown() { if (positionY == 64) { for (int i = 0; i < 6; i++) { if (positionX >= 64 + (i * 96) - 8 && positionX <= 96 + (i * 96) + 8 && !base[i]) { base[i] = 1; positionX = STARTING_POSITION_X; positionY = STARTING_POSITION_Y; - return; + return true; } } for (int i = 0; i < 6; i++) { @@ -101,14 +101,15 @@ void Frog::touchdown() { base[i] = 1; positionX = STARTING_POSITION_X; positionY = STARTING_POSITION_Y; - return; + return true; } else { reset(); - return; + return false; } } } + return false; } bool Frog::endGame() { diff --git a/Frog.h b/Frog.h index 7f9fb27..abd6a00 100644 --- a/Frog.h +++ b/Frog.h @@ -26,7 +26,7 @@ class Frog { bool isAlive(); int getLives(); bool collision(Obstacle* other); - void touchdown(); + bool touchdown(); bool endGame(); }; diff --git a/main.cpp b/main.cpp index 3890f59..7de6834 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ int main(int argc, char** argv) { Obstacle** logs = new Obstacle * [20]; for (int i = 0; i < 5; i++) { + /* trucks[i] = new Obstacle(i * 256, 256, 96, 32, -0.3, "images/truck_head_left.bmp"); trucks[i + 5] = new Obstacle(i * 288, 288, 64, 32, 0.7, "images/car_head_right.bmp"); trucks[i + 10] = new Obstacle(i * 288, 320, 64, 32, -0.5, "images/car_head_left.bmp"); @@ -24,6 +25,17 @@ int main(int argc, char** argv) { logs[i + 5] = new Obstacle(i * 288, 128, 64, 32, 0.5, "images/turtle_size_2.bmp"); logs[i + 10] = new Obstacle(i * 288, 160, 96, 32, -0.7, "images/log_size_3.bmp"); logs[i + 15] = new Obstacle(i * 256, 192, 64, 32, 0.3, "images/turtle_size_2.bmp"); + */ + + trucks[i] = new Obstacle(i * 256, 256, 96, 32, -0.1, "images/truck_head_left.bmp"); + trucks[i + 5] = new Obstacle(i * 288, 288, 64, 32, 0.1, "images/car_head_right.bmp"); + trucks[i + 10] = new Obstacle(i * 288, 320, 64, 32, -0.1, "images/car_head_left.bmp"); + trucks[i + 15] = new Obstacle(i * 256, 352, 96, 32, 0.1, "images/truck_head_right.bmp"); + + logs[i] = new Obstacle(i * 256, 96, 96, 32, -0.1, "images/log_size_3.bmp"); + logs[i + 5] = new Obstacle(i * 288, 128, 64, 32, 0.1, "images/turtle_size_2.bmp"); + logs[i + 10] = new Obstacle(i * 288, 160, 96, 32, -0.1, "images/log_size_3.bmp"); + logs[i + 15] = new Obstacle(i * 256, 192, 64, 32, 0.1, "images/turtle_size_2.bmp"); } int t1 = SDL_GetTicks(); @@ -67,14 +79,22 @@ int main(int argc, char** argv) { } } if (!dead) frog->move(speed); - else frog->reset(); + else { + frog->reset(); + time = 0; + } } else { for (int i = 0; i < 20; i++) { - if (frog->collision(trucks[i])) frog->reset(); + if (frog->collision(trucks[i])) { + frog->reset(); + time = 0; + } } } - frog->touchdown(); + if (frog->touchdown()) { + time = 0; + } // drawing objects for (int i = 0; i < 20; i++) {