Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a reset key, fixed aliens max position & animation speed #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 23 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
bool game_running = false;
int move_dir = 0;
bool fire_pressed = 0;
bool reset = 0;

#define GL_ERROR_CASE(glerror)\
case glerror: snprintf(error, sizeof(error), "%s", #glerror)
Expand Down Expand Up @@ -79,6 +80,9 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
case GLFW_KEY_SPACE:
if(action == GLFW_RELEASE) fire_pressed = true;
break;
case GLFW_KEY_R:
if (action == GLFW_RELEASE) reset = true;
break;
default:
break;
}
Expand Down Expand Up @@ -722,6 +726,10 @@ int main(int argc, char* argv[])

glfwSwapBuffers(window);
glfwPollEvents();

if (reset)
//Exit this IF Statement... will be change properly further down.
game.player.life = 1;
continue;
}

Expand Down Expand Up @@ -984,7 +992,7 @@ int main(int argc, char* argv[])
else game.player.x += player_move_dir;
}

if(aliens_killed < game.num_aliens)
if(aliens_killed < game.num_aliens && !reset)
{
size_t ai = 0;
while(game.aliens[ai].type == ALIEN_DEAD) ++ai;
Expand All @@ -999,7 +1007,20 @@ int main(int argc, char* argv[])
}
else
{
alien_update_frequency = 120;
if (reset)
{
reset = false;
game.player.life = 3;
score = 0;
fire_pressed = false;
}
should_change_speed = true;
game.num_bullets = 0;
alien_swarm_max_position = game.width - 16 * 11 - 3; //Reset max alien width

// since we are updating speed right away to fix animation
// lets just double the initial speed.(for sub 1 frame)
alien_update_frequency = 120*2;
alien_swarm_position = 24;

aliens_killed = 0;
Expand Down