From 2769e423db67b764183516388c2a1589c22afb08 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 11 May 2015 22:15:40 +0100 Subject: [PATCH] added textures from texture packs --- assets.py | 8 +++++++- bullet.py | 3 +-- game.py | 6 +++++- player.py | 5 ++--- target.py | 6 +++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/assets.py b/assets.py index 2165d25..25ded18 100644 --- a/assets.py +++ b/assets.py @@ -7,7 +7,9 @@ class Textures(): self.images = { "PLAYER":"player.png", "BULLET":"bullet.png", - "TARGETS":[] + "TARGETS":[], + "SHOOTER":"shooter.png", + "TARGET_BULLET":"target_bullet.png" } self.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\" self.pack = "default" @@ -28,6 +30,10 @@ class Textures(): filename = self.path + self.pack + "\\{0}.png".format(self.images[objectName.upper()]) return pygame.image.load(filename) + def get_target_texture(self): + filename = self.path + self.pack + "\\{}.png".format(self.images["TARGETS"][randint(0,len(self.images["TARGETS"]))]) + return pygame.image.load(filename) + Level_Template = namedtuple('Level_Template', ("rows", "padding", "firebacks", "powerups")) Levels = [ diff --git a/bullet.py b/bullet.py index 4ecd394..dbd7e92 100644 --- a/bullet.py +++ b/bullet.py @@ -6,8 +6,7 @@ class Bullet(pygame.sprite.Sprite): super().__init__() self.width = 4 self.height = 10 - self.image = pygame.Surface((self.width, self.height)) - self.image.fill((255,255,255)) + self.image = pygame.transform.scale(textures.get_texture("BULLET"), (self.width, self.height)) self.rect = self.image.get_rect() self.rect.x = parent.rect.x + parent.width/2 - self.width/2 self.rect.y = parent.rect.y + parent.height/2 diff --git a/game.py b/game.py index 8ff2b5d..dd31b10 100644 --- a/game.py +++ b/game.py @@ -64,7 +64,7 @@ def generate_targets(player): index = randint(0, len(sprite_list)-1) if sprite_list[index].type != "SHOOTER": sprite_list[index].type = "SHOOTER" - sprite_list[index].image.fill((0,255,0)) + 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 sprite_list[index].rect = sprite_list[index].image.get_rect() sprite_list[index].set_position(x,y, center=False) @@ -175,6 +175,10 @@ def play(window): if randint(0,375) > 1: continue temp = Bullet(target) temp.type="TARGET" + temp.image = pygame.transform.scale(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) temp.speed = -3 #So it shoots down! bullet_group.add(temp) diff --git a/player.py b/player.py index eb72e96..f6066fe 100644 --- a/player.py +++ b/player.py @@ -2,13 +2,12 @@ import pygame class Shooter(pygame.sprite.Sprite): - def __init__(self, window, colour=(255,255,255), width=45, height=20): + def __init__(self, window, texture, colour=(255,255,255), width=45, height=20): super().__init__() self.width = width self.height = height self.colour = colour - self.image = pygame.Surface((width, height)) - self.image.fill(self.colour) + self.image = pygame.transform.scale(textures.get_texture("PLAYER"), (self.width, self.height)) self.rect = self.image.get_rect() self.speed = 3 self.window_rect = window.get_rect() diff --git a/target.py b/target.py index 047a5ec..46794b7 100644 --- a/target.py +++ b/target.py @@ -1,13 +1,13 @@ import pygame +from random import randint class Target(pygame.sprite.Sprite): - def __init__(self, x, y, color=(30,0,150), width=16, height=16): + def __init__(self, x, y, textures, color=(30,0,150), width=16, height=16): super().__init__() self.width = width self.height = height - self.image = pygame.Surface((self.width, self.height)) - self.image.fill(color) + self.image = pygame.transform.scale(textures.get_target_texture(), (self.width, self.height)) self.rect = self.image.get_rect() self.speed = 7 self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates