Esempio n. 1
0
 def mouse_lbtn_down(self, evt):
     from LocalInput import LocalInput
     from Map import QuadTreeForTile
     from Game import CGameApp
     from Team import *
     mouse_x = LocalInput.mouse_pos[0]
     mouse_y = LocalInput.mouse_pos[1]
     app = CGameApp.get_instance()
     bp_ui = app.gui_manager.character_bp
     if self.fsm.is_in_state(Player_Enum.Player_State_Pick_Characters):
         for character_btn in bp_ui.character_pool_btn:
             if QuadTreeForTile.check_tile(
                     character_btn.x, character_btn.y, character_btn.w,
                     character_btn.h, mouse_x, mouse_y, 0,
                     0) and character_btn.in_character_pool:
                 if character_btn.in_character_pool:
                     character_btn.in_character_pool = False
                     if self.team.name == Team_Enum.TEAM_RED:
                         bp_ui.character_red_pick.append(character_btn)
                         app.team_red.add_character(
                             app.characters[character_btn.name])
                     elif self.team.name == Team_Enum.TEAM_BLUE:
                         bp_ui.character_blue_pick.append(character_btn)
                         app.team_blue.add_character(
                             app.characters[character_btn.name])
                 print "Pick Character"
                 self.send_event(CGameApp.get_instance(),
                                 Event(EventType.GAME_BAN_PICK_TURN))
     elif self.fsm.is_in_state(Player_Enum.Player_State_Ban_Characters):
         for character_btn in bp_ui.character_pool_btn:
             if QuadTreeForTile.check_tile(
                     character_btn.x, character_btn.y, character_btn.w,
                     character_btn.h, mouse_x, mouse_y, 0,
                     0) and character_btn.in_character_pool:
                 if character_btn.in_character_pool:
                     character_btn.in_character_pool = False
                     if self.team.name == Team_Enum.TEAM_RED:
                         bp_ui.character_red_ban.append(character_btn)
                     elif self.team.name == Team_Enum.TEAM_BLUE:
                         bp_ui.character_blue_ban.append(character_btn)
                 print "Ban Character"
                 self.send_event(CGameApp.get_instance(),
                                 Event(EventType.GAME_BAN_PICK_TURN))
     elif self.fsm.is_in_state(Player_Enum.Player_State_In_Turn):
         print str(self.team.name) + "'s turn"
         self.send_event(self.team, evt)
     elif self.fsm.is_in_state(Player_Enum.Player_State_Waiting):
         print str(self.team.name) + " is waiting for its turn"
Esempio n. 2
0
 def get_wnd_by_mouse(self, mouse_pos):
     from Map import QuadTreeForTile
     for (name, wnd) in self.gui_wnds.items():
         if QuadTreeForTile.check_tile(wnd.x, wnd.y, wnd.w, wnd.h,
                                       mouse_pos[0], mouse_pos[1], 0, 0):
             return wnd
     return None
Esempio n. 3
0
    def draw(self, et):
        from Game import CGameApp
        app = CGameApp.get_instance()
        app.screen.blit(self.surface, ((self.x, self.y), (self.w, self.h)))
        text_w = self.text_surface.get_width()
        text_h = self.text_surface.get_height()
        off_x = (self.w - text_w) / 2
        off_y = (self.h - text_h) / 2
        app.screen.blit(self.text_surface,
                        ((self.x + off_x, self.y + off_y), (text_w, text_h)))
        pygame.draw.rect(app.screen, (128, 128, 128),
                         (self.x, self.y, self.w, self.h),
                         Gui_Enum.WND_BORDER_WIDTH.value)
        from LocalInput import LocalInput
        from Map import QuadTreeForTile
        if QuadTreeForTile.check_tile(self.x, self.y, self.w, self.h,
                                      LocalInput.mouse_pos[0],
                                      LocalInput.mouse_pos[1], 0, 0):
            pygame.draw.rect(app.screen, (0, 255, 0),
                             (self.x, self.y, self.w, self.h),
                             Gui_Enum.WND_BORDER_WIDTH.value)
            if self.desc is not None:
                self.desc.show = True
        else:
            if self.desc is not None:
                self.desc.show = False

        self.process_evt_queue()
Esempio n. 4
0
 def get_widget_by_mouse(self, mouse_pos):
     from Map import QuadTreeForTile
     for (name, widget) in self.widgets.items():
         if QuadTreeForTile.check_tile(widget.x, widget.y, widget.w,
                                       widget.h, mouse_pos[0], mouse_pos[1],
                                       0, 0):
             return widget
     return None
