Пример #1
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
    })
Пример #2
0
 def update(self, dt):
     System.update(self, dt)
     for event in tdl.event.get(): # Iterate over recent events.
         if event.type == 'KEYDOWN':
             if event.keychar not in IGNORED_INPUTS:
                 EventManager.Instance().fireEvent("EVENT_KeyPressed", {"char" : event.keychar.upper()})
                 if (event.keychar.upper() == "Q"): EventManager.Instance().fireEvent("EVENT_QuitGame", {})
         if event.type == 'KEYUP':
             if event.keychar not in IGNORED_INPUTS:
                 EventManager.Instance().fireEvent("EVENT_KeyReleased", {"char" : event.keychar.upper()})
Пример #3
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!")
Пример #4
0
    def _emit(self):
        # Add cost to TTR
        self._ttr += self._cost

        if self._emit_event != "":
            EventManager.Instance().fireEvent(self._emit_event,
                                              self._emit_data)
Пример #5
0
	def collision(self, a, b):
		#msg = "{0} collided with {1}".format(a, b)
		
		# If the initiator is a projectile, apply damage to what it hits
		if a.hasComponent(Projectile):
			EventManager.Instance().fireEvent("EVENT_DealDamage", {"attacker" : a, "attacked" : b, "damage" : a.components["Projectile"].damage})
			a.removable = True
Пример #6
0
    def Init(self):
        # Setup links between the various managers
        SystemManager.Instance().Init()
        EntityManager.Instance().Init()
        EventManager.Instance().Init()

        self.lastUpdated = 0
        self.running = True
        self.message_log = []
Пример #7
0
	def update(self, dt):
		# Update all projectiles
		for e, component in EntityManager.Instance().pairs_for_type(Projectile):
			currentPos = e.components["Transform2D"].position
			EventManager.Instance().fireEvent("EVENT_MoveEntity", {"entity" : e, "vector2D" : Direction.getVector(component.direction)})

		# Remove all removable entities
		entities = EntityManager.Instance().list_entities()
		for entity in entities:
			if entity.removable:
				EntityManager.Instance().remove_entity(entity)
Пример #8
0
    def Init(self, tps=100):
        # Setup links between the various managers
        SystemManager.Instance().Init()
        EntityManager.Instance().Init()
        EventManager.Instance().Init()

        self.tps = tps
        self.lastUpdated = time.time()
        self.running = True
        self.message_log = []
        self.cached_map = []
Пример #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})
Пример #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()
Пример #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()
Пример #12
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
Пример #13
0
    def __init__(self, window, offsetX, offsetY, width, height, side, updateEvent, parent, bounded=False):
        self.window = window
        self.width = width
        self.height = height
        self.offsetX = offsetX
        self.offsetY = offsetY
        self.bounded = bounded
        self.side = side
        self.data = []
        self.console = tdl.Console(width, height)
        self.updateEvent = updateEvent
        self.parent = parent

        # Register update func for updating data
        if self.updateEvent != None:
            EventManager.Instance().subscribe(self.updateEvent, self.updateData)
Пример #14
0
 def init(self):
     EventManager.Instance().subscribe("EVENT_DealDamage", self.dealDamage)
Пример #15
0
 def init(self):
     # Register listener for setting camera focus
     EventManager.Instance().subscribe("EVENT_FocusCameraOnEntity", self.setCameraFocus)
Пример #16
0
 def message(self, msg, color=Colors.white):
     self.message_log.append({msg: {"color": color}})
     EventManager.Instance().fireEvent("EVENT_ConsoleMessageAdded",
                                       self.message_log)
Пример #17
0
 def init(self):
     EventManager.Instance().subscribe("EVENT_ShootProjectile",
                                       self.spawnProjectile)
Пример #18
0
 def takeDamage(self, dmg):
     self.health -= dmg
     if self.health <= 0:
         EventManager.Instance().fireEvent("EVENT_PlayerDied")
Пример #19
0
	def init(self):
		EventManager.Instance().subscribe("EVENT_MoveEntity", self.attemptMove)