Beispiel #1
0
def init():
    GameManager.Instance().Init()

    # Apply all sub-systems to system manager
    SystemManager.Instance().add_system(Input(), priority=0)
    SystemManager.Instance().add_system(Renderer(110, 50), priority=0)
    SystemManager.Instance().add_system(Physics(), priority=0)

    # Setup GUI
    renderer = SystemManager.Instance().get_system_of_type(Renderer)

    # Add panels
    renderer.addPanel(
        Panel(renderer.window, renderer.screen_width - 20, 0, 20,
              renderer.screen_height - 7, Panel.Right, "EVENT_StatsUpdated",
              renderer))
    EventManager.Instance().fireEvent("EVENT_StatsUpdated", [{
        "HP: 10/10": {
            "color": Colors.gold
        }
    }, {
        "MP:  5/20": {
            "color": Colors.gold
        }
    }])

    renderer.addPanel(
        Panel(renderer.window, 0, renderer.screen_height - 7,
              renderer.screen_width, 7, Panel.Bottom,
              "EVENT_ConsoleMessageAdded", renderer))
    GameManager.Instance().message("Hello, this is my first console message!")
Beispiel #2
0
def onKeyPressed(args):
    char = args["char"]
    v = None

    GameManager.Instance().message("Bryant pressed a button: {}".format(char),
                                   Colors.green)

    if char == "UP":
        v = Vector2D(0, -1)
    elif char == "LEFT":
        v = Vector2D(-1, 0)
    elif char == "RIGHT":
        v = Vector2D(1, 0)
    elif char == "DOWN":
        v = Vector2D(0, 1)
    elif char == "F":
        EventManager.Instance().fireEvent("EVENT_FocusCameraOnEntity", player)
        return
    elif char == "G":
        EventManager.Instance().fireEvent("EVENT_FocusCameraOnEntity", None)
        return
    else:
        return

    EventManager.Instance().fireEvent("EVENT_MoveEntity", {
        "entity": player,
        "vector2D": v
    })
Beispiel #3
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 #4
0
 def load_map(self, filename):
     mapArr = []
     count = 0
     with open(filename, 'r') as fp:
         lines = fp.readlines()
         for line in lines:
             mapArr.append([])
             for char in line.strip('\n'):
                 mapArr[count].append(char)
             count += 1
     GameManager.Instance().loadMap(mapArr)
Beispiel #5
0
    def _scan(self):
        scan_results = []
        GameManager.Instance().refreshCachedMap()
        cached_map = list(GameManager.Instance().cached_map)
        rng = self.bot._scan_range
        posX = self.entity.components["Transform2D"].position.x
        posY = self.entity.components["Transform2D"].position.y
        lowerX = max(posX - rng, 0)
        lowerY = max(posY - rng, 0)
        print(GameManager.Instance().map_size_x,
              GameManager.Instance().map_size_y,
              self.entity.components["Transform2D"].position.y)
        upperX = min(posX + rng, GameManager.Instance().map_size_x - 1)
        upperY = min(posY + rng, GameManager.Instance().map_size_y - 1)
        for col in xrange(lowerX, upperX + 1):
            for row in xrange(lowerY, upperY + 1):
                # TODO: COuld be a bug because this assumes no entity can be found on the same tile as your robot.
                if len(cached_map[col][row]) > 0:
                    if self.entity in cached_map[col][row]:
                        cached_map[col][row].remove(self.entity)
                        continue
                    scan_results.append((Vector2D(row,
                                                  col), cached_map[col][row]))

        return scan_results
Beispiel #6
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 #7
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 #8
0
    def dealDamage(self, args):
        attacker = args["attacker"]
        attacked = args["attacked"]
        damage = args["damage"]

        if "Health" in attacked.components:
            attacked.components["Health"].health -= damage
            if attacked.components["Health"].health <= 0:
                attacked.removable = True

            GameManager.Instance().message(
                "{0} hit {1} for {2} damage ({3} / {4})".format(
                    attacker, attacked, damage,
                    attacked.components["Health"].health,
                    attacked.components["Health"].maxHealth), Colors.red)
