Example #1
0
class Tiles:

    size = 80

    def load_texture(file, size):
        bitmap = pygame.image.load(file)
        surface = pygame.Surface((size, size), pygame.HWSURFACE)
        surface.blit(bitmap, (0, 0))
        return surface

    Grass = load_texture(os_format_dir_name("graphics{os_dir}grass2.png"),
                         size)

    Stone = load_texture(os_format_dir_name("graphics{os_dir}stone.png"), size)

    Sand = load_texture(os_format_dir_name("graphics{os_dir}sand.png"), size)

    Lava = load_texture(os_format_dir_name("graphics{os_dir}lava.png"), size)

    Lava_Rock = load_texture(
        os_format_dir_name("graphics{os_dir}lava_rock.png"), size)

    Texture_tags = {
        "1": Grass,
        "2": Stone,
        "3": Sand,
        "4": Lava,
        "5": Lava_Rock
    }
Example #2
0
    def __init__(self):
        self.Engine = None
        self.game_vars = {}

        self.mapname = os_format_dir_name("maps{os_dir}Elemental_plane.map")
        self.terrain = scripts.map_engine.Map_Engine.load_map(self.mapname)

        # Surfaces in this are blitted before the sprites
        self.surf_dict0 = {}
        # Surfaces in this are blitted after sprites
        self.surf_dict1 = {}
        # Surfaces in this are blitted after the base gui
        self.surf_dict2 = {}
        # Surfaces in this are blitted after the pause screen
        self.surf_dict3 = {}
        # Surfaces in this are always blitted and updated
        self.surf_dict4 = {}

        # Make sure this contains all surf_dicts
        self.surf_dict_list = [
            self.surf_dict0, self.surf_dict1, self.surf_dict2, self.surf_dict3,
            self.surf_dict4
        ]

        # Prevents surfaces from tearing on the screen during pause menu by holding all rects from all surfaces in
        # surf_dict4
        self.surf_dict4_copy = []

        self.cursor_img = pygame.Surface((31, 27))
        self.cursor_img.blit(
            pygame.image.load(
                os_format_dir_name(
                    "graphics{os_dir}gui_images{os_dir}cursor.png")), (0, 0))
        self.cursor_img.set_colorkey(Color.Red)

        self.background_img = None

        self.pause_layer = pygame.Surface((0, 0))

        self.pause_frame = pygame.Surface((0, 0))
        self.paused = False
        self.pause_flagged = False

        # Used for tracking blits per frame for debugging purposes
        self.bpf = 0
Example #3
0
def load_gui_from_image(file_name):

    corner_dimensions = (0, 0, 1, 1)
    side_dimensions = (0, 0, 1, 1)
    background_dimensions = (0, 0, 1, 1)

    try:
        component_image = pygame.image.load(
            os_format_dir_name("graphics{os_dir}gui_images{os_dir}") +
            file_name + ".png")

        with open("graphics//gui_images//" + file_name +
                  "_dimensions.txt") as dimensions_file:
            current_line = dimensions_file.readline()
            while current_line != "":
                split_line = current_line.split(" ")
                if split_line[0] == "corner:":
                    corner_dimensions = ast.literal_eval(split_line[1])
                elif split_line[0] == "side:":
                    side_dimensions = ast.literal_eval(split_line[1])
                elif split_line[0] == "background:":
                    background_dimensions = ast.literal_eval(split_line[1])
                else:
                    raise ValueError("Unknown identifier: " + split_line[0])
                current_line = dimensions_file.readline()
    except FileNotFoundError:
        print("Problem loading gui.")
        component_image = pygame.Surface((100, 100))

    for value in corner_dimensions:
        if value < 0:
            raise ValueError("Gui dimensions need to be positive.")
    for value in side_dimensions:
        if value < 0:
            raise ValueError("Gui dimensions need to be positive.")
    for value in background_dimensions:
        if value < 0:
            raise ValueError("Gui dimensions need to be positive.")

    corner_image = pygame.Surface((corner_dimensions[2], corner_dimensions[3]))
    side_image = pygame.Surface((side_dimensions[2], side_dimensions[3]))
    background_image = pygame.Surface(
        (background_dimensions[2], background_dimensions[3]))

    corner_image.blit(component_image, (0, 0),
                      (corner_dimensions[0], corner_dimensions[1],
                       corner_dimensions[2], corner_dimensions[3]))
    side_image.blit(component_image, (0, 0),
                    (side_dimensions[0], side_dimensions[1],
                     side_dimensions[2], side_dimensions[3]))
    background_image.blit(component_image, (0, 0),
                          (background_dimensions[0], background_dimensions[1],
                           background_dimensions[2], background_dimensions[3]))
    return GUIComponents(corner_image, side_image, background_image)
Example #4
0
    def __init__(self, sprite):

        self.sprite = sprite
        self.default_ability_sound = os_format_dir_name("sounds{os_dir}fight{os_dir}sword_clash.wav")
Example #5
0
from pygame.mixer import Sound
import pygame
from scripts.tools import os_format_dir_name
"""
Holds all of the sounds that abilities can play
"""

pygame.mixer.init()


class SoundPack:
    def __init__(self, s_sound, f_sound, p_sound):

        # Allows all three sounds to be passed as one parameter to an Ability class

        self.success_sound_file = s_sound
        self.failure_sound_file = f_sound
        self.partial_sound_file = p_sound


basic_sword = os_format_dir_name("sounds{os_dir}fight{os_dir}sword_clash.wav")
eerie_magic = os_format_dir_name("sounds{os_dir}fight{os_dir}eerie_magic.wav")
block = os_format_dir_name("sounds{os_dir}fight{os_dir}shield_block.wav")

snd_basic_atk = SoundPack(basic_sword, None, None)
snd_basic_mag = SoundPack(eerie_magic, None, None)
snd_basic_blk = SoundPack(block, None, None)
snd_empty_pack = SoundPack(None, None, None)