Exemplo n.º 1
0
    def __init__(self, game):
        SceneComponent.__init__(self, game)
        self.width = 512
        self.height = 512

        self.name = "room"

        self.background = Sprite()
        self.background.material = self.game.loader.get_image("world")
        self.background.material_width, self.background.material_height = 768, 909
        self.background.width, self.background.height = self.width, self.height
        self.background.crop = (0, 0, 768, 909)

        # Cache room background surface for optimization
        self.cache_enabled = True
        self.cache = None

        # List of rectangles
        self.walls = []
        # List of shapes
        self.obstacles = []

        # List of InvisibleWall objects
        self.compiled_walls = []
        # List of collision bodies
        self.compiled_obstacles = []
Exemplo n.º 2
0
    def __init__(self, game):
        Entity.__init__(self, game)
        self.name = "item"
        # Item ID
        self.id = -1

        # Setup sprite
        self.sprite = Sprite()
        self.sprite.material = self.game.loader.get_image("items")
        self.sprite.material_width = self.sprite.material_height = 16
        self.sprite.crop = (160,17,16,16)
        self.resize(32, 32)
        self.debug = True
        # Stack count
        self.count = 1
Exemplo n.º 3
0
    def __init__(self, game):
        InteractionEntity.__init__(self, game)
        self.name = "shop_entity"
        self.debug = True

        self.sprite = Sprite()
        self.sprite.material = game.loader.get_image("pikachu")
        self.sprite.crop = (32, 96, 32, 32)
        self.resize(64, 64)

        self.collision_body.set_position(0, 8)

        self.border = InvisibleWall(self.game)
        self.border.resize(32, 32)
        self.border.set_position(16, 24)
        self.border.name = self.name + "_fake_wall"

        self.game.get_scene().add(self.border)
Exemplo n.º 4
0
    def __init__(self, game):
        CollisionActor.__init__(self, game)
        self.height = 64
        self.width = 128
        self.add_property(Property.COLLISION_WALL)

        box = CollisionBox(0, 0, self.width, self.height)
        box.parent = self
        self.collision_body = box

        # Setup sprite
        sprite = Sprite()
        sprite.material = self.game.loader.get_image("wall")
        sprite.height = self.height
        sprite.width = self.width

        sprite.material_height = 48
        sprite.material_width = 48
        sprite.crop = (0, 0, 48, 48)
        self.sprite = sprite
Exemplo n.º 5
0
import math
import os
import pygame
import sys
from Graphics.GameWindow import GameWindow
from Graphics.Sprite import Sprite

pygame.init()

# CREATE THE GAME WINDOW.
game_window = GameWindow(800, 600)

# CREATE THE PLAYER.
player = Sprite("Images/Player.bmp", 10, 10)

print(player.Image)

# ADD THE PLAYER TO THE SET OF OBJECTS DRAWN ON SCREEN.
game_window.AddSprite(player)

while (True):
    for event in pygame.event.get():
        if event.type is pygame.QUIT:
            sys.exit()
        if event.type is pygame.KEYDOWN:
            if event.key is pygame.K_ESCAPE:
                sys.exit()

    currently_pressed_keys = pygame.key.get_pressed()
    if currently_pressed_keys[pygame.K_w]:
        player.Move(0, -2)
Exemplo n.º 6
0
class Room(SceneComponent):
    def __init__(self, game):
        SceneComponent.__init__(self, game)
        self.width = 512
        self.height = 512

        self.name = "room"

        self.background = Sprite()
        self.background.material = self.game.loader.get_image("world")
        self.background.material_width, self.background.material_height = 768, 909
        self.background.width, self.background.height = self.width, self.height
        self.background.crop = (0, 0, 768, 909)

        # Cache room background surface for optimization
        self.cache_enabled = True
        self.cache = None

        # List of rectangles
        self.walls = []
        # List of shapes
        self.obstacles = []

        # List of InvisibleWall objects
        self.compiled_walls = []
        # List of collision bodies
        self.compiled_obstacles = []

    # Initialize room stuff
    def setup_room(self, scene, width, height):
        self.log("Setting up")
        self.setup_walls(scene)
        self.resize(width, height)

    # Add wall collision to scene
    def setup_walls(self, scene):
        self.log("Adding walls", self.walls)
        for wall in self.walls:
            self.add_wall(wall.x, wall.y, wall.width, wall.height, scene)

    # Adds obstacle collision to scene
    def setup_obstacles(self, scene):
        pass

    # Resize room
    def resize(self, w, h):
        self.log(self.width, self.height)
        old_w, old_h = self.width, self.height
        self.width, self.height = w, h
        ratio_w, ratio_h = self.width / old_w, self.height / old_h
        # Update existing walls
        for wall in self.compiled_walls:
            wall.scale(ratio_w, ratio_h)
            wall.set_position(wall.x * ratio_w, wall.y * ratio_h)
        self.background.width, self.background.height = self.width, self.height
        self.cache = None

    # Converts local room coordinates to global screen coordinates
    def room_axis_to_global(self, x, y):
        return x + self.x, y + self.y

    # Converts global screen coordinates to local room coordinates
    def global_axis_to_room(self, x, y):
        return x - self.x, y - self.y

    def add_wall(self, x, y, w, h, scene):
        wall_x, wall_y = self.room_axis_to_global(x, y)
        wall = InvisibleWall(self.game)
        wall.set_position(wall_x, wall_y)
        wall.resize(w, h)
        self.compiled_walls.append(wall)
        scene.add(wall)
        self.log("Added", wall)

    def draw(self):
        camera = self.game.get_scene().camera
        dx = 0 if camera is None else camera.x
        dy = 0 if camera is None else camera.y
        if self.cache_enabled and self.cache is not None:
            self.game.screen.blit(self.cache, (self.x - dx, self.y - dy))
        else:
            surface = self.background.get_surface(dt=0)
            if self.cache_enabled:
                self.cache = surface
            self.game.screen.blit(self.cache, (self.x - dx, self.y - dy))