Beispiel #1
0
 def draw_skill_rect(self, color):
     from Game import CGameApp
     app = CGameApp.get_instance()
     x = self.pos_x + app.offset_x
     y = self.pos_y + app.offset_y
     pygame.draw.rect(CGameApp.get_instance().screen, color,
                      (x, y, self.width, self.height), 2)
Beispiel #2
0
 def draw(self, et):
     from Game import CGameApp
     app = CGameApp.get_instance()
     x = self.pos_x + app.offset_x
     y = self.pos_y + app.offset_y
     app.screen.blit(self.img, ((x, y), (self.width, self.height)))
     if self.color is not None:
         pygame.draw.rect(CGameApp.get_instance().screen, self.color,
                          (x, y, self.width, self.height), 1)
Beispiel #3
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"
Beispiel #4
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()
Beispiel #5
0
    def draw(self, et):
        super(Map_State_Show_MiniMap, self).draw(et)
        lvl_map = self.fsm.owner
        from Game import CGameApp
        app = CGameApp.get_instance()
        app.screen.blit(
            lvl_map.tile_sets[Prototype_Map_Enum.TILE_SET_MINI_MAP],
            ((lvl_map.mini_map_pos_x, lvl_map.mini_map_pos_y),
             (lvl_map.mini_map_width, lvl_map.mini_map_height)))
        rect_x = float(lvl_map.mini_map_width) / lvl_map.mini_map_ratio_x
        rect_y = float(lvl_map.mini_map_height) / lvl_map.mini_map_ratio_y
        off_x = float(app.offset_x) / lvl_map.mini_map_ratio_x
        off_y = float(app.offset_y) / lvl_map.mini_map_ratio_y
        off_x = lvl_map.mini_map_pos_x - off_x
        off_y = lvl_map.mini_map_pos_y - off_y
        pygame.draw.rect(app.screen, (0, 255, 0),
                         (off_x, off_y, rect_x, rect_y), 2)

        # show character icons
        for (name, character) in app.team_red.characters.items():
            x = character.pos_x / Prototype_Map_Enum.TILE_WIDTH.value * Prototype_Map_Enum.MINI_MAP_CELL_WIDTH.value + lvl_map.mini_map_pos_x
            y = character.pos_y / Prototype_Map_Enum.TILE_HEIGHT.value * Prototype_Map_Enum.MINI_MAP_CELL_HEIGHT.value + lvl_map.mini_map_pos_y
            pygame.draw.rect(
                app.screen, (255, 0, 0),
                (x, y, Prototype_Map_Enum.MINI_MAP_CELL_WIDTH.value,
                 Prototype_Map_Enum.MINI_MAP_CELL_HEIGHT.value), 2)

        for (name, character) in app.team_blue.characters.items():
            x = character.pos_x / Prototype_Map_Enum.TILE_WIDTH.value * Prototype_Map_Enum.MINI_MAP_CELL_WIDTH.value + lvl_map.mini_map_pos_x
            y = character.pos_y / Prototype_Map_Enum.TILE_HEIGHT.value * Prototype_Map_Enum.MINI_MAP_CELL_HEIGHT.value + lvl_map.mini_map_pos_y
            pygame.draw.rect(
                app.screen, (0, 0, 255),
                (x, y, Prototype_Map_Enum.MINI_MAP_CELL_WIDTH.value,
                 Prototype_Map_Enum.MINI_MAP_CELL_HEIGHT.value), 2)
Beispiel #6
0
 def __init__(self, name, x, y, w, h, color, alpha, text, text_color,
              parent):
     super(GuiLabel, self).__init__(name, x, y, w, h, color, alpha, parent)
     from Game import CGameApp
     app = CGameApp.get_instance()
     self.text_surface = app.font.render(text, False, text_color)
     self.adjust_text_surface()
Beispiel #7
0
 def emit(self, character, enemies, allies):
     from Game import CGameApp
     if self.refresh_time > 0:
         return
     self.emit_time = CGameApp.get_instance().total_turn
     self.refresh_time = self.cool_down
     print "Emit Skill"