Beispiel #9
0
    def onKeyPressed(self, args):
        char = args["char"]
        v = None

        GameManager.Instance().message("You pressed a button: {}".format(char), Colors.green)

        if char == "UP":
            v = Vector2D(0, -1)
        elif char == "LEFT":
            v = Vector2D(-1, 0)
        elif char == "RIGHT":
            v = Vector2D(1, 0)
        elif char == "DOWN":
            v = Vector2D(0, 1)
        elif char == "S":
            for e, component in EntityManager.Instance().pairs_for_type(Robot):
                EventManager.Instance().fireEvent("EVENT_ShootProjectile", {"origin" : e.components["Transform2D"].position, "direction" : e.components["Robot"].bot.direction, "damage" : 20})
                return
        elif char == "1":
            robots = []
            for e, component in EntityManager.Instance().pairs_for_type(Robot):
                robots.append(e)
            if len(robots) >= 1:
                EventManager.Instance().fireEvent("EVENT_FocusCameraOnEntity", robots[0])
            return
        elif char == "2":
            robots = []
            for e, component in EntityManager.Instance().pairs_for_type(Robot):
                robots.append(e)
            if len(robots) >= 2:
                EventManager.Instance().fireEvent("EVENT_FocusCameraOnEntity", robots[1])
            return
        elif char == "G":
            EventManager.Instance().fireEvent("EVENT_FocusCameraOnEntity", None)
            return
        else:
            return

        for e, component in EntityManager.Instance().pairs_for_type(Robot):
            EventManager.Instance().fireEvent("EVENT_MoveEntity", {"entity" : e, "vector2D" : v})
Beispiel #10
0
def main():
    global player

    # Parse command line for robots
    if len(sys.argv) != 3:
        print("USAGE: python main.py [BOT1] [BOT2]")
        exit()
    bot1 = sys.argv[1]
    bot2 = sys.argv[2]
    b1 = importlib.import_module("bots." + bot1)
    b2 = importlib.import_module("bots." + bot2)

    battlecogs = BattleCOGS(bot1, bot2)

    # Setup game systems
    battlecogs.init()

    # DO GAME LOGIC STUFF #

    # Create a player
    battlecogs.add_robot(getattr(b1, bot1), 15, 9)
    battlecogs.add_robot(getattr(b2, bot2), 30, 9)

    # Load map
    battlecogs.load_map("assets/level_1.txt")

    # Get key presses
    EventManager.Instance().subscribe("EVENT_KeyPressed", battlecogs.onKeyPressed)

    # END GAME LOGIC STUFF #

    # Register game over callback on "Q" being pressed
    EventManager.Instance().subscribe("EVENT_QuitGame", battlecogs.quitCallback)

    # Run game
    GameManager.Instance().run()
Beispiel #11
0
def main():
    global player

    # Setup game systems
    init()

    # DO GAME LOGIC STUFF #

    # Create a player
    create_player()

    # Load map
    load_map("assets/level_1.txt")

    # Get key presses
    EventManager.Instance().subscribe("EVENT_KeyPressed", onKeyPressed)

    # END GAME LOGIC STUFF #

    # Register game over callback on "Q" being pressed
    EventManager.Instance().subscribe("EVENT_QuitGame", quitCallback)

    # Run game
    GameManager.Instance().run()
Beispiel #12
0
from core.SpriteManager import SpriteManager

builtins.sprite_manager = SpriteManager('img/')

from core.DataManager import DataManager

builtins.data_manager = DataManager()

from core.SoundManager import SoundManager

builtins.sound_manager = SoundManager('music/', 'sound/')

from core.GameManager import GameManager

builtins.game_manager = GameManager()

from core.RenderManager import RenderManager

builtins.render_manager = RenderManager()

from core.MapManager import MapManager

builtins.map_manager = MapManager()

from core.Mouse import Mouse

builtins.mouse = Mouse()

from core.Menu import Menu
Beispiel #13
0
 def quitCallback(self, args):
     GameManager.Instance().running = False