示例#1
0
    def __init__(self, waiter, subject):
        """
        Constructor
        :param waiter: waiter for implement hammer action
        :return: None
        """

        # Constructor of base class
        Customer.__init__(self, waiter)
        Observer.__init__(self)
        self.register(subject, 'player_motion')

        avatars = Factory.get_avatars('hammer_avatars')
        if avatars is None:
            raise BaseException('Can not load avatar for hammer')
        self.drawable_avatars = []
        for avatar in avatars:
            drawable_item = Drawable(avatar, (0, 0), DRAWABLE_INDEX.PLAYER)
            self.drawable_avatars.append(drawable_item)

        # Default is the first one
        self.drawable_avatar = self.drawable_avatars[0]

        self.sound_hit = Factory.get_sound('hammer_hit')
        if self.sound_hit is None:
            raise BaseException('Can not load "hit" sound effect of hammer')

        # Used to step counter, change image when hammer
        self.index = 0

        # Used to prevent hammer when hammering
        self.hammering = False

        self.timer = None

        self.pos = (0, 0)

        self.size = (10, 15)     # Height, Width

        self.distance = (150, 150)
示例#2
0
    def __init__(self, name, waiter, stick_time):

        Customer.__init__(self, waiter)

        self.name = name

        self.appear_index = 0
        self.die_index = 0
        self.disappear_index = 0
        self.stand_index = 0

        self.appear_timer = None
        self.die_timer = None
        self.disappear_timer = None
        self.stand_timer = None
        self.main_timer = None

        self.alive = True
        self.showing = False

        self.size = (40, 40)
        self.rect_bound = pygame.Rect(0, 0, self.size[0], self.size[1])

        appear_avatars = Factory.get_avatars('head_appear_avatars')
        if appear_avatars is None:
            raise BaseException('Can not load avatar for Head')
        self.appear_drawable_avatars = []
        for avatar in appear_avatars:
            pos = (0, 0)
            drawable_item = Drawable(avatar, pos, DRAWABLE_INDEX.HEAD)
            self.appear_drawable_avatars.append(drawable_item)

        die_avatars = Factory.get_avatars('head_die_avatars')
        if die_avatars is None:
            raise BaseException('Can not load avatar for Head')
        self.die_drawable_avatars = []
        for avatar in die_avatars:
            pos = (0, 0)
            drawable_item = Drawable(avatar, pos, DRAWABLE_INDEX.HEAD)
            self.die_drawable_avatars.append(drawable_item)

        disappear_avatars = Factory.get_avatars('head_disappear_avatars')
        if disappear_avatars is None:
            raise BaseException('Can not load avatar for Head')
        self.disappear_drawable_avatars = []
        for avatar in disappear_avatars:
            pos = (0, 0)
            drawable_item = Drawable(avatar, pos, DRAWABLE_INDEX.HEAD)
            self.disappear_drawable_avatars.append(drawable_item)

        stand_avatars = Factory.get_avatars('head_stand_avatars')
        if disappear_avatars is None:
            raise BaseException('Can not load avatar for Head')
        self.stand_drawable_avatars = []
        for avatar in stand_avatars:
            pos = (0, 0)
            drawable_item = Drawable(avatar, pos, DRAWABLE_INDEX.HEAD)
            self.stand_drawable_avatars.append(drawable_item)

        self.stick_time = stick_time

        self.sound_head_appear = Factory.get_sound('head_appear')
        self.sound_head_disappear = Factory.get_sound('head_disappear')
        self.sound_head_hit = Factory.get_sound('head_hit')

        return
    def __init__(self, event_controller, env):

        # Init pygame
        pygame.init()
        pygame.mixer.init()

        # Save event_controller to use later
        self.event_controller = event_controller
        self.env = env

        # Set some value for head
        self.number_of_enemy = NUM_SPRITES.NUMBER_OF_ENEMY
        self.time_to_create_new = DURATION.TIME_CREATE_NEW
        self.max_of_current_enemy = NUM_SPRITES.MAX_OF_CURRENT_ENEMY
        self.totalCreatedEnemy = 0

        # Constructor of base class
        Observer.__init__(self)
        # Register to receive some special events
        self.register(event_controller, 'special')

        Waiter.__init__(self)

        # Attribute declare
        self.quit_game = False
        self.player = None

        self.heads = []
        self.head_timer = None
        self.interval_section = 3
        self.appear_delay = 3
        self.stick_time = 0.12
        self.is_first_blood = True

        self.sound_prepare4battle = Factory.get_sound('prepare4battle')
        if self.sound_prepare4battle is None:
            raise NotImplementedError
        self.sound_prepare4battle_playing = False
        self.sound_first_blood = Factory.get_sound('first_blood')
        if self.sound_first_blood is None:
            raise NotImplementedError
        self.sound_double_kill = Factory.get_sound('double_kill')
        if self.sound_double_kill is None:
            raise NotImplementedError
        self.sound_triple_kill = Factory.get_sound('triple_kill')
        if self.sound_triple_kill is None:
            raise NotImplementedError
        self.sound_ultra_kill = Factory.get_sound('ultra_kill')
        if self.sound_ultra_kill is None:
            raise NotImplementedError
        self.sound_rampage_kill = Factory.get_sound('rampage')
        if self.sound_rampage_kill is None:
            raise NotImplementedError

        self.screen = pygame.display.set_mode(self.env.screen_size)
        pygame.mouse.set_visible(False)    # Hide default mouse cursor

        self.timer_counter = None
        self.stage = None
        self.id = 0
        self.finish = False
        self.num_head_kill_in_section = 0