1
Fork 0

tabs vs spaces, and updated logic to make it work (from last nights editing)

This commit is contained in:
Jake Howard 2015-05-12 12:16:27 +01:00
parent e34503d2bc
commit 03de948eb4

31
game.py
View file

@ -55,14 +55,14 @@ def generate_targets(player):
for i in range(level.rows):
i *= level.padding + 8
for j in range(40, WINDOW_SIZE[0] - 40, level.padding + 8):
temp = Target(x=j,y=i, player.options["Textures"])
temp = Target(x=j,y=i, textures=player.options["Textures"])
sprite_list.append(temp)
del temp
for i in range(level.firebacks):
changed = False
while not changed:
index = randint(0, len(sprite_list)-1)
index = randint(0, len(sprite_list)-1) if len(sprite_list) - 1 != 0 else 0
if sprite_list[index].type != "SHOOTER":
sprite_list[index].type = "SHOOTER"
sprite_list[index].image = pygame.transform.scale(player.options["Textures"].get_texture("SHOOTER"), (sprite_list[index].width, sprite_list[index].height))
@ -78,8 +78,8 @@ def generate_targets(player):
def play(window, options):
window_rect = window.get_rect()
player = Shooter(window=window)
options["Textures"].load_texture_pack(options["Textures"].pack)
player = Shooter(window=window, texture=options["Textures"])
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.83)
player.options = options
player_group = pygame.sprite.Group()
@ -94,6 +94,7 @@ def play(window, options):
"Target Movement":[FPS*0.5,FPS*0.5],
"Powerup":[FPS*100, FPS*100]
}
init_sounds()
Sounds["main"].play(loops=-1) #Start background music
logging.info("Game Started.")
@ -108,12 +109,14 @@ def play(window, options):
return "QUIT"
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
temp = Bullet(player)
temp = Bullet(player, player.options["Textures"])
Sounds["shot"].play()
bullet_group.add(temp)
if event.type == pygame.KEYDOWN and event.key == pygame.K_KP_PLUS:
player.OP = not player.OP
logging.info("Player is now OP!")
player.OP = True
Sounds["main"].stop()
Sounds["OP"].play(loops=-1)
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
@ -125,7 +128,7 @@ def play(window, options):
else: player.move(-player.speed)
if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6] and player.OP:
temp = Bullet(player)
temp = Bullet(player, player.options["Textures"])
bullet_group.add(temp)
if keys[pygame.K_r] and [pygame.K_9] and [pygame.K_k] and player.OP:
@ -149,7 +152,7 @@ def play(window, options):
if bullet.type == "TARGET":
bullet_group.remove(bullet)
logging.info("You were hit by a target's bullet!")
player.lives -= 1
if not player.OP: player.lives -= 1
if player.lives <= 0:
return "LIVES"
@ -160,7 +163,7 @@ def play(window, options):
if target.rect.x <= 30 or target.rect.x >=WINDOW_SIZE[0] - 30:
drop_targets = True
if target.rect.y >= player.rect.y + 20:
if target.rect.y >= player.rect.y + 35:
PLAYING_GAME = False
return "PLAYER COLLISION"
@ -174,9 +177,9 @@ def play(window, options):
for target in target_group:
if target.type == "SHOOTER":
if randint(0,375) > 1: continue
temp = Bullet(target)
temp = Bullet(target, player.options["Textures"])
temp.type="TARGET"
temp.image = pygame.transform.scale(textures.get_texture("TARGET_BULLET"), (temp.width, temp.height))
temp.image = pygame.transform.scale(player.options["Textures"].get_texture("TARGET_BULLET"), (temp.width, temp.height))
x,y = temp.rect.x, temp.rect.y
temp.rect = temp.image.get_rect()
temp.set_position(x,y)
@ -186,8 +189,8 @@ def play(window, options):
if len(target_group) == 0: #If all current players are gone.
player.level += 1
target_group = generate_targets(player)
player.change_colour(player.colours[player.level])
target_group.draw()
target_group.draw(window)
bullet_group.empty()
pygame.display.update()
sleep(1.5)