Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Frog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,30 @@ 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++) {
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;
}
else {
reset();
return;
return false;
}
}
}
return false;
}

bool Frog::endGame() {
Expand Down
2 changes: 1 addition & 1 deletion Frog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Frog {
bool isAlive();
int getLives();
bool collision(Obstacle* other);
void touchdown();
bool touchdown();
bool endGame();
};

26 changes: 23 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down Expand Up @@ -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++) {
Expand Down