Example #1
0
    def hit(self, damage):
        self.hp -= damage
        if self.hp <= 0 and self.alive:
            self.body.velocity = 0, 0
            self.body.angular_velocity = 0
            self.destroy()
        else:
            hit_images = []
            for i in range(1, 10):
                image = pyglet.image.load("res/PNG/Tanks/hit/%d.png" % (i))
                hit_images.append(image)
            for i in range(len(hit_images)):
                hit_images[i].anchor_x = hit_images[i].width // 2
                hit_images[i].anchor_y = hit_images[i].height // 2 + 5
            hit_anim = pyglet.image.Animation.from_image_sequence(
                hit_images, 0.1, False)
            hit_sprite = pyglet.sprite.Sprite(hit_anim,
                                              x=self.sprite.position[0],
                                              y=self.sprite.position[1],
                                              batch=fg_batch,
                                              group=explosion_group)
            hit_sprite.scale = Tank.SCALE
            hit_sprite.rotation = self.sprite.rotation

            global effect_count
            effect_count += 1
            hit_sprite.idn = effect_count
            effects[effect_count] = hit_sprite

            def hit_s(self):
                effects[hit_sprite.idn].delete()
                effects.pop(hit_sprite.idn)

            clock.schedule_once(hit_s, 1)
Example #2
0
    def __init__(self,
                 img, x=0, y=0,
                 blend_src=GL_SRC_ALPHA,
                 blend_dest=GL_ONE_MINUS_SRC_ALPHA,
                 batch=None,
                 group=None,
                 usage='dynamic',
                 subpixel=False):
        '''Create a sprite.

        :Parameters:
            `img` : `AbstractImage` or `Animation`
                Image or animation to display.
            `x` : int
                X coordinate of the sprite.
            `y` : int
                Y coordinate of the sprite.
            `blend_src` : int
                OpenGL blend source mode.  The default is suitable for
                compositing sprites drawn from back-to-front.
            `blend_dest` : int
                OpenGL blend destination mode.  The default is suitable for
                compositing sprites drawn from back-to-front.
            `batch` : `Batch`
                Optional batch to add the sprite to.
            `group` : `Group`
                Optional parent group of the sprite.
            `usage` : str
                Vertex buffer object usage hint, one of ``"none"`` (default),
                ``"stream"``, ``"dynamic"`` or ``"static"``.  Applies
                only to vertex data.
            `subpixel` : bool
                Allow floating-point coordinates for the sprite. By default,
                coordinates are restricted to integer values.

        '''
        if batch is not None:
            self._batch = batch

        self._x = x
        self._y = y

        if isinstance(img, image.Animation):
            self._animation = img
            self._frame_index = 0
            self._texture = img.frames[0].image.get_texture()
            self._next_dt = img.frames[0].duration
            if self._next_dt:
                clock.schedule_once(self._animate, self._next_dt)
        else:
            self._texture = img.get_texture()

        ## MY ADDITION - set anchor in center
        self._texture.anchor_x = self._texture.width/2
        self._texture.anchor_y = self._texture.height/2

        self._group = SpriteGroup(self._texture, blend_src, blend_dest, group)
        self._usage = usage
        self._subpixel = subpixel
        self._create_vertex_list()
Example #3
0
 def next_text(self, _):
     self.textidx += 1
     self.textidx %= len(texts)
     delay = 1.5
     if self.text == '':
         delay = 0.5
     clock.schedule_once(self.next_text, delay)
Example #4
0
    def init(self, **kwargs):
        self.image = load_image(self.image_file)
        self.sprite = Sprite(self.image, self.x, self.y,
                             batch=self.batch, group=self.group)
        self.chunk.objects.append(self)

        clock.schedule_once(self.delete, self.timer)
