tabs vs spaces, and added more texture code.
This commit is contained in:
parent
03de948eb4
commit
e21781e586
1 changed files with 44 additions and 43 deletions
87
assets.py
87
assets.py
|
@ -3,65 +3,66 @@ from collections import namedtuple
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
class Textures():
|
class Textures():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.images = {
|
self.images = {
|
||||||
"PLAYER":"player.png",
|
"PLAYER":"player",
|
||||||
"BULLET":"bullet.png",
|
"BULLET":"bullet",
|
||||||
"TARGETS":[],
|
"TARGETS":[],
|
||||||
"SHOOTER":"shooter.png",
|
"SHOOTER":"shooter",
|
||||||
"TARGET_BULLET":"target_bullet.png"
|
"TARGET_BULLET":"bullet_target"
|
||||||
}
|
}
|
||||||
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"
|
||||||
|
|
||||||
def load_texture_pack(self, packName):
|
def load_texture_pack(self, pack_name):
|
||||||
if os.path.exists(self.path + packName):
|
if os.path.exists(self.path + pack_name):
|
||||||
self.images["TARGETS"] = []
|
self.images["TARGETS"] = []
|
||||||
|
|
||||||
targets = glob.glob(self.path+packName+"\\target*.png")
|
targets = glob.glob(self.path+pack_name+"\\target*.png")
|
||||||
logging.debug("Found {0} target files.".format(len(targets)))
|
logging.debug("Found {0} target files.".format(len(targets)))
|
||||||
for file in targets:
|
for file in targets:
|
||||||
fileName = file.split("\\")[-1]
|
filename = file.split("\\")[-1].replace(".png", "")
|
||||||
self.images["TARGETS"].append(filename)
|
self.images["TARGETS"].append(filename)
|
||||||
|
|
||||||
self.pack = packName
|
self.pack = pack_name
|
||||||
else: logging.warn("Cannot find texture pack '{}'".format(packName))
|
else: logging.warn("Cannot find texture pack '{}'".format(ppack_name))
|
||||||
|
|
||||||
def get_texture(self, objectName):
|
def get_texture(self, objectName):
|
||||||
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):
|
def get_target_texture(self):
|
||||||
filename = self.path + self.pack + "\\{}.png".format(self.images["TARGETS"][randint(0,len(self.images["TARGETS"]))])
|
index = randint(0,len(self.images["TARGETS"])-1) if len(self.images["TARGETS"]) >=1 else 0
|
||||||
return pygame.image.load(filename)
|
filename = self.path + self.pack + "\\{}.png".format(self.images["TARGETS"][randint(0,len(self.images["TARGETS"])-1)])
|
||||||
|
return pygame.image.load(filename)
|
||||||
|
|
||||||
def list_packs(self):
|
def list_packs(self):
|
||||||
return [x[0] for x in os.walk(self.path)]
|
return [x[0].replace(self.path, "") for x in os.walk(self.path)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Level_Template = namedtuple('Level_Template', ("rows", "padding", "firebacks", "powerups"))
|
Level_Template = namedtuple('Level_Template', ("rows", "padding", "firebacks", "powerups"))
|
||||||
Levels = [
|
Levels = [
|
||||||
Level_Template(2, 20, 0, 0),
|
Level_Template(2, 20, 0, 0),
|
||||||
Level_Template(3, 15, 2, 1),
|
Level_Template(3, 15, 2, 1),
|
||||||
Level_Template(4, 25, 7, 1)
|
Level_Template(4, 25, 7, 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def generate_random_level():
|
def generate_random_level():
|
||||||
logging.info("Generating a random level!")
|
logging.info("Generating a random level!")
|
||||||
rows = randint(0, 12)
|
rows = randint(0, 12)
|
||||||
padding = randint(0, 30)
|
padding = randint(0, 30)
|
||||||
firebacks = randint(0, 15)
|
firebacks = randint(0, 15)
|
||||||
powerups = randint(0, 15)
|
powerups = randint(0, 15)
|
||||||
return Level_Template(rows, padding, firebacks, powerups)
|
return Level_Template(rows, padding, firebacks, powerups)
|
||||||
|
|
||||||
|
|
||||||
Sounds = {}
|
Sounds = {}
|
||||||
def init_sounds():
|
def init_sounds():
|
||||||
music_files = ["main.mp3", "fire.mp3"]
|
music_files = ["main.wav", "OP.wav", "shot.wav"]
|
||||||
for file in music_files:
|
for file in music_files:
|
||||||
path = os.path.dirname(os.path.realpath(__file__)) + "\\resources\\sounds\\" + file
|
path = os.path.dirname(os.path.realpath(__file__)) + "\\resources\\sounds\\" + file
|
||||||
if file == "main.mp3": mixer = pygame.mixer.music.load(path)
|
mixer = pygame.mixer.Sound(path)
|
||||||
else: mixer = pygame.mixer.Sound(file)
|
mixer.set_volume(1.0)
|
||||||
Sounds.update(file.split(".")[0], mixer)
|
Sounds[file.replace(".wav", "")] = mixer
|
Reference in a new issue