added textures from texture packs
This commit is contained in:
parent
7ce3cbe077
commit
2769e423db
5 changed files with 18 additions and 10 deletions
|
@ -7,7 +7,9 @@ class Textures():
|
||||||
self.images = {
|
self.images = {
|
||||||
"PLAYER":"player.png",
|
"PLAYER":"player.png",
|
||||||
"BULLET":"bullet.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.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\"
|
||||||
self.pack = "default"
|
self.pack = "default"
|
||||||
|
@ -28,6 +30,10 @@ class Textures():
|
||||||
filename = self.path + self.pack + "\\{0}.png".format(self.images[objectName.upper()])
|
filename = self.path + self.pack + "\\{0}.png".format(self.images[objectName.upper()])
|
||||||
return pygame.image.load(filename)
|
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"))
|
Level_Template = namedtuple('Level_Template', ("rows", "padding", "firebacks", "powerups"))
|
||||||
Levels = [
|
Levels = [
|
||||||
|
|
|
@ -6,8 +6,7 @@ class Bullet(pygame.sprite.Sprite):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.width = 4
|
self.width = 4
|
||||||
self.height = 10
|
self.height = 10
|
||||||
self.image = pygame.Surface((self.width, self.height))
|
self.image = pygame.transform.scale(textures.get_texture("BULLET"), (self.width, self.height))
|
||||||
self.image.fill((255,255,255))
|
|
||||||
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
|
||||||
self.rect.y = parent.rect.y + parent.height/2
|
self.rect.y = parent.rect.y + parent.height/2
|
||||||
|
|
6
game.py
6
game.py
|
@ -64,7 +64,7 @@ def generate_targets(player):
|
||||||
index = randint(0, len(sprite_list)-1)
|
index = randint(0, len(sprite_list)-1)
|
||||||
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.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
|
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)
|
sprite_list[index].set_position(x,y, center=False)
|
||||||
|
@ -175,6 +175,10 @@ def play(window):
|
||||||
if randint(0,375) > 1: continue
|
if randint(0,375) > 1: continue
|
||||||
temp = Bullet(target)
|
temp = Bullet(target)
|
||||||
temp.type="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!
|
temp.speed = -3 #So it shoots down!
|
||||||
bullet_group.add(temp)
|
bullet_group.add(temp)
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,12 @@ import pygame
|
||||||
|
|
||||||
|
|
||||||
class Shooter(pygame.sprite.Sprite):
|
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__()
|
super().__init__()
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.colour = colour
|
self.colour = colour
|
||||||
self.image = pygame.Surface((width, height))
|
self.image = pygame.transform.scale(textures.get_texture("PLAYER"), (self.width, self.height))
|
||||||
self.image.fill(self.colour)
|
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.speed = 3
|
self.speed = 3
|
||||||
self.window_rect = window.get_rect()
|
self.window_rect = window.get_rect()
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import pygame
|
import pygame
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
|
||||||
class Target(pygame.sprite.Sprite):
|
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__()
|
super().__init__()
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.image = pygame.Surface((self.width, self.height))
|
self.image = pygame.transform.scale(textures.get_target_texture(), (self.width, self.height))
|
||||||
self.image.fill(color)
|
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.speed = 7
|
self.speed = 7
|
||||||
self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates
|
self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates
|
||||||
|
|
Reference in a new issue