added powerups to game
This commit is contained in:
parent
b166569da3
commit
852071900e
5 changed files with 44 additions and 10 deletions
|
@ -9,7 +9,8 @@ class Textures():
|
||||||
"BULLET":"bullet",
|
"BULLET":"bullet",
|
||||||
"TARGETS":[],
|
"TARGETS":[],
|
||||||
"SHOOTER":"shooter",
|
"SHOOTER":"shooter",
|
||||||
"TARGET_BULLET":"bullet_target"
|
"TARGET_BULLET":"bullet_target",
|
||||||
|
"POWERUP": "powerup"
|
||||||
}
|
}
|
||||||
self.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\"
|
self.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\"
|
||||||
self.pack = "default"
|
self.pack = "default"
|
||||||
|
|
|
@ -2,10 +2,10 @@ import pygame
|
||||||
|
|
||||||
|
|
||||||
class Bullet(pygame.sprite.Sprite):
|
class Bullet(pygame.sprite.Sprite):
|
||||||
def __init__(self, parent, textures):
|
def __init__(self, parent, textures, bigger):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.width = 6
|
self.width = 6 * (1+int(bigger))
|
||||||
self.height = 14
|
self.height = 14 * (1+int(bigger))
|
||||||
self.image = pygame.transform.scale(textures.get_texture("BULLET"), (self.width, self.height))
|
self.image = pygame.transform.scale(textures.get_texture("BULLET"), (self.width, self.height))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.x = parent.rect.x + parent.width/2 - self.width/2
|
self.rect.x = parent.rect.x + parent.width/2 - self.width/2
|
||||||
|
|
29
game.py
29
game.py
|
@ -7,7 +7,7 @@ from player import Shooter
|
||||||
from assets import *
|
from assets import *
|
||||||
from target import Target, generate_targets
|
from target import Target, generate_targets
|
||||||
|
|
||||||
|
POWERUPS = ["SPEED", "DOUBLE", "LIVES", "SCORE", "BIGGER"]
|
||||||
PLAYING_GAME = False
|
PLAYING_GAME = False
|
||||||
WINDOW_SIZE = (680, 790)
|
WINDOW_SIZE = (680, 790)
|
||||||
HUD_COLOUR = (255,168,72)
|
HUD_COLOUR = (255,168,72)
|
||||||
|
@ -57,8 +57,8 @@ def play(window, options):
|
||||||
FPS = player.options["Difficulty"]
|
FPS = player.options["Difficulty"]
|
||||||
|
|
||||||
timeouts = {
|
timeouts = {
|
||||||
"Target Movement":[FPS*0.75,FPS*0.75],
|
"Target Movement":[FPS*0.65,FPS*0.65],
|
||||||
"Powerup":[FPS*100, FPS*100]
|
"Powerup":[FPS*15, FPS*15]
|
||||||
}
|
}
|
||||||
init_sounds()
|
init_sounds()
|
||||||
Sounds["main"].play(loops=-1) #Start background music
|
Sounds["main"].play(loops=-1) #Start background music
|
||||||
|
@ -77,14 +77,18 @@ def play(window, options):
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN and event.key in [pygame.K_SPACE, pygame.K_w, pygame.K_UP] and not fired:
|
if event.type == pygame.KEYDOWN and event.key in [pygame.K_SPACE, pygame.K_w, pygame.K_UP] and not fired:
|
||||||
if player.options["Sounds"]: Sounds["shot"].play()
|
if player.options["Sounds"]: Sounds["shot"].play()
|
||||||
temp = Bullet(player, player.options["Textures"])
|
temp = Bullet(player, player.options["Textures"], player.powerup == "BIGGER")
|
||||||
|
bullet_group.add(temp)
|
||||||
|
if player.powerup == "DOUBLE":
|
||||||
|
temp = Bullet(player, player.options["Textures"], player.powerup == "BIGGER")
|
||||||
|
temp.rect.y += 20
|
||||||
bullet_group.add(temp)
|
bullet_group.add(temp)
|
||||||
fired = True
|
fired = True
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_KP_PLUS:
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_KP_PLUS:
|
||||||
if not player.options["Sounds"] or not player.OP:
|
if not player.options["Sounds"] or not player.OP:
|
||||||
Sounds["main"].stop()
|
Sounds["main"].stop()
|
||||||
Sounds["OP"].play(loops=-1)
|
#Sounds["OP"].play(loops=-1)
|
||||||
player.OP = True
|
player.OP = True
|
||||||
player.change_colour((255,96,0))
|
player.change_colour((255,96,0))
|
||||||
elif player.OP:
|
elif player.OP:
|
||||||
|
@ -121,6 +125,9 @@ def play(window, options):
|
||||||
target_group.remove(target)
|
target_group.remove(target)
|
||||||
bullet_group.remove(bullet)
|
bullet_group.remove(bullet)
|
||||||
player.score += 1
|
player.score += 1
|
||||||
|
if target.lives <= 0 and target.type == "POWERUP":
|
||||||
|
player.powerup = POWERUPS[randint(0,len(POWERUPS)-1)]
|
||||||
|
logging.info("Powerup set to {}".format(player.powerup))
|
||||||
|
|
||||||
hit_list = pygame.sprite.spritecollide(bullet, player_group, False)
|
hit_list = pygame.sprite.spritecollide(bullet, player_group, False)
|
||||||
for player in hit_list:
|
for player in hit_list:
|
||||||
|
@ -149,10 +156,20 @@ def play(window, options):
|
||||||
|
|
||||||
timeouts["Target Movement"][0] = timeouts["Target Movement"][1]
|
timeouts["Target Movement"][0] = timeouts["Target Movement"][1]
|
||||||
|
|
||||||
|
if timeouts["Powerup"][0] <= 0:
|
||||||
|
timeouts["Powerup"][0] = timeouts["Powerup"][1]
|
||||||
|
|
||||||
|
if player.powerup == "SCORE":
|
||||||
|
player.score += 10
|
||||||
|
player.powerup = ""
|
||||||
|
elif player.powerup == "LIVES":
|
||||||
|
player.lives += 1
|
||||||
|
player.powerup = ""
|
||||||
|
|
||||||
for target in target_group:
|
for target in target_group:
|
||||||
if target.type == "SHOOTER":
|
if target.type == "SHOOTER":
|
||||||
if randint(0,600) > 1: continue
|
if randint(0,600) > 1: continue
|
||||||
temp = Bullet(target, player.options["Textures"])
|
temp = Bullet(target, player.options["Textures"], False)
|
||||||
temp.type="TARGET"
|
temp.type="TARGET"
|
||||||
temp.image = pygame.transform.scale(player.options["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
|
||||||
|
|
BIN
resources/texture_packs/default/powerup.png
Normal file
BIN
resources/texture_packs/default/powerup.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
16
target.py
16
target.py
|
@ -52,12 +52,28 @@ def generate_targets(player, window_size, Levels):
|
||||||
index = randint(0, len(sprite_list)-1) if (len(sprite_list) - 1 != 0) else 0
|
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].lives = 2
|
||||||
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))
|
||||||
x,y = sprite_list[index].rect.x, sprite_list[index].rect.y
|
x,y = sprite_list[index].rect.x, sprite_list[index].rect.y
|
||||||
sprite_list[index].rect = sprite_list[index].image.get_rect()
|
sprite_list[index].rect = sprite_list[index].image.get_rect()
|
||||||
sprite_list[index].set_position(x,y, center=False) #Already Centered!
|
sprite_list[index].set_position(x,y, center=False) #Already Centered!
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
if len(sprite_list) < level.powerups:
|
||||||
|
powerups = len(sprite_list)
|
||||||
|
else: powerups = level.powerups
|
||||||
|
for i in range(powerups):
|
||||||
|
changed = False
|
||||||
|
while not changed:
|
||||||
|
index = randint(0, len(sprite_list)-1) if (len(sprite_list) - 1 != 0) else 0
|
||||||
|
if sprite_list[index].type != "POWERUP" and sprite_list[index].type != "SHOOTER" :
|
||||||
|
sprite_list[index].type = "POWERUP"
|
||||||
|
sprite_list[index].image = pygame.transform.scale(player.options["Textures"].get_texture("POWERUP"), (sprite_list[index].width, sprite_list[index].height))
|
||||||
|
x,y = sprite_list[index].rect.x, sprite_list[index].rect.y
|
||||||
|
sprite_list[index].rect = sprite_list[index].image.get_rect()
|
||||||
|
sprite_list[index].set_position(x,y, center=False) #Already Centered!
|
||||||
|
changed = True
|
||||||
|
|
||||||
for sprite in sprite_list: #Because sprite groups dont support indexing!
|
for sprite in sprite_list: #Because sprite groups dont support indexing!
|
||||||
group.add(sprite)
|
group.add(sprite)
|
||||||
return group
|
return group
|
||||||
|
|
Reference in a new issue