Beispiel #1
0
    def load_environment(self, data):
        if type(data) is str:
            data = load_resource(data)

        self.reset_model()
        self.populate(data)
        self.game.environment = self.model[ZsData.ENVIRONMENT]
Beispiel #2
0
    def tile(image_name, surface):
        # PYGAME CHOKE POINT

        if image_name not in ContainerGraphics.PRE_RENDERS:
            bg_image = load_resource(image_name)
            sx, sy = Settings.SCREEN_SIZE  # pre render the tiled background
            sx *= 2  # to the size of a full screen
            sy *= 2
            pr_surface = Surface(
                (sx, sy), SRCALPHA, 32)

            w, h = pr_surface.get_size()
            img_w, img_h = bg_image.get_size()

            for x in range(0, w + img_w, img_w):
                for y in range(0, h + img_h, img_h):
                    pr_surface.blit(bg_image.pygame_surface, (x, y))

            ContainerGraphics.PRE_RENDERS[image_name] = pr_surface

        full_bg = ContainerGraphics.PRE_RENDERS[image_name]     # return a subsection of the full
        #                                                       # pre rendered background
        r = surface.get_rect().clip(full_bg.get_rect())
        blit_region = full_bg.subsurface(r)
        surface.blit(blit_region, (0, 0))

        return surface
Beispiel #3
0
        def get_data(arg):
            if type(arg) is str:
                if ".json" in arg:
                    return load_resource(arg)

                else:
                    return self.model[arg]

            else:
                return arg
Beispiel #4
0
    def draw_corners(image_name, surface, corners):
        corner_image = load_resource(image_name)
        w, h = surface.get_size()
        cw, ch = corner_image.get_size()
        a, b, c, d = "abcd"
        locations = {a: (0, 0),
                     b: (w - cw, 0),
                     c: (0, h - ch),
                     d: (w - cw, h - ch)}

        for corner in corners:
            surface.blit(
                ContainerGraphics.get_corner(corner_image, corner).pygame_surface,
                locations[corner]
            )
Beispiel #5
0
    def get_full_side_image(image_name, orientation):
        if image_name not in ContainerGraphics.PRE_RENDERS:
            image = load_resource(image_name)
            iw, ih = image.get_size()

            h, v = "hv"
            size = {h: (iw, Settings.SCREEN_SIZE[1]),
                    v: (Settings.SCREEN_SIZE[0], iw)}[orientation]
            pr_surface = Surface(
                size, SRCALPHA, 32)

            span = {h: range(0, size[1], ih),
                    v: range(0, size[0], iw)}[orientation]

            for i in span:
                position = {h: (0, i),
                            v: (i, 0)}[orientation]
                pr_surface.blit(image.pygame_surface, position)

            ContainerGraphics.PRE_RENDERS[image_name] = pr_surface

        return ContainerGraphics.PRE_RENDERS[image_name]
Beispiel #6
0
 def get_resource(file_name):
     return load_resource(file_name)
Beispiel #7
0
import pygame

from app.get_context import get_context_classes
from app.pygame_screen import PygameScreen
from zs2.context import Context
from zs2.game import Game
from zs2.resources import load_resource
from zs_constants import Settings

pygame.init()
# pygame.mixer.quit()
# pygame.mixer.init(buffer=256)


if __name__ == "__main__":
    scr = PygameScreen()
    clock = pygame.time.Clock()
    game = Game(scr, clock, Settings.FRAME_RATE)

    env = load_resource(Settings.APP_START)
    entities, interfaces = get_context_classes()
    class_dict = {
        cls.__name__: cls for cls in entities
    }

    Context(game, class_dict, *interfaces).load_environment(env)

    game.main()
Beispiel #8
0
    def load_controller(file_name):
        devices = load_resource(file_name)["devices"]

        return ControllerIO.make_controller(file_name, devices)