Example #5
0
    def __init__(self, x, y):
        dst = 50
        num = 10
        dt = .6
        fscale = 1
        by = 360.0/num
        self.images = []
        for i in range(num):
            ang = i*by
            rad = ang / 180.0 * math.pi
            s = simage.SImage('wedge.png', x, y)
            s.sp.x = rabbyt.lerp(end=math.cos(rad)*dst*fscale+x, dt=dt)
            s.sp.y = rabbyt.lerp(end=math.sin(rad)*dst*fscale+y, dt=dt)
            '''cool things:
            #1
            s.sp.rot = ang - 90

            #2
            s.sp.rot = ang

            #3
            s.sp.rot = ang + 90
            '''
            s.sp.rot = rabbyt.lerp(ang, ang - 90.0, dt=dt/2)
            s.sp.rot = rabbyt.lerp(ang + 90, ang - 90.0, dt=dt)
            #s.sp.rot = ang - 90.0
            s.sp.scale = rabbyt.lerp(0,fscale,dt=dt)
            self.images.append(s)
        self.on = True
        def tmp(dt):
            l = rabbyt.lerp(1.0,0.0,dt=dt)
            for i in self.images:
                i.sp.alpha = l#rabbyt.lerp(1.0,0.0,dt=1)
            clock.schedule_once(self.off, dt)
        clock.schedule_once(tmp, dt/2)
Example #6
0
    def fire(self, projectile_id):
        if self.ammo_type == SharedProjectile.Ammo_Type.REGULAR and self.ammo1 <= 0 or self.ammo_type == SharedProjectile.Ammo_Type.AP and self.ammo2 <= 0:
            return
        if self.ammo_type == SharedProjectile.Ammo_Type.REGULAR:
            self.ammo1 -= 1
        elif self.ammo_type == SharedProjectile.Ammo_Type.AP:
            self.ammo2 -= 1
        posx = self.body.position[0] + (
            sin(radians(self.barrelSprite.rotation)) * 50)
        posy = self.body.position[1] + (
            cos(radians(self.barrelSprite.rotation)) * 50)
        global projectile_count
        p = SharedProjectile(pos=(posx, posy),
                             color=self.color,
                             idn=projectile_id,
                             src_idn=self.idn,
                             client_id=self.CLIENT_ID,
                             type=self.ammo_type)
        p.body.velocity = (p.velocity *
                           sin(radians(self.barrelSprite.rotation)),
                           p.velocity *
                           cos(radians(self.barrelSprite.rotation)))
        p.body.angle = radians(self.barrelSprite.rotation)
        projectiles[p.idn] = p
        projectile_count += 1

        self.isReloading = True

        def reload(self, idn):
            tanks[idn].isReloading = False

        clock.schedule_once(reload, 2, self.idn)
Example #7
0
    def start(self):
        self._remove_last_games_items()

        self.wave = 0
        Player.start_game()
        self.add(HudInstructions())
        clock.schedule_once(lambda _: self.spawn_wave(), 2)
Example #8
0
    def __init__(self,
                 img, x=0, y=0, z=0,
                 blend_src=GL_SRC_ALPHA,
                 blend_dest=GL_ONE_MINUS_SRC_ALPHA,
                 batch=None,
                 group=None,
                 usage='dynamic',
                 subpixel=False,
                 alpha_test_val=0.5):
        '''Create a sprite with z-coordinate support.

        :Parameters:
            `img` : `AbstractImage` or `Animation`
                Image or animation to display.
            `x` : int
                X coordinate of the sprite.
            `y` : int
                Y coordinate of the sprite.
            `z` : int
                Z coordinate of the sprite.
            `blend_src` : int
                OpenGL blend source mode.  The default is suitable for
                compositing sprites drawn from back-to-front.
            `blend_dest` : int
                OpenGL blend destination mode.  The default is suitable for
                compositing sprites drawn from back-to-front.
            `batch` : `Batch`
                Optional batch to add the sprite to.
            `group` : `Group`
                Optional parent group of the sprite.
            `usage` : str
                Vertex buffer object usage hint, one of ``"none"`` (default),
                ``"stream"``, ``"dynamic"`` or ``"static"``.  Applies
                only to vertex data.

        '''
        if batch is not None:
            self._batch = batch

        self._x = x
        self._y = y
        self._z = z
        
        self._alpha_test_val = alpha_test_val

        if isinstance(img, image.Animation):
            self._animation = img
            self._frame_index = 0
            self._texture = img.frames[0].image.get_texture()
            self._next_dt = img.frames[0].duration
            if self._next_dt:
                clock.schedule_once(self._animate, self._next_dt)
        else:
            self._texture = img.get_texture()

        # Must use the ZSpriteGroup to be able to enable depth testing
        self._group = ZSpriteGroup(self._alpha_test_val, self._texture, blend_src, blend_dest, group)
        self._usage = usage
        self._subpixel = subpixel
        self._create_vertex_list()