Beispiel #8
0
    def emit(self, character, enemies, allies):
        super(Hakurei_Reimu_FuMaJin, self).emit(character, enemies, allies)
        from Game import CGameApp
        app = CGameApp.get_instance()
        if character is None:
            return

        for ally in allies:
            if ally.name != character.name:
                skill_drawer = Skill_Anim_Drawer(Skill_Animations.FUMAJIN)
                skill_drawer.pos = (ally.pos_x, ally.pos_y)
                skill_drawer.is_loop = False
                app.cur_player.skills_objects.add_data(skill_drawer)
                buff = Skill_Buff("FuMaJin", character, ally)
                buff.FUIN = True
                buff.REMAIN_TIME = self.duration
                buff.START_TIME = app.total_turn
                character.send_event(ally, Event_Skill(EventType.CHARACTER_AURA, buff))

        for enemy in enemies:
            skill_drawer = Skill_Anim_Drawer(Skill_Animations.FUMAJIN)
            skill_drawer.pos = (enemy.pos_x, enemy.pos_y)
            skill_drawer.is_loop = False
            app.cur_player.skills_objects.add_data(skill_drawer)
            buff = Skill_Buff("FuMaJin", character, enemy)
            buff.FUIN = True
            buff.REMAIN_TIME = self.duration
            buff.START_TIME = app.total_turn
            character.send_event(enemy, Event_Skill(EventType.CHARACTER_AURA, buff))
Beispiel #9
0
 def set_pos(self, x, y):
     self.pos_x = x
     self.pos_y = y
     from Game import CGameApp
     lvl_map = CGameApp.get_instance().level_map
     tile = lvl_map.get_tile_by_coord(self.pos_x, self.pos_y)
     tile.occupy = True
     return
Beispiel #10
0
    def get_range(self, x, y):
        from Game import CGameApp
        app = CGameApp.get_instance()
        tx = x / app.level_map.tile_width
        ty = y / app.level_map.tile_height
        ctx = self.pos_x / app.level_map.tile_width
        cty = self.pos_y / app.level_map.tile_height

        return abs(ctx - tx) + abs(cty - ty)
Beispiel #11
0
 def handle_mouse_rbtn_down(self, evt):
     from Game import CGameApp
     app = CGameApp.get_instance()
     self.lvl_map.reset_map()
     self.fsm.change_to_state(Team_Enum.TEAM_NORMAL)
     self.send_event(app.gui_manager, Event(EventType.CLOSE_CHARACTER_MENU))
     if self.character_selected is not None:
         self.character_selected.fsm.change_to_state(
             Character_State_Enum.WAITING_FOR_CMD)
Beispiel #12
0
 def __init__(self, name, x, y, w, h, color, alpha, text, text_color,
              parent):
     super(GuiButton, self).__init__(name, x, y, w, h, color, alpha, parent)
     from Game import CGameApp
     app = CGameApp.get_instance()
     self.text_surface = app.font.render(text, False, text_color)
     self.desc = None
     self.skill_attached = None
     # register handlers
     self.add_handler(EventType.MOUSE_LBTN_DOWN, self.handle_click)
Beispiel #13
0
 def handle_click(self, evt):
     print str(self.name) + " Button Pressed"
     from Game import CGameApp
     app = CGameApp.get_instance()
     pygame.draw.rect(app.screen, (0, 0, 255),
                      (self.x, self.y, self.w, self.h), 1)
     self.send_event(
         self.parent,
         Event_Gui_Btn_Pressed(EventType.GUI_BTN_PRESSED, self.name))
     return
Beispiel #14
0
 def handle_skill_btn(self):
     print "Select Skill"
     from Game import CGameApp
     from Team import Team_Enum
     app = CGameApp.get_instance()
     app.cur_player.team.fsm.change_to_state(
         Team_Enum.TEAM_CHARACTER_SELECTED)
     if self.show:
         from Game import CGameApp
         app = CGameApp.get_instance()
         gui_mgr = app.gui_manager
         cur_team = CGameApp.get_instance().cur_team
         gui_mgr.gui_wnds[Gui_Enum.Character_Skill_Item_Menu].show = True
         gui_mgr.gui_wnds[
             Gui_Enum.Character_Skill_Item_Menu].link_to_character(
                 app.cur_player.team.character_selected)
         gui_mgr.gui_wnds[Gui_Enum.Character_Skill_Item_Menu].set_pos(
             self.x + self.w, self.y)
         self.send_event(app.cur_player.team.character_selected,
                         Event(EventType.CHARACTER_SKILL_CMD))