Esempio n. 5
0
 def draw(self, et):
     super(Game_State_Playing, self).draw(et)
     self.fsm.owner.level_map.draw(et)
     self.fsm.owner.player_guest.draw(et)
     self.fsm.owner.player_host.draw(et)
     self.fsm.owner.gui_manager.draw(et)
     self.team_label.draw(et)
     app = self.fsm.owner
     app.screen.blit(app.end_turn, (400, 700, 200, 50))
     if QuadTreeForTile.check_tile(400, 700, 200, 50,
                                   LocalInput.mouse_pos[0],
                                   LocalInput.mouse_pos[1], 0, 0):
         pygame.draw.rect(app.screen, (255, 255, 255), (400, 700, 200, 50),
                          1)
Esempio n. 6
0
 def draw(self, et):
     super(Game_State_Init, self).draw(et)
     app = self.fsm.owner
     if app.title_screen is not None:
         app.screen.blit(app.title_screen,
                         ((0, 0), (app.screen_w, app.screen_h)))
         app.screen.blit(app.begin_game, (250, 250))
         w = app.begin_game.get_width()
         h = app.begin_game.get_height()
         from Map import QuadTreeForTile
         if QuadTreeForTile.check_tile(250, 250, w, h,
                                       LocalInput.mouse_pos[0],
                                       LocalInput.mouse_pos[1], 0, 0):
             pygame.draw.rect(app.screen, (0, 255, 0), (250, 250, w, h), 1)
Esempio n. 7
0
 def handle_mouse_lbtn_down(self, evt):
     if self.fsm.is_in_state(Game_Enum.Game_Init):
         w = self.begin_game.get_width()
         h = self.begin_game.get_height()
         if QuadTreeForTile.check_tile(250, 250, w, h,
                                       LocalInput.mouse_pos[0],
                                       LocalInput.mouse_pos[1], 0, 0):
             print "Begin Game"
             self.fsm.change_to_state(Game_Enum.Game_Team_Select)
     elif self.fsm.is_in_state(Game_Enum.Game_Team_Select):
         state = self.fsm.states[Game_Enum.Game_Team_Select]
         if QuadTreeForTile.check_tile(state.red_team_area[0],
                                       state.red_team_area[1],
                                       state.red_team_area[2],
                                       state.red_team_area[3],
                                       LocalInput.mouse_pos[0],
                                       LocalInput.mouse_pos[1], 0, 0):
             pygame.draw.rect(self.screen, (0, 255, 0), state.red_team_area,
                              1)
             print "Choose Red Team"
             self.player_host.set_team(self.team_red)
             self.player_guest.set_team(self.team_blue)
             self.fsm.change_to_state(Game_Enum.Game_Characters_Ban_Pick)
         elif QuadTreeForTile.check_tile(state.blue_team_area[0],
                                         state.blue_team_area[1],
                                         state.blue_team_area[2],
                                         state.blue_team_area[3],
                                         LocalInput.mouse_pos[0],
                                         LocalInput.mouse_pos[1], 0, 0):
             pygame.draw.rect(self.screen, (0, 255, 0),
                              state.blue_team_area, 1)
             print "Choose Blue Team"
             self.player_host.set_team(self.team_blue)
             self.player_guest.set_team(self.team_red)
             self.fsm.change_to_state(Game_Enum.Game_Characters_Ban_Pick)
     elif self.fsm.is_in_state(Game_Enum.Game_Characters_Ban_Pick):
         self.send_event(
             self.cur_player,
             Event_Mouse_LBTN_DOWN(EventType.MOUSE_LBTN_DOWN,
                                   LocalInput.mouse_pos))
     elif self.fsm.is_in_state(Game_Enum.Game_Playing):
         self.send_event(self.player_guest, evt)
         self.send_event(self.player_host, evt)
         if QuadTreeForTile.check_tile(400, 700, 200, 50,
                                       LocalInput.mouse_pos[0],
                                       LocalInput.mouse_pos[1], 0, 0):
             if self.cur_player.team.name == self.player_host.team.name:
                 self.player_host.fsm.change_to_state(
                     Player_Enum.Player_State_Waiting)
                 self.player_guest.fsm.change_to_state(
                     Player_Enum.Player_State_In_Turn)
                 self.cur_player = self.player_guest
             elif self.cur_player.team.name == self.player_guest.team.name:
                 self.player_guest.fsm.change_to_state(
                     Player_Enum.Player_State_Waiting)
                 self.player_host.fsm.change_to_state(
                     Player_Enum.Player_State_In_Turn)
                 self.cur_player = self.player_host
             self.player_host.calculate_buffs()
             self.player_guest.calculate_buffs()
             self.player_host.team.team_money += 5
             self.player_guest.team.team_money += 5
             self.cur_player.team.total_turn += 1
             self.total_turn += 1
     return
