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

Space invaders #9

Merged
merged 28 commits into from
Aug 4, 2017
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f889917
Add initial commit of space invaders
alessandro-bugatti Jun 26, 2017
b07142f
Introduce structs instead of plain variables
alessandro-bugatti Jun 26, 2017
5ac94ac
Introduce tank movements
alessandro-bugatti Jun 26, 2017
2928f65
Add functions to update and draw objects
alessandro-bugatti Jun 28, 2017
47b89c0
Fix typo
alessandro-bugatti Jun 28, 2017
8b80117
Add score
alessandro-bugatti Jun 28, 2017
2d64b53
Add leading zeros to the score
alessandro-bugatti Jun 28, 2017
11ac0b8
Add lives drawing
alessandro-bugatti Jun 28, 2017
6c254af
Add lives management
alessandro-bugatti Jun 28, 2017
6bc5c4a
Add game over
alessandro-bugatti Jun 29, 2017
b03191c
Erase README content
alessandro-bugatti Jun 30, 2017
c56d9ed
Add aliens' shots
alessandro-bugatti Jul 6, 2017
27de911
Improve aliens' bullets management
alessandro-bugatti Jul 6, 2017
30ee90f
Merge branch 'master' into space_invaders
alessandro-bugatti Jul 18, 2017
ffaff15
Add tank collision with alien's bullets
alessandro-bugatti Jul 18, 2017
6d6b821
Improve Game Over message
alessandro-bugatti Jul 18, 2017
f3e9aa7
Add update_tank function to check tank out of bounds
alessandro-bugatti Jul 20, 2017
317f215
Fix alien ships collision with the tank
alessandro-bugatti Jul 20, 2017
78fbaa3
Add background music
alessandro-bugatti Jul 20, 2017
5dbc3d0
Add sound effects
alessandro-bugatti Jul 20, 2017
6a44256
Fix aliens shooting
alessandro-bugatti Jul 20, 2017
ca178e2
Add basic levels management
alessandro-bugatti Jul 20, 2017
9757b32
Improve tank shooting
alessandro-bugatti Jul 20, 2017
5f8a0d9
Add best scores management
alessandro-bugatti Jul 27, 2017
7395f13
Merge branch 'master' into space_invaders
alessandro-bugatti Jul 27, 2017
e06a9d9
Add multiple games management
alessandro-bugatti Jul 28, 2017
6b16a8e
Fix english typo
alessandro-bugatti Aug 4, 2017
2380ecd
Add readme
alessandro-bugatti Aug 4, 2017
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
Prev Previous commit
Next Next commit
Add multiple games management
alessandro-bugatti committed Jul 28, 2017
commit e06a9d916c7ba13f1524555b5d9fea28632652f1
105 changes: 65 additions & 40 deletions lessons/0999_space_invaders/main.cpp
Original file line number Diff line number Diff line change
@@ -519,6 +519,25 @@ void game_over()

}

void repeat_game()
{
int w = text_width(main_font,80,"Play again?");
int h = text_height(main_font,80,"Play again?");

draw_filled_rect(0,0,get_window_width(), get_window_height(),
Color(0,0,0,255));
draw_text(main_font,80,"Play again?",(get_window_width()-w)/2,
(get_window_height()-h)/2,
Color(255,255,255,255));
w = text_width(main_font,80,"[y/n]");
h = text_height(main_font,80,"[y/n]");
draw_text(main_font,80,"[y/n]",(get_window_width()-w)/2,
(get_window_height()-h)/2 + 80,
Color(255,255,255,255));
update();

}

int main(int argc, char* argv[]) {

//init the library
@@ -528,50 +547,56 @@ int main(int argc, char* argv[]) {
int i;
right_border = (get_window_width() - SPACE*2 - (DIM+SPACE)*N_SHIPS);
read_best_scores();
init_ships();
init_tank();
play_music("sounds/loopy.wav");
splashscreen();
while(!done() && lives > 0)
{
update_ships();
read_input();
alien_shot();
update_tank();
update_bullet();
update_alien_bullets();
draw_filled_rect(0,0,get_window_width(),get_window_height(),
Color(0,0,0,255)); //the background
draw_ships();
draw_tank();
draw_bullet();
draw_alien_bullets();
if (alien_striked())
points += hit_value;
if (lost_life())
{
init_ships();
init_tank();
lives--;
}
if (level_completed())
do{
lives = 3;
points = 0;
undone();
init_ships();
init_tank();
while(!done() && lives > 0)
{
init_ships();
init_tank();
SPEED += 0.05;
lives++;
level++;
update_ships();
read_input();
alien_shot();
update_tank();
update_bullet();
update_alien_bullets();
draw_filled_rect(0,0,get_window_width(),get_window_height(),
Color(0,0,0,255)); //the background
draw_ships();
draw_tank();
draw_bullet();
draw_alien_bullets();
if (alien_striked())
points += hit_value;
if (lost_life())
{
init_ships();
init_tank();
lives--;
}
if (level_completed())
{
init_ships();
init_tank();
SPEED += 0.05;
lives++;
level++;
}
draw_points();
draw_lives();
update();
}
draw_points();
draw_lives();
update();
}
game_over();
wait_for_button_pressed();
if (points >= minimum_score())
add_new_record();
draw_best_scores();
wait_for_button_pressed();
game_over();
wait_for_button_pressed();
if (points >= minimum_score())
add_new_record();
draw_best_scores();
wait_for_button_pressed();
repeat_game();
}while('y' == read_key());
stop_music();
save_best_scores();
//close the library and clean up everything