Beispiel #15
0
 def draw(self, et):
     if not self.show:
         return
     self.process_evt_queue()
     from Game import CGameApp
     app = CGameApp.get_instance()
     app.screen.blit(self.surface, ((self.x, self.y), (self.w, self.h)))
     for (name, widget) in self.widgets.items():
         if widget.show:
             widget.draw(et)
     pygame.draw.rect(app.screen, (255, 255, 255),
                      (self.x, self.y, self.w, self.h), 2)
Beispiel #16
0
 def draw(self, et):
     super(Character_State_Skill_Target_Search, self).draw(et)
     self.fsm.owner.sprite_sheet.draw(0, self.fsm.owner.get_pos())
     from Game import CGameApp
     from LocalInput import LocalInput
     app = CGameApp.get_instance()
     map = app.level_map
     tile = map.select_tile_by_mouse(LocalInput.mouse_pos)
     map.reset_skill_map()
     if tile is not None and tile.marked:
         map.bfs_travel_skill(tile, (255, 0, 0),
                              self.fsm.owner.cur_skill.aoe_rng)
Beispiel #17
0
    def select_character_by_mouse(self, mouse_pos):
        from Game import CGameApp
        app = CGameApp.get_instance()
        x = mouse_pos[0] - app.offset_x
        y = mouse_pos[1] - app.offset_y

        for (name, character) in self.characters.items():
            if QuadTreeForTile.check_tile(
                    character.pos_x, character.pos_y,
                    Prototype_Map_Enum.TILE_WIDTH.value - 1,
                    Prototype_Map_Enum.TILE_HEIGHT.value - 1, x, y, 0, 0):
                return character
        return None
Beispiel #18
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, (255, 0, 255),
                         (self.x, self.y, self.w, self.h), 1)

        self.process_evt_queue()
Beispiel #19
0
 def draw(self, et):
     super(Character_State_Waiting_For_Command, self).draw(et)
     from Game import CGameApp
     from Team import Team_Enum
     app = CGameApp.get_instance()
     c = (255, 255, 255)
     if self.fsm.owner.team.name == Team_Enum.TEAM_RED:
         c = (255, 0, 0)
     elif self.fsm.owner.team.name == Team_Enum.TEAM_BLUE:
         c = (0, 0, 255)
     x = self.fsm.owner.get_pos()[0] + app.offset_x
     y = self.fsm.owner.get_pos()[1] + app.offset_y
     pygame.draw.ellipse(app.screen, c, ((x, y), (36, 36)), 2)
     self.fsm.owner.sprite_sheet.draw(0, self.fsm.owner.get_pos())
Beispiel #20
0
 def handle_show_character_menu(self, evt):
     from Game import CGameApp
     app = CGameApp.get_instance()
     if evt.character is not None:
         self.gui_wnds[Gui_Enum.Character_Plane].link_to_character(
             evt.character)
         if evt.character.team.name == app.cur_player.team.name:
             x = evt.character.pos_x + 18
             y = evt.character.pos_y + 18
             x += app.offset_x
             y += app.offset_y
             self.gui_wnds[Gui_Enum.Character_Control_Menu].set_pos(x, y)
             self.gui_wnds[Gui_Enum.Character_Control_Menu].show = True
     return
Beispiel #21
0
 def handle_attack_btn(self):
     print "Handle Attack Btn"
     from Game import CGameApp
     from Team import Team_Enum
     app = CGameApp.get_instance()
     app.cur_player.team.fsm.change_to_state(
         Team_Enum.TEAM_CHARACTER_SELECTED)
     self.send_event(app.cur_player.team.character_selected,
                     Event(EventType.CHARACTER_ATTACK_CMD))
     self.send_event(app.gui_manager, Event(EventType.CLOSE_CHARACTER_MENU))
     tile = app.level_map.get_tile_by_coord(
         app.cur_player.team.character_selected.pos_x,
         app.cur_player.team.character_selected.pos_y)
     app.level_map.bfs_travel_no_occupy(
         tile, (255, 0, 0, 196),
         app.cur_player.team.character_selected.attack_range)
