1
Fork 0

stupid indenting, updated logic, and upped FPS

This commit is contained in:
Jake Howard 2015-04-29 09:48:26 +01:00
parent 59a35548a6
commit 392f97be4f

28
game.py
View file

@ -9,7 +9,7 @@ from target import Target
PLAYING_GAME = False
WINDOW_SIZE = (640,480)
FPS = 60
FPS = 120
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.init()
window = pygame.display.set_mode(WINDOW_SIZE)
window_rect = window.get_rect()
exit_code = play(window) # Run main game loop
if exit_code =
pygame.quit()
# Reshow the main menu
@ -41,10 +39,13 @@ def generate_targets():
def play(window):
player = Shooter()
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.9)
window_rect = window.get_rect()
player = Shooter(window=window)
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.93)
player_group = pygame.sprite.Group()
player_group.add(player)
player_group.draw(window)
target_group = generate_targets()
bullet_group = pygame.sprite.Group()
@ -54,8 +55,7 @@ def play(window):
while PLAYING_GAME:
window.fill((0,0,0))
target_group.update()
bullet_group.update()
player_group.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
@ -68,19 +68,19 @@ def play(window):
bullet_group.add(temp)
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT]:
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
player.move(player.speed)
if keys[pygame.K_LEFT]:
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
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)
bullet_group.add(temp)
for sprite in bullet_group:
if not sprite.at_goal():
sprite.to_goal()
if not sprite.at_top():
sprite.update()
if sprite.rect.y < 0:
bullet_group.remove(sprite)
@ -91,7 +91,7 @@ def play(window):
bullet_group.remove(bullet)
logging.info("Hit Target!")
player_group.update()
bullet_group.draw(window)
target_group.draw(window)
player_group.draw(window)