Example #9
0
    def on_first_throw(self, first_result):
        self.board_ctrl.dice_ctrl.stop_waiting_for_throw(self.on_first_throw)
        self.first_result = first_result

        clock.schedule_once(lambda _: self.board_ctrl.dice_ctrl.reset_dice(),
                            delay=0.3)
        self.board_ctrl.dice_ctrl.wait_for_throw(self.on_second_throw)
Example #10
0
 def __init__(self, x, y, dx, _, owner):
     WorldItem.__init__(self, x, y, 0, 0)
     self.rotation = 0
     self.speed = copysign(uniform(5, 52), -dx)
     self.curve = uniform(0.002, 0.02)
     self.owner = owner
     clock.schedule_once(lambda _: self.reset_owner(), 1)
Example #11
0
def on_key_press(symbol, modifiers):
  global lastKeyPressed
  #for now escape quits
  if symbol == key.ESCAPE: InitGL.win.has_exit = True
  lastKeyPressed = (symbol, modifiers)
  Nodes.canvas.focused.keydown = (symbol, modifiers)
  #set up keyrate timer - on_key_release removes it
  clock.schedule_once(repeatKey, 0.4)
Example #12
0
 def emphasize(self, duration=0.10):
     if self.emphasizable:
         self.emphasizable = False
         if duration < 0.10:
             duration = 0.10
         half_duration = duration / 2.0
         self.do(ScaleTo(1.2, half_duration) + ScaleTo(1, half_duration))
         schedule_once(self.make_emphasizable, duration)
Example #13
0
 def __init__(self, difficulties, camera):
     self.difficulties = difficulties
     self.counter = 0
     self.labels = deque()
     self.credit_it = self.credit_text()
     self.camera = camera
     schedule_interval(self.update_position, 0.017)
     schedule_once(self.update_text, 0)
Example #14
0
def on_key_press(symbol,modifiers):
    if symbol == key.Q:
        pyglet.app.exit()
    if symbol in valid_keys:
        if move_robber(symbol):
            clock.schedule_once(move_cop0, cop_delay)
            clock.schedule_once(move_cop1, cop_delay * 2)
            game_state.print_locations()
Example #15
0
 def _level_anime(dt, self):
     if self.level_anime <= 3:
         self.level_anime += 1
         clock.schedule_once(self._level_anime, 2, self)
     else:
         self.level_anime = -1
     if DEBUG:
         print 'LEVEL END ANIMATION (%s)' %(self.level_anime)
Example #16
0
 def next_frame(self, dt):
     self.index = (self.index + 1) % len(self.animation.frames)
     frame = self.animation.frames[self.index]
     if frame.duration is not None:
         delay = frame.duration - (self.expected_delay - dt)
         delay = min(max(0, delay), frame.duration)
         clock.schedule_once(self.next_frame, delay)
         self.expected_delay = delay
Example #17
0
def scene1():
    print "scene1"
    s.Narration('Sending me into the snow-storm')
    s.Narration('Without any help')
    s.Narration('Again')
    s.Narration('Alone')
    clock.schedule_interval(spawn_troll, 5)
    clock.schedule_once(scene2, 20)
Example #18
0
 def take_damage(self, dmg) -> int:
     self.color = (128, 0, 0)
     clock.schedule_once(self.revert_color, 0.25)
     self.health = self.health - dmg
     if (self.health <= 0):
         self.is_dead = True
         return (5 * (1 + self.multiplier))
     else:
         return 0
Example #19
0
 def controller_changed(self, sender, original):
     start_zone = self.play_zones[original]
     end_zone = self.play_zones[sender.controller]
     guicard = start_zone.get_card(sender)
     start_pos = self.project_to_window(*tuple(start_zone.pos+guicard.pos))
     start_zone.remove_card(sender, clock)
     guicard = end_zone.add_card(sender,startt=1.6)
     end_pos = self.project_to_window(*tuple(end_zone.pos+guicard.pos))
     clock.schedule_once(lambda t: self.sparks.add_spark(start_pos, end_pos, dt=1., color=str(sender.color)), 0.7)
