Beispiel #1
0
 def setCameraFocus(self, entity):
     if entity == None:
         self.offset_transform = Transform2D(self.console_mid)
     else:
         try:
             self.offset_transform = entity.components["Transform2D"]
         except:
             print("[ERROR] Entity has no Transform2D component!")
Beispiel #2
0
def create_player():
    global player
    player = EntityManager.Instance().create_entity('@', z=10)
    EntityManager.Instance().add_component(player,
                                           Transform2D(Vector2D(10, 10)))
    EntityManager.Instance().add_component(player, Health())
    EntityManager.Instance().add_component(
        player, Collider(COLLIDER_PLAYER, COLLIDER_PLAYER | COLLIDER_WALL))
    GameManager.Instance().message(
        "Bryant entered the strange room hesitantly.", Colors.red)
Beispiel #3
0
 def loadMap(self, mapArr):
     for row in range(0, len(mapArr)):
         for col in range(0, len(mapArr[0])):
             entity = EntityManager.Instance().create_entity(
                 mapArr[row][col])
             EntityManager.Instance().add_component(
                 entity, Transform2D(Vector2D(col, row)))
             if entity.symbol == "#":
                 EntityManager.Instance().add_component(
                     entity,
                     Collider(COLLIDER_WALL,
                              COLLIDER_PLAYER | COLLIDER_WALL))
Beispiel #4
0
    def spawnProjectile(self, args):
        origin = args["origin"]
        direction = args["direction"]
        damage = args["damage"]

        p = EntityManager.Instance().create_entity("+", z=9)
        EntityManager.Instance().add_component(p, Transform2D(origin))
        EntityManager.Instance().add_component(p,
                                               Projectile(damage, direction))
        EntityManager.Instance().add_component(
            p, Collider(COLLIDER_PROJECTILE, COLLIDER_PLAYER | COLLIDER_WALL))
        GameManager.Instance().message("A bullet shot rings through the air!",
                                       Colors.yellow)
Beispiel #5
0
    def addPanel(self, panel):
        self.panels.append(panel)

        # Shrink game panel to fit within upper left hand corner
        if panel.side == Panel.Right:
            if panel.offsetX < self.game_panel.width:
                self.game_panel.width = panel.offsetX
        elif panel.side == Panel.Bottom:
            if panel.offsetY < self.game_panel.height:
                self.game_panel.height = panel.offsetY

        # Setup game window center in relation to panel[0] (main game scene)
        self.console_mid = Vector2D(int(self.game_panel.width / 2), int(self.game_panel.height / 2))
        self.offset_transform = Transform2D(self.console_mid)
Beispiel #6
0
    def add_robot(self, type, x, y):
        # Create a bot and link back the entity so that user can reference other components
        bot = type()
        robot = EntityManager.Instance().create_entity(bot.symbol, z=10)
        bot.action = Robot(robot, bot)

        EntityManager.Instance().add_component(robot, Transform2D(Vector2D(x, y)))
        EntityManager.Instance().add_component(robot, Health())
        EntityManager.Instance().add_component(robot, Collider(COLLIDER_PLAYER, COLLIDER_PLAYER | COLLIDER_WALL))
        EntityManager.Instance().add_component(robot, bot.action)
        GameManager.Instance().message("Bryant entered the strange room hesitantly.", Colors.red)

        EventManager.Instance().fireEvent("EVENT_StatsUpdated", [{"HP: {0}/{1}".format(robot.components["Health"].health, robot.components["Health"].maxHealth) : {"color" : Colors.gold}},
                                                                 {"MP:  5/20" : {"color" : Colors.gold}}])
        return robot
Beispiel #7
0
    def loadMap(self, mapArr):
        self.map_size_x = len(mapArr[0])
        self.map_size_y = len(mapArr)
        print("Map Size: ({0}, {1})".format(self.map_size_x, self.map_size_y))
        for row in range(0, len(mapArr)):
            for col in range(0, len(mapArr[0])):
                if mapArr[row][col] in list(healthLookupTable.keys()):
                    entity = EntityManager.Instance().create_entity(
                        mapArr[row][col])
                    EntityManager.Instance().add_component(
                        entity, Transform2D(Vector2D(col, row)))
                    EntityManager.Instance().add_component(
                        entity, Health(healthLookupTable[mapArr[row][col]]))

                    EntityManager.Instance().add_component(
                        entity,
                        Collider(
                            COLLIDER_WALL, COLLIDER_PLAYER | COLLIDER_WALL
                            | COLLIDER_PROJECTILE))
Beispiel #8
0
    def __init__(self, width, height, font='assets/terminal_8x12.png'):
        System.__init__(self)

        # Define screen sizes
        self.screen_width = width
        self.screen_height = height

        # Set rendered font
        tdl.set_font(font)

        # Create console window
        self.window = tdl.init(self.screen_width, self.screen_height, "gripe engine")

        # Initial screen properties
        self.console_mid = Vector2D(int(self.screen_width / 2), int(self.screen_height / 2))
        self.offset_transform = Transform2D(self.console_mid)

        # Add initial game panel (panel[0] is main game always)
        self.game_panel = GamePanel(self.window, 0, 0, self.screen_width, self.screen_height, None, None, self)
        self.panels = []