1
Fork 0

added textures from texture packs

This commit is contained in:
Jake Howard 2015-05-11 22:15:40 +01:00
parent 7ce3cbe077
commit 2769e423db
5 changed files with 18 additions and 10 deletions

View file

@ -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 = [

View file

@ -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

View file

@ -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)

View file

@ -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()

View file

@ -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