Example #20
0
 def make_shape_animations(self):
     x, y = get_xy_positions(self.win.width, self.win.height)
     s = SImage(get_random_image(), x, y)
     s.sp.x = rabbyt.lerp(end=random.uniform(0, self.win.width), dt=1)
     s.sp.y = rabbyt.lerp(end=random.uniform(0, self.win.height), dt=1)
     s.sp.rot = rabbyt.lerp(start=0, end=360, dt=1)
     s.sp.scale = rabbyt.lerp(.25, 1, dt=1)
     self.world.objects.append(s)
     clock.schedule_once(lambda dt: self.world.objects.remove(s), 1)
Example #21
0
 def _spawn(self, dt):
     x = uniform(self.left, self.right)
     y = uniform(self.bottom, self.top)
     spawned_enemy = choice(self.available_enemies, p=self.spawn_ratios)
     spawned_enemy(self.game_controller, center_x=x, center_y=y)
     clock.schedule_once(
         self._spawn,
         self.spawn_interval *
         np.sqrt(len(self.game_controller.enemy_list) + 1))
Example #22
0
 def __init__(self, entity, logic, **args):
   super(ExplosionBehavior, self).__init__(entity, logic)
   
   entity.name = next_anonymous_name(self)
   entity.state = ["explode"]
   
   self.play_sound("Burst")
   
   clock.schedule_once(self.remove, .24)
Example #23
0
 def make_shape_animations(self):
     x, y = get_xy_positions(self.win.width, self.win.height)
     s = SImage(get_random_image(), x, y)
     s.sp.x = rabbyt.lerp(end=random.uniform(0, self.win.width), dt=1)
     s.sp.y = rabbyt.lerp(end=random.uniform(0, self.win.height), dt=1)
     s.sp.rot = rabbyt.lerp(start=0, end=360, dt=1)
     s.sp.scale = rabbyt.lerp(.25, 1, dt=1)
     self.world.objects.append(s)
     clock.schedule_once(lambda dt:self.world.objects.remove(s), 1)
Example #24
0
 def spawn(self, dt=None, set_health=True):
     point = self._determine_spawn(self.team)
     if point is not None: #will return None if all the gates have been destroyed
         self.position, self.forward, self.up = point.position + point.forward * 5, point.forward, point.up
         self.velocity = Vector3(0,0,0)
         if set_health:
             self.health, self.dead = 100, False
     else:
         clock.schedule_once(self.spawn, 5)
Example #25
0
def scene2(dt):
    print "scene2"
    s.Narration('Why me?')
    s.Narration('Alone')
    s.Narration('Why me?')
    s.Narration('Alone')
    s.Narration('This is not fair')
    clock.unschedule(spawn_troll)
    clock.schedule_interval(spawn_troll, 3)
    clock.schedule_once(scene3, 20)
Example #26
0
    def play(self):
        if self.mediaplayer:
            logging.debug( 'Music.play {')
            self.mediaplayer = MediaPlayer()
            self.mediaplayer.volume = 0.45
            self.mediaplayer.eos_action = self.mediaplayer.EOS_LOOP
            self.mediaplayer.queue(self.current_source)

            # if we play music immediately, it stutters a little at the start
            # so schedule it to start a second from now
            clock.schedule_once(lambda _: self.mediaplayer.play(), 1)
            logging.debug( '} Music.play')
Example #27
0
    def play(self):
        if settings.get('all', 'force_audio') == 'silent':
            return

        self.player = Player()
        self.player.volume = 0.15
        self.player.eos_action = self.player.EOS_LOOP
        self.player.queue(self.music)

        # if we play music immediately, it stutters a little at the start
        # so schedule it to start a second from now
        if settings.getboolean('all', 'music'):
            clock.schedule_once(lambda _: self.player.play(), 1)
Example #28
0
 def make_string(self, string):
     x, y = get_xy_positions(self.win.width, self.win.height)
     s = SpriteText(self.ft, string)
     s.rgba = rcolor()
     s.x = rabbyt.lerp(x, random.uniform(0, self.win.width), dt=1)
     s.y = rabbyt.lerp(y, random.uniform(0, self.win.height), dt=1)
     s.rot = rabbyt.lerp(start=0, end=360, dt=1)
     s.scale = rabbyt.lerp(.5, 1, dt=1)
     self.world.objects.append(s)
     def tmp(dt):
         s.alpha = rabbyt.lerp(1.0, 0, dt=2)
         clock.schedule_once(lambda dt:self.world.objects.remove(s),2)
     clock.schedule_once(tmp, 2)
