Skip to content

Commit

Permalink
Issue rodrigets#9
Browse files Browse the repository at this point in the history
Implemented.
  • Loading branch information
AK-007 committed Oct 6, 2017
1 parent b334dce commit b5fb817
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions asteroides.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sys import exit
from random import randrange


counter=0
def main():

pygame.init()
Expand All @@ -15,7 +15,7 @@ def main():
font_name = pygame.font.get_default_font()
game_font = pygame.font.SysFont(font_name, 72)

screen = pygame.display.set_mode((956, 560), 0, 32)
screen = pygame.display.set_mode((956, 560))

background_filename = 'seamless_space.png'
background = pygame.image.load(background_filename).convert()
Expand Down Expand Up @@ -50,7 +50,9 @@ def main():

clock = pygame.time.Clock()


global counter
t=game_font.render("Score : "+str(counter),1,(255, 0, 0))
screen.blit(t,(700,2))
def create_asteroid():
return {
'surface': pygame.image.load('asteroid.png').convert_alpha(),
Expand Down Expand Up @@ -92,12 +94,14 @@ def remove_missed_shots():

def shoot_asteroids():
# check for collisions between shots and asteroids
for shot in shots:
shot_rect = get_rect(shot)
for asteroid in asteroids:
if shot_rect.colliderect(get_rect(asteroid)):
shots.remove(shot)
asteroids.remove(asteroid)
for shot in shots:
shot_rect = get_rect(shot)
for asteroid in asteroids:
if shot_rect.colliderect(get_rect(asteroid)):
shots.remove(shot)
asteroids.remove(asteroid)
global counter
counter+=5

def move_asteroids():
for asteroid in asteroids:
Expand Down Expand Up @@ -161,10 +165,10 @@ def ship_collided():

if pressed_keys[K_SPACE] and ticks_to_shot <= 0:
# play sound
fire_sound.play()
shots.append(create_shot(ship))
fire_sound.play()
shots.append(create_shot(ship))
# set timer for next possible shot
ticks_to_shot = 15
ticks_to_shot = 15


# moving the background to simulate space travel
Expand All @@ -190,12 +194,13 @@ def ship_collided():
move_asteroids()
move_shots()
shoot_asteroids()

t=game_font.render("Score : "+str(counter),True,(255, 0, 0))
screen.blit(t,(700,2))
for asteroid in asteroids:
screen.blit(asteroid['surface'], asteroid['position'])

for shot in shots:
screen.blit(shot['surface'], shot['position'])
screen.blit(shot['surface'], shot['position'])


if not collided:
Expand All @@ -222,6 +227,7 @@ def ship_collided():
pressed_keys = pygame.key.get_pressed()

if pressed_keys[K_r]:
counter=0
main()

else:
Expand Down

0 comments on commit b5fb817

Please sign in to comment.