stupid indenting, updated logic, and upped FPS
This commit is contained in:
parent
59a35548a6
commit
392f97be4f
1 changed files with 33 additions and 33 deletions
66
game.py
66
game.py
|
@ -9,7 +9,7 @@ from target import Target
|
||||||
|
|
||||||
PLAYING_GAME = False
|
PLAYING_GAME = False
|
||||||
WINDOW_SIZE = (640,480)
|
WINDOW_SIZE = (640,480)
|
||||||
FPS = 60
|
FPS = 120
|
||||||
|
|
||||||
def rounding(x, base): return int(base * round(float(x)/base))
|
def rounding(x, base): return int(base * round(float(x)/base))
|
||||||
|
|
||||||
|
@ -18,11 +18,9 @@ def initialise(menu, options):
|
||||||
pygame.mixer.pre_init(44100, -16, 2, 2048)
|
pygame.mixer.pre_init(44100, -16, 2, 2048)
|
||||||
pygame.init()
|
pygame.init()
|
||||||
window = pygame.display.set_mode(WINDOW_SIZE)
|
window = pygame.display.set_mode(WINDOW_SIZE)
|
||||||
window_rect = window.get_rect()
|
|
||||||
|
|
||||||
|
|
||||||
exit_code = play(window) # Run main game loop
|
exit_code = play(window) # Run main game loop
|
||||||
|
if exit_code =
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
# Reshow the main menu
|
# Reshow the main menu
|
||||||
|
|
||||||
|
@ -41,10 +39,13 @@ def generate_targets():
|
||||||
|
|
||||||
|
|
||||||
def play(window):
|
def play(window):
|
||||||
player = Shooter()
|
window_rect = window.get_rect()
|
||||||
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.9)
|
|
||||||
|
player = Shooter(window=window)
|
||||||
|
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.93)
|
||||||
player_group = pygame.sprite.Group()
|
player_group = pygame.sprite.Group()
|
||||||
player_group.add(player)
|
player_group.add(player)
|
||||||
|
player_group.draw(window)
|
||||||
|
|
||||||
target_group = generate_targets()
|
target_group = generate_targets()
|
||||||
bullet_group = pygame.sprite.Group()
|
bullet_group = pygame.sprite.Group()
|
||||||
|
@ -54,8 +55,7 @@ def play(window):
|
||||||
|
|
||||||
while PLAYING_GAME:
|
while PLAYING_GAME:
|
||||||
window.fill((0,0,0))
|
window.fill((0,0,0))
|
||||||
target_group.update()
|
player_group.update()
|
||||||
bullet_group.update()
|
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
@ -67,36 +67,36 @@ def play(window):
|
||||||
temp = Bullet(player)
|
temp = Bullet(player)
|
||||||
bullet_group.add(temp)
|
bullet_group.add(temp)
|
||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_RIGHT]:
|
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
|
||||||
player.move(player.speed)
|
player.move(player.speed)
|
||||||
|
|
||||||
if keys[pygame.K_LEFT]:
|
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
|
||||||
player.move(-player.speed)
|
player.move(-player.speed)
|
||||||
|
|
||||||
if keys[pygame.K_s]:
|
if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6]:
|
||||||
temp = Bullet(player)
|
temp = Bullet(player)
|
||||||
bullet_group.add(temp)
|
bullet_group.add(temp)
|
||||||
|
|
||||||
for sprite in bullet_group:
|
for sprite in bullet_group:
|
||||||
if not sprite.at_goal():
|
if not sprite.at_top():
|
||||||
sprite.to_goal()
|
sprite.update()
|
||||||
if sprite.rect.y < 0:
|
if sprite.rect.y < 0:
|
||||||
bullet_group.remove(sprite)
|
bullet_group.remove(sprite)
|
||||||
|
|
||||||
for bullet in bullet_group:
|
for bullet in bullet_group:
|
||||||
hit_list = pygame.sprite.spritecollide(bullet, target_group, True)
|
hit_list = pygame.sprite.spritecollide(bullet, target_group, True)
|
||||||
for target in hit_list:
|
for target in hit_list:
|
||||||
target_group.remove(target)
|
target_group.remove(target)
|
||||||
bullet_group.remove(bullet)
|
bullet_group.remove(bullet)
|
||||||
logging.info("Hit Target!")
|
logging.info("Hit Target!")
|
||||||
|
|
||||||
|
player_group.update()
|
||||||
bullet_group.draw(window)
|
bullet_group.draw(window)
|
||||||
target_group.draw(window)
|
target_group.draw(window)
|
||||||
player_group.draw(window)
|
player_group.draw(window)
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
clock.tick(FPS)
|
clock.tick(FPS)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Reference in a new issue