def go_next_test_hand(dt):
    global h, test_hand_no
    hand_str, expected_desc = test_hands[test_hand_no]
    h = Hand.from_str(hand_str)
    actual_desc = h.get_desc()
    result = "PASS!"
    if actual_desc != expected_desc: 
        result = "FAIL!!"
    text.text = "hand:%s\nactual:%s\nexpected:%s\n%s" % (hand_str, actual_desc, expected_desc, result)
    if test_hand_no + 1 == len(test_hands): 
        text.text = "ALL YOUR TESTS ARE BELONG TO US!"
    else: 
        test_hand_no = test_hand_no + 1
        clock.schedule_once(go_next_test_hand, TEST_DELAY) 
Example #30
0
    def update(self,dt):
        ''' Update game state '''
        if self.pause or self.level_anime > 0:
            return
        elif self.level_anime == -1:
            if self.target_controller.level + 1 > len(self.LEVELS):
                self.game_complete = True
            self.target_controller = TargetController(
                self.target_controller.difficulty,
                self.target_controller.level + 1)
            self.level_anime = 0
        elif not (self.game_complete or self.level_anime) and (
            self.score > self.LEVELS[self.target_controller.level - 1]):
            self.level_anime = 1
            clock.schedule_once(self._level_anime, 2.5, self)
            self.killall()

        for t in self.target_controller.targets:
            if (not t.is_dead):
                # Calculate the health kill
                if t.z < self.LAWN_ZMAX:
                    self.health_loss += (self.LAWN_ZMAX - t.z) / self.HDDOWN
                # Move Target
                t.move(dt)
            else:
                # they killed Kenny!
                t.deadtime+=dt
                if (t.deadtime > self.target_controller.max_deadtime):
                    self.target_controller.targets.remove(t)

        # Incrementing counters and timers
        self.timestamp+=dt
        run_len=time.time() - self.runtime

        # checking: should we create target(s)
        create_target = False
        if (self.timestamp > self.target_controller.release_int):
            self.timestamp=0
            create_target = True
        if create_target:
            # K Were supposed to create target(s)
            count = 1
            if (not len(filter(
                    lambda t: not t.is_dead,
                    self.target_controller.targets))):
                # If we clear all targets then create a bunch right away
                count = self.target_controller.relive_count
            for i in range(count):
                if (len(self.target_controller.targets) < MAX_TARGETS):
                        self.target_controller.generate_target(run_len)
Example #31
0
 def invalid_target(self, sender, target):
     if isPlayer(target):
         pstatus = self.player_status[target]
         avatar = pstatus.avatar
         if avatar.shaking == 0:
             avatar.shaking = 1
             avatar._pos.set_transition(dt=0.25, method=lambda t: anim.oscillate_n(t, 4))
             avatar.pos += euclid.Vector3(10, 0, 0)
             clock.schedule_once(lambda t: setattr(avatar, "shaking", 0), 0.5)
     elif isPermanent(target):
         zone = self.play_zones[target.controller]
         guicard = zone.get_card(target)
         guicard.shake()
         clock.schedule_once(lambda t: guicard.unshake(), 0.25)