Esempio n. 8
0
    def draw(self, et):
        from Map import QuadTreeForTile
        from LocalInput import LocalInput
        from Game import CGameApp
        app = CGameApp.get_instance()
        mouse_x = LocalInput.mouse_pos[0]
        mouse_y = LocalInput.mouse_pos[1]

        app.screen.blit(self.ui_frame, (0, 0))

        for character_btn in self.character_pool_btn:
            if character_btn.in_character_pool:
                character_btn.draw(et)
            if QuadTreeForTile.check_tile(
                    character_btn.x, character_btn.y, character_btn.w - 1,
                    character_btn.h - 1, mouse_x, mouse_y, 0,
                    0) and character_btn.in_character_pool:
                if character_btn.in_character_pool:
                    pygame.draw.rect(
                        app.screen, (255, 0, 255),
                        (character_btn.x, character_btn.y, 36, 36), 2)
                    self.link_to_character(character_btn.name)

        # bp coords
        x = self.bp_x
        y = self.blue_pick_y
        count = 0
        for character_btn in self.character_blue_pick:
            count += 1
            character_btn.x = x
            character_btn.y = y
            character_btn.draw(et)
            if QuadTreeForTile.check_tile(character_btn.x, character_btn.y,
                                          character_btn.w - 1,
                                          character_btn.h - 1, mouse_x,
                                          mouse_y, 0, 0):
                pygame.draw.rect(app.screen, (255, 0, 255),
                                 (character_btn.x, character_btn.y, 36, 36), 2)
                self.link_to_character(character_btn.name)
            if count % 15 == 0:
                x = self.bp_x
                y += 36
            else:
                x += 36

        x = self.bp_x
        y = self.blue_ban_y
        count = 0
        for character_btn in self.character_blue_ban:
            count += 1
            character_btn.x = x
            character_btn.y = y
            character_btn.draw(et)
            if QuadTreeForTile.check_tile(character_btn.x, character_btn.y,
                                          character_btn.w - 1,
                                          character_btn.h - 1, mouse_x,
                                          mouse_y, 0, 0):
                pygame.draw.rect(app.screen, (255, 0, 255),
                                 (character_btn.x, character_btn.y, 36, 36), 2)
                self.link_to_character(character_btn.name)
            count += 1
            if count % 15 == 0:
                x = self.bp_x
                y += 36
            else:
                x += 36

        x = self.bp_x
        y = self.red_pick_y
        count = 0
        for character_btn in self.character_red_pick:
            count += 1
            character_btn.x = x
            character_btn.y = y
            character_btn.draw(et)
            if QuadTreeForTile.check_tile(character_btn.x, character_btn.y,
                                          character_btn.w - 1,
                                          character_btn.h - 1, mouse_x,
                                          mouse_y, 0, 0):
                pygame.draw.rect(app.screen, (255, 0, 255),
                                 (character_btn.x, character_btn.y, 36, 36), 2)
                self.link_to_character(character_btn.name)
            count += 1
            if count % 15 == 0:
                x = self.bp_x
                y += 36
            else:
                x += 36

        x = self.bp_x
        y = self.red_ban_y
        count = 0
        for character_btn in self.character_red_ban:
            count += 1
            character_btn.x = x
            character_btn.y = y
            character_btn.draw(et)
            if QuadTreeForTile.check_tile(character_btn.x, character_btn.y,
                                          character_btn.w - 1,
                                          character_btn.h - 1, mouse_x,
                                          mouse_y, 0, 0):
                pygame.draw.rect(app.screen, (255, 0, 255),
                                 (character_btn.x, character_btn.y, 36, 36), 2)
                self.link_to_character(character_btn.name)
            count += 1
            if count % 15 == 0:
                x = self.bp_x
                y += 36
            else:
                x += 36

        self.character_name.draw(et)
        self.character_pic.draw(et)
        pygame.draw.rect(app.screen, (255, 0, 255), (3, 378, 150, 150), 1)
        self.character_str.draw(et)
        self.character_agi.draw(et)
        self.character_int.draw(et)
        self.character_atk.draw(et)
        self.character_atk_rng.draw(et)
        self.character_def.draw(et)
        self.character_res.draw(et)
        self.character_ap.draw(et)
        self.character_hp.draw(et)
        self.character_mp.draw(et)