Ejemplo n.º 1
0
 def launch_game_graphics(self, master, arena='tt'):
     # setup window
     self.master = master
     master.wm_title("Punch Arena v." + m_c.VERSION_NUMBER)
     # setup canvases
     map_canvas = tk.Canvas(master, bg='pink', width=m_c.canvas_w, height=m_c.canvas_h1, highlightthickness=0)
     map_canvas.pack()
     self.game_arena = World_map(self.my_time, self.my_msg, map_canvas, arena)
     self.place_player_char(map_canvas)
     statbar_frame = tk.Frame(master, bg='red', width=m_c.canvas_w, height=m_c.canvas_h2, highlightthickness=0)
     statbar_frame.pack()
     self.statbar = StatBar(statbar_frame, self.my_time, self.my_msg, self.player1)
     self.hover_box = self.statbar.get_hover()
     self.my_msg.register_hoverbox(self.hover_box)
     self.my_msg.create_overhead(map_canvas)
Ejemplo n.º 2
0
class Game:
    def __init__(self, master):
        global game_object
        game_object = self
        self.launch_game_cores(master)
        self.launch_game_graphics(master, 'tt')
        self.launch_game_listeners(master)
        self.my_time.start_game_ticks()

    def launch_game_cores(self, master):
        # create state machine core
        self.my_state = StateCore()
        # create message core
        self.my_msg = MessageCore(self.my_state)
        self.my_state.attach_message_core(self.my_msg)
        # create time core (animation, state machine update)
        self.my_time = TimeCore(master, self.my_state, self.my_msg)
        self.my_state.attach_time_core(self.my_time)
        self.my_msg.attach_time_core(self.my_time)

    def launch_game_graphics(self, master, arena='tt'):
        # setup window
        self.master = master
        master.wm_title("Punch Arena v." + m_c.VERSION_NUMBER)
        # setup canvases
        map_canvas = tk.Canvas(master, bg='pink', width=m_c.canvas_w, height=m_c.canvas_h1, highlightthickness=0)
        map_canvas.pack()
        self.game_arena = World_map(self.my_time, self.my_msg, map_canvas, arena)
        self.place_player_char(map_canvas)
        statbar_frame = tk.Frame(master, bg='red', width=m_c.canvas_w, height=m_c.canvas_h2, highlightthickness=0)
        statbar_frame.pack()
        self.statbar = StatBar(statbar_frame, self.my_time, self.my_msg, self.player1)
        self.hover_box = self.statbar.get_hover()
        self.my_msg.register_hoverbox(self.hover_box)
        self.my_msg.create_overhead(map_canvas)

    def place_player_char(self, map_canvas):
        # create player
        self.player1 = Player("player1", self.my_time, NPC=False, pid=1)
        # associate player with canvas, create sprite, and register for animation
        self.player1.attach_canvas(map_canvas)
        self.player1.create_sprite("player1")
        self.player1.register_object()
        # attaching all the relevant crap
        self.player1.attach_state_machine(self.my_state)
        self.player1.attach_worldmap(self.game_arena)
        self.player1.attach_message_core(self.my_msg)
        self.player1.set_coords(self.game_arena.playerPos[0], self.game_arena.playerPos[1])
        self.my_state.append_player(self.player1)

    def launch_game_listeners(self, master):
        # bind listeners
        master.bind("<space>", GameInput.space_detect)
        master.bind('<Left>', GameInput.leftKey)
        master.bind('<Right>', GameInput.rightKey)
        master.bind('<Up>', GameInput.upKey)
        master.bind('<Down>', GameInput.downKey)
        master.bind('<KeyPress>', GameInput.key_detect)

    """console commands"""

    def attach_console(self, console):
        global game_console
        game_console = console

    def debug_place_world_tile(self, x, y, variant):
        self.game_arena.replace_tile(x, y, variant)

    def check_time(self):
        return self.my_time.check_time()

    def force_state(self, s):
        self.my_state.set_state(s)

    def force_p1_drainhp(self, amount):
        self.player1.drain_hp(amount)

    def force_p1_drainmp(self, amount):
        self.player1.drain_mp(amount)