Beispiel #22
0
 def handle_character_attacked(self, evt):
     if self.immortal:
         return
     dmg = evt.src_character.attack - self.defense
     self.hp -= dmg
     evt.src_character.fsm.change_to_state(
         Character_State_Enum.WAITING_FOR_CMD)
     if self.hp <= 0:
         self.fsm.change_to_state(Character_State_Enum.DEAD)
         from Game import CGameApp
         lvl_map = CGameApp.get_instance().level_map
         tile = lvl_map.get_tile_by_coord(self.pos_x, self.pos_y)
         tile.occupy = False
         self.team.dead_characters[self.name] = self
         del self.team.characters[self.name]
     else:
         self.fsm.change_to_state(Character_State_Enum.ATTACKED)
Beispiel #23
0
 def handle_move_btn(self):
     print "Handle Move Btn"
     from Game import CGameApp
     from Team import Team_Enum
     app = CGameApp.get_instance()
     app.cur_player.team.fsm.change_to_state(
         Team_Enum.TEAM_CHARACTER_SELECTED)
     if app.cur_player.team.character_selected is not None:
         self.send_event(app.cur_player.team.character_selected,
                         Event(EventType.CHARACTER_MOVE_CMD))
         self.send_event(app.gui_manager,
                         Event(EventType.CLOSE_CHARACTER_MENU))
         tile = app.level_map.get_tile_by_coord(
             app.cur_player.team.character_selected.pos_x,
             app.cur_player.team.character_selected.pos_y)
         app.level_map.bfs_travel(tile, (0, 0, 255, 196),
                                  app.cur_player.team.character_selected.ap)
Beispiel #24
0
    def emit(self, character, enemies, allies):
        super(Hakurei_Reimu_MuGenNoKoSoKuKiGanSaTsu, self).emit(character, enemies, allies)
        from Game import CGameApp
        app = CGameApp.get_instance()
        if character is None:
            return

        for ally in allies:
            skill_drawer = Skill_Anim_Drawer(Skill_Animations.AP_UP)
            skill_drawer.pos = (ally.pos_x, ally.pos_y)
            skill_drawer.is_loop = False
            app.cur_player.skills_objects.add_data(skill_drawer)
            buff = Skill_Buff("MuGenNoKoSoKuKiGanSaTsu", character, ally)
            buff.AP = self.ap_buff
            buff.REMAIN_TIME = self.duration
            buff.START_TIME = app.total_turn
            character.send_event(ally, Event_Skill(EventType.CHARACTER_AURA, buff))
Beispiel #25
0
 def handle_skill(self, skill):
     if skill is None:
         return
     from Game import CGameApp
     from Character import Character_State_Enum
     app = CGameApp.get_instance()
     map = app.level_map
     team = app.cur_player.team
     tile = app.level_map.get_tile_by_coord(team.character_selected.pos_x,
                                            team.character_selected.pos_y)
     map.bfs_travel_no_occupy(tile, (0, 0, 255), skill.rng)
     self.send_event(app.gui_manager, Event(EventType.CLOSE_CHARACTER_MENU))
     team.character_selected.fsm.change_to_state(
         Character_State_Enum.SKILL_TARGET_SEARCH)
     print skill.name
     if isinstance(skill, Skill_Single_Target):
         print "Single Target Skill"
         team.character_selected.cur_skill = skill
     elif isinstance(skill, Skill_AOE):
         print "AOE Skill"
         team.character_selected.cur_skill = skill