Example #32
0
 def enter_zone(self, sender, card):
     if sender in self.status_zones:
         pstatus, symbol = self.status_zones[sender]
         if card.key in self.tracker:
             start_pos, from_zone = self.tracker[card.key]
             end_pos = pstatus.pos + symbol.pos
             if from_zone in self.play_zones.values():
                 guicard = from_zone.get_card(card)
                 from_zone.remove_card(card, clock)
                 self.sparks.add_spark(start_pos, start_pos, dt=1.5, color=str(card.color), grow=True)
                 clock.schedule_once(lambda t: self.sparks.add_spark(start_pos, end_pos, dt=1.25, color=str(card.color)), 1.55)
                 clock.schedule_once(lambda t: pstatus.update_zone(sender), 2.80)
                 clock.schedule_once(lambda t: self.sparks.add_star_spark(end_pos, end_pos, dt=.5, color=str(card.color)) , 2.70)
             else:
                 dt = 1.0
                 self.sparks.add_spark(start_pos, end_pos, dt=dt, color="")
                 clock.schedule_once(lambda t: pstatus.update_zone(sender), dt)
             del self.tracker[card.key]
         else: pstatus.update_zone(sender)
     elif str(sender) == "battlefield":
         dt = 0.5
         zone = self.play_zones[card.controller]
         if card.key in self.tracker:
             guicard = zone.add_card(card,startt=dt)
             start_pos, from_zone = self.tracker[card.key]
             end_pos = self.project_to_window(*tuple(zone.pos+guicard.pos))
             self.sparks.add_spark(start_pos, end_pos, grow=True, dt=dt, color=str(card.color))
             del self.tracker[card.key]
         else: zone.add_card(card,startt=0)
     else:
         if card.key in self.tracker:
             start_pos, from_zone = self.tracker[card.key]
             if from_zone in self.play_zones.values():
                 from_zone.remove_card(card, clock)
             del self.tracker[card.key]
Example #33
0
    def _set_image(self, img):
        if self._animation is not None:
            clock.unschedule(self._animate)
            self._animation = None

        if isinstance(img, image.Animation):
            self._animation = img
            self._frame_index = 0
            self._set_texture(img.frames[0].image.get_texture())
            self._next_dt = img.frames[0].duration
            clock.schedule_once(self._animate, self._next_dt)
        else:
            self._set_texture(img.get_texture())
        self._update_position()
Example #34
0
    def fire(self, dt):
        """
        fire a bullet
        """
        if not self.reload:
            angle_radians = radians(self.t.rot)

            bullet_x = self.t.x + sin(angle_radians)
            bullet_y = self.t.y + cos(angle_radians)

            bullet = self.active_weapon(bullet_x, bullet_y, self)
            bullet.rot = self.t.rot
            self.bullet_list.append(bullet)
            self.reload = True
            clock.schedule_once(self.reloadComplete, bullet.load_time)
Example #35
0
	def toggleAwake(self, dt = 0):


		if(self.world.awokenHunter):
			self.awake = not self.awake
		else:
			self.awake = False

		
		if(self.awake):
			# If we just woke up
			clock.schedule_once(self.toggleAwake, uniform(*self.awakeTime))
		else:
			# We just fell asleep, sleep for 5 to 8 seconds
			clock.schedule_once(self.toggleAwake, uniform(*self.sleepTime))
Example #36
0
    def spawn_wave(self):
        self.wave += 1
        self.add(HudMessage("Wave %d" % (self.wave,), remove_after=2))

        text = WAVE_MESSAGES[min(self.wave - 1, len(WAVE_MESSAGES) - 1)]
        hudmessage = HudMessage(text, y=self.height / 2 - 40, color=(255, 255, 255, 128), font_size=16, remove_after=2)
        clock.schedule_once(lambda _: self.add(hudmessage), 0.5)

        number = self.wave ** 2

        def _spawn(fast):
            clock.schedule_once(lambda _: Enemy.spawn(fast), 1.5 + n * 0.25)

        for n in xrange(number):
            fast = n >= number + 2 - self.wave
            _spawn(fast)
Example #37
0
    def __display_fix(self):
        """
        Display the fixation point
        """
        # Tell the Render instance not attempt to render stimuli
        self.render_stimuli = False

        # Set current_img to the fixation point image
        self.current_img = self.render.fix_image

        # Set the shaders to not be used, bind the VBO using bind_message
        # and assign current_img as the texture
        self.__ready_texture(False, self.render.bind_message)

        # Ready the change over in state
        schedule_once(self.__next_state, FIX_DUR)
Example #38
0
def reset_game():
    global bvx, bvy

    point_label.text = 'Player: {0} Computer: {1}'.format(ppoints, cpoints)

    computer.x = window.width - 8
    computer.y = window.height / 2

    ball.x = window.width / 2
    ball.y = 0
    bvx = 0
    bvy = 0

    global ready_visible
    ready_visible = True
    clock.schedule_once(push_ball, 2)