tabs vs spaces, and updated logic to make it work (from last nights editing)
This commit is contained in:
parent
e34503d2bc
commit
03de948eb4
1 changed files with 155 additions and 152 deletions
31
game.py
31
game.py
|
@ -55,14 +55,14 @@ def generate_targets(player):
|
||||||
for i in range(level.rows):
|
for i in range(level.rows):
|
||||||
i *= level.padding + 8
|
i *= level.padding + 8
|
||||||
for j in range(40, WINDOW_SIZE[0] - 40, 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)
|
sprite_list.append(temp)
|
||||||
del temp
|
del temp
|
||||||
|
|
||||||
for i in range(level.firebacks):
|
for i in range(level.firebacks):
|
||||||
changed = False
|
changed = False
|
||||||
while not changed:
|
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":
|
if sprite_list[index].type != "SHOOTER":
|
||||||
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))
|
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):
|
def play(window, options):
|
||||||
window_rect = window.get_rect()
|
window_rect = window.get_rect()
|
||||||
|
options["Textures"].load_texture_pack(options["Textures"].pack)
|
||||||
player = Shooter(window=window)
|
player = Shooter(window=window, texture=options["Textures"])
|
||||||
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.83)
|
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.83)
|
||||||
player.options = options
|
player.options = options
|
||||||
player_group = pygame.sprite.Group()
|
player_group = pygame.sprite.Group()
|
||||||
|
@ -94,6 +94,7 @@ def play(window, options):
|
||||||
"Target Movement":[FPS*0.5,FPS*0.5],
|
"Target Movement":[FPS*0.5,FPS*0.5],
|
||||||
"Powerup":[FPS*100, FPS*100]
|
"Powerup":[FPS*100, FPS*100]
|
||||||
}
|
}
|
||||||
|
init_sounds()
|
||||||
Sounds["main"].play(loops=-1) #Start background music
|
Sounds["main"].play(loops=-1) #Start background music
|
||||||
|
|
||||||
logging.info("Game Started.")
|
logging.info("Game Started.")
|
||||||
|
@ -108,12 +109,14 @@ def play(window, options):
|
||||||
return "QUIT"
|
return "QUIT"
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
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)
|
bullet_group.add(temp)
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_KP_PLUS:
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_KP_PLUS:
|
||||||
player.OP = not player.OP
|
player.OP = True
|
||||||
logging.info("Player is now OP!")
|
Sounds["main"].stop()
|
||||||
|
Sounds["OP"].play(loops=-1)
|
||||||
|
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
|
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
|
||||||
|
@ -125,7 +128,7 @@ def play(window, options):
|
||||||
else: player.move(-player.speed)
|
else: player.move(-player.speed)
|
||||||
|
|
||||||
if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6] and player.OP:
|
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)
|
bullet_group.add(temp)
|
||||||
|
|
||||||
if keys[pygame.K_r] and [pygame.K_9] and [pygame.K_k] and player.OP:
|
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":
|
if bullet.type == "TARGET":
|
||||||
bullet_group.remove(bullet)
|
bullet_group.remove(bullet)
|
||||||
logging.info("You were hit by a target's 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:
|
if player.lives <= 0:
|
||||||
return "LIVES"
|
return "LIVES"
|
||||||
|
|
||||||
|
@ -160,7 +163,7 @@ def play(window, options):
|
||||||
if target.rect.x <= 30 or target.rect.x >=WINDOW_SIZE[0] - 30:
|
if target.rect.x <= 30 or target.rect.x >=WINDOW_SIZE[0] - 30:
|
||||||
drop_targets = True
|
drop_targets = True
|
||||||
|
|
||||||
if target.rect.y >= player.rect.y + 20:
|
if target.rect.y >= player.rect.y + 35:
|
||||||
PLAYING_GAME = False
|
PLAYING_GAME = False
|
||||||
return "PLAYER COLLISION"
|
return "PLAYER COLLISION"
|
||||||
|
|
||||||
|
@ -174,9 +177,9 @@ def play(window, options):
|
||||||
for target in target_group:
|
for target in target_group:
|
||||||
if target.type == "SHOOTER":
|
if target.type == "SHOOTER":
|
||||||
if randint(0,375) > 1: continue
|
if randint(0,375) > 1: continue
|
||||||
temp = Bullet(target)
|
temp = Bullet(target, player.options["Textures"])
|
||||||
temp.type="TARGET"
|
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
|
x,y = temp.rect.x, temp.rect.y
|
||||||
temp.rect = temp.image.get_rect()
|
temp.rect = temp.image.get_rect()
|
||||||
temp.set_position(x,y)
|
temp.set_position(x,y)
|
||||||
|
@ -186,8 +189,8 @@ def play(window, options):
|
||||||
if len(target_group) == 0: #If all current players are gone.
|
if len(target_group) == 0: #If all current players are gone.
|
||||||
player.level += 1
|
player.level += 1
|
||||||
target_group = generate_targets(player)
|
target_group = generate_targets(player)
|
||||||
player.change_colour(player.colours[player.level])
|
target_group.draw(window)
|
||||||
target_group.draw()
|
bullet_group.empty()
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
sleep(1.5)
|
sleep(1.5)
|
||||||
|
|
||||||
|
|
Reference in a new issue