Beispiel #26
0
 def link_to_character(self, name):
     from Game import CGameApp
     characters = CGameApp.get_instance().characters
     if name in characters:
         character = characters[name]
         self.character_name.set_text(character.name, (255, 255, 255))
         self.character_pic.set_picture(character.sprite)
         self.character_str.set_text("STR: " + str(character.strength),
                                     (255, 255, 255))
         self.character_agi.set_text("AGI: " + str(character.agility),
                                     (255, 255, 255))
         self.character_int.set_text("INT: " + str(character.intelligence),
                                     (255, 255, 255))
         self.character_atk.set_text("ATK: " + str(character.attack),
                                     (255, 255, 255))
         self.character_atk_rng.set_text(
             "RNG: " + str(character.attack_range), (255, 255, 255))
         self.character_def.set_text("DEF: " + str(character.defense),
                                     (255, 255, 255))
         self.character_res.set_text("RES: " + str(character.resistance),
                                     (255, 255, 255))
         self.character_ap.set_text("AP: " + str(character.ap),
                                    (255, 255, 255))
         self.character_hp.set_text("HP: " + str(character.hp),
                                    (255, 255, 255))
         self.character_mp.set_text("MP: " + str(character.mp),
                                    (255, 255, 255))
     else:
         self.character_name.set_text("???", (255, 255, 255))
         self.character_pic.set_picture(None)
         self.character_str.set_text("STR:", (255, 255, 255))
         self.character_agi.set_text("AGI:", (255, 255, 255))
         self.character_int.set_text("INT:", (255, 255, 255))
         self.character_atk.set_text("ATK:", (255, 255, 255))
         self.character_atk_rng.set_text("RNG:", (255, 255, 255))
         self.character_def.set_text("DEF:", (255, 255, 255))
         self.character_res.set_text("RES:", (255, 255, 255))
         self.character_ap.set_text("AP:", (255, 255, 255))
         self.character_hp.set_text("HP:", (255, 255, 255))
         self.character_mp.set_text("MP:", (255, 255, 255))
 def draw(self, et):
     if not self.show:
         return
     self.anim_time += et
     self.acc_time += et
     if self.acc_time > self.skill_anim_sheet.frame_time:
         self.acc += 1
         self.acc_time = 0
         self.acc %= self.skill_anim_sheet.total_frames
     if self.anim_time > self.skill_anim_sheet.anim_len:
         self.acc = 0
         self.acc_time = 0
         self.anim_time = 0
         self.loops += 1
         if not self.is_loop:
             self.show = False
     else:
         from Game import CGameApp
         app = CGameApp.get_instance()
         app.screen.blit(
             self.skill_anim_sheet.frames[self.acc],
             ((self.pos[0] + app.offset_x, self.pos[1] + app.offset_y),
              (36, 36)))
Beispiel #28
0
 def handle_mouse_lbtn_down(self, evt):
     from LocalInput import LocalInput
     from Game import CGameApp
     app = CGameApp.get_instance()
     mouse_character = app.select_character_by_mouse(evt.mouse_pos)
     if self.fsm.is_in_state(Team_Enum.TEAM_NORMAL):
         print str(self.name) + " in Normal State"
         if mouse_character is not None:
             self.send_event(
                 app.gui_manager,
                 Event_Gui_Show_Character_Menu(
                     EventType.SHOW_CHARACTER_MENU, mouse_character))
             if mouse_character.team.name != app.cur_player.team.name:
                 return
             else:
                 self.character_selected = mouse_character
                 self.send_event(
                     app.gui_manager,
                     Event_Gui_Show_Character_Menu(
                         EventType.SHOW_CHARACTER_MENU, mouse_character))
                 self.fsm.change_to_state(Team_Enum.TEAM_CHARACTER_SELECTED)
     elif self.fsm.is_in_state(Team_Enum.TEAM_CHARACTER_SELECTED):
         print str(self.name) + " in Selected State"
         if self.character_selected.fsm.is_in_state(
                 Character_State_Enum.WAITING_FOR_CMD):
             if mouse_character is not None:
                 self.send_event(
                     app.gui_manager,
                     Event_Gui_Show_Character_Menu(
                         EventType.SHOW_CHARACTER_MENU, mouse_character))
         if self.character_selected is not None:
             self.send_event(
                 self.character_selected,
                 Event_Mouse_LBTN_DOWN(EventType.MOUSE_LBTN_DOWN,
                                       LocalInput.mouse_pos))
         return
Beispiel #29
0
 def select_tile_by_mouse(self, mouse_pos):
     from Game import CGameApp
     app = CGameApp.get_instance()
     x = mouse_pos[0] - int(app.offset_x)
     y = mouse_pos[1] - int(app.offset_y)
     return self.get_tile_by_coord(x, y)
Beispiel #30
0
 def get_view_port(self):
     from Game import CGameApp
     app = CGameApp.get_instance()
     return (-app.offset_x, -app.offset_y, app.screen_w,
             CGameApp.get_instance().screen_h)