当前位置: 首页>>代码示例>>Python>>正文


Python Animation.update方法代码示例

本文整理汇总了Python中animation.Animation.update方法的典型用法代码示例。如果您正苦于以下问题:Python Animation.update方法的具体用法?Python Animation.update怎么用?Python Animation.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在animation.Animation的用法示例。


在下文中一共展示了Animation.update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Powerup

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]
class Powerup(object):
    def __init__(self, i, j):
        global powerups
        init_powerups()
        self.i = i
        self.j = j
        self.timer = globals.pw_timer
        self.powerup = choice(powerups)
        index = powerups.index(self.powerup)
        player = globals.squares[i][j].owner.player_number-1
        self.animation = Animation(globals.pw_images[index][player])

    def update(self):
        self.timer -= globals.clock.get_time()
        if self.timer < 0:
            globals.powerups.remove(self)

        self.animation.update()

    def pickup(self, player):
        self.powerup(player)
        globals.powerups.remove(self)

    def render(self):
        self.animation.render(
            self.i * globals.square_size,
            self.j * globals.square_size,
        )
开发者ID:joaodelgado,项目名称:bomber,代码行数:30,代码来源:powerup.py

示例2: Bomb

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]
class Bomb(object):
    def __init__(self, i, j, player):
        self.i = i
        self.j = j
        self.player = player
        self.timer = globals.b_timer
        self.animation = Animation(globals.b_images[player.player_number-1])

    def update(self):
        self.timer -= globals.clock.get_time()
        if self.timer < 0:
            self.explode()
        self.animation.update()

    def explode(self):
        self.remove()

        # rewrite for loops
        for i in range(
                max(0,
                    int(self.i - self.player.bomb_radious)),
                min(globals.squares_per_line,
                    int(self.i+1 + self.player.bomb_radious))):
            for j in range(
                    max(0,
                        int(self.j - self.player.bomb_radious)),
                    min(globals.squares_per_line,
                        int(self.j+1 + self.player.bomb_radious))):
                center = (self.i, self.j)
                square = (i, j)

                if utils.distance(center, square) <= self.player.bomb_radious:

                    # delete powerup in that square, if any
                    for powerup in globals.powerups:
                        if powerup.i == square[0] and \
                           powerup.j == square[1]:
                            globals.powerups.remove(powerup)
                            break

                    # delete bomb in that square, if any
                    for bomb in globals.bombs:
                        if bomb.i == square[0] and \
                           bomb.j == square[1]:
                            bomb.remove()
                            break

                    if globals.squares[i][j].owner != self.player:
                        globals.squares[i][j].change_owner(self.player)
                    globals.explosions.append(Explosion(i, j))

    def remove(self):
        globals.bombs.remove(self)
        self.player.current_bombs -= 1

    def render(self):
        self.animation.render(
            self.i * globals.square_size,
            self.j * globals.square_size,
        )
开发者ID:joaodelgado,项目名称:bomber,代码行数:62,代码来源:bomb.py

示例3: __init__

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]
class Character:

  def __init__(self, screen_w, screen_h, unit):
    self.unit = unit
    self.create_animations()
    image_rect = self.animation.get_current_frame().image.get_rect()
    self.center = image_rect.width/2
    self.position = [(screen_w - image_rect.width)/2, screen_h - image_rect.height]
    size_reduction = 10*unit
    self.collision_rect = pygame.Rect(image_rect.left + size_reduction, 
      image_rect.top + size_reduction,
      image_rect.width - 2*size_reduction, 
      image_rect.height - 4*size_reduction)
    self.screen_w = screen_w
    self.direction = [0, 0]
    
  def create_animations(self):
    image = pygame.image.load("assets/character.png")
    
    # create the frames for the "walking left" animation
    frames = [
      Frame(image = image, position = [0, 4*self.unit], duration = 4),
      Frame(image = image, position = [0, 0],           duration = 4),
    ]

    # and with that create the "walking left" animation
    self.animation = Animation(frames)
    
  def input(self, event):
    if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_LEFT:
        self.direction[0] = -1
      elif event.key == pygame.K_RIGHT:
        self.direction[0] = 1
    if event.type == pygame.KEYUP:
      if (event.key == pygame.K_LEFT and self.direction[0] == -1) or\
        (event.key == pygame.K_RIGHT and self.direction[0] == 1):
        self.direction[0] = 0
  
  def update(self):
    if self.direction[0] != 0:
      self.animation.update()
    self.position[0] = (self.position[0] + self.direction[0]*8*self.unit + self.center)\
      %self.screen_w - self.center
  
  def draw(self, on_surface):
    self.animation.draw(on_surface, self.position)
   
  def collides_with(self, other):
    return self.get_absolute_rect().colliderect(other.get_absolute_rect())
  
  def get_absolute_rect(self):
    return self.collision_rect.move(self.position)
开发者ID:codelurker,项目名称:pygame-tutorial,代码行数:55,代码来源:character.py

示例4: Game

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]
class Game(object):

    def __init__(self):

        pygame.init()

        self.screen = pygame.display.set_mode(
            (SCREEN_WIDTH, SCREEN_HEIGHT), 0, 32)
        self.clock = pygame.time.Clock()

        # Game states
        self.paused = 0
        self.game_over = 0
        self.running = 1
        self.keep_drawing_ship = 1

        # Game objects
        self.ship = ship.Ship(
            self.screen, (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))
        self.asteroids = []
        self.bullets = []

        # Scoreboard
        self.score = 0
        self.scoreboard = Scoreboard(self.screen)

        # Bullet Gauge
        self.bullet_gauge = BulletGauge(self.screen, 10, self.spawn_bullet)

        # Health bar
        self.health_bar = Bar(self.screen, self.ship.max_health,
                              [30, SCREEN_HEIGHT - 20,
                               80, 10],
                              RED, WHITE)
        # Game Over Text
        self.game_over_text = GameOverText(self.screen)
        self.reduce_game_over_text_alpha = Timer(
            100, self.game_over_text.reduce_alpha)

        # Asteroid spawning
        self.since_last_asteroid = 0
        self.new_asteroid_time = 1000

        # Levels
        self.level_gen = generate_levels()
        self.level = 1
        self.level_limit = next(self.level_gen)

        self.level_text = LevelText(self.screen)

    def run(self):

        while self.running:

            time_passed = self.clock.tick(60)

            # KEYBOARD INPUT
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.running = 0
                    break

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        self.running = 0
                        break
                    if event.key == pygame.K_SPACE:
                        if not self.paused and not self.game_over:
                            self.bullet_gauge.shoot()

                    if event.key == pygame.K_p:
                        self.paused = not self.paused

            if not self.paused and not self.game_over:
                self.update(time_passed)

            if self.game_over:
                self.update_game_over_sequence(time_passed)

            self.draw()

    def update(self, time_passed):
        # Send keyboard input
        self.ship.handleKeyevents(pygame.key.get_pressed())

        # Object updates
        self.ship.update(time_passed)

        for bullet in self.bullets:
            bullet.update(time_passed)

        for asteroid in self.asteroids:
            asteroid.update(time_passed, self.ship.pos)

        # Maintenance functions
        self.ship.keep_in_bounds()
        self.maintain_bullets()
        self.maintain_asteroids()

        # Collisions
#.........这里部分代码省略.........
开发者ID:fifiman,项目名称:Asteroid-Shooter,代码行数:103,代码来源:game.py

示例5: __init__

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]

#.........这里部分代码省略.........
            Non-permitted collisions such as 
            player and collideables or enemies and 
            collideables will be handle by player
            and enemy classes respectively.

            This is to minimize collision checks,
            for instance, if the player was not colliding with 
            a wall before they moved and the player still hasn't 
            moved, then there is no need to check if the player 
            has collided with the wall again. "Look-ahead" 
            collision should be implemented in the classes of the
            moving game objects, and checked only before the object
            moves for this very purpose.
        """

        # player collisions
        for p in self.players:
            sprs = pygame.sprite.spritecollide(p, self.items, False)
            for s in sprs:
                p.collide(s)

            enemies = pygame.sprite.spritecollide(p, self.enemies, False)
            for e in enemies:
                p.collide(e)

        # enemy collisions
        for e in self.enemies:
            sprs = pygame.sprite.spritecollide(p, self.items, False)
            for s in sprs:
                p.collide(s)

    def __blit_spr__(self, spr, surf):
        """
            Blit a sprite to the screen surface
            with consideration to the world's
            focus. If there is a focus, everything
            will be blitted in relation to the focus
            rect
        """
        frect = self.focus
        pos = spr.get_position()
        if frect: 
            if self.hz_focus:
                fx = self.screen_size[0]//2 - frect.width //2
                dx = frect.x - pos[0]
                pos[0] = fx - dx + self.focus_offsetx
            if self.vt_focus:
                fy = self.screen_size[1]//2 - frect.height//2
                dy = frect.y - pos[1]
                pos[1] = fy - dy + self.focus_offsety
        else:
            pos[0] += self.focus_offsetx
            pos[1] += self.focus_offsety
        surf.blit(spr.image, pos)

    def __shake__(self):
        n = SHAKE_PADDING//2
        self.x = random.randint(-n, n)
        self.y = random.randint(-n, n)

    def update(self, dt, surf): 
        """
            Update, and everything to screen in correct order
            bg, noncollideables, collideables, enemies, player, items
            and according to the correct focus
        """
        if self.ani:
            if self.ani.targets:
                self.ani.update(dt)
            else:
                self.ani = None
                self.focus = self.target_focus
                print("Focus: %s" % self.focus)
        self.__handle_collisions__()
        if self.shake:
            self.__shake__()
        wsurf = self.world_surf
        wsurf.fill((0,0,0))
        bg = self.background
        if self.focus:
            x = self.screen_size[0]//2 - self.focus.x - self.focus.width//2
            y = 0
            wsurf.blit(bg, [x,y])
        else:
            wsurf.blit(bg, [0,0])
        # if bg:
        for spr in self.all_objects:
            spr.update(dt)

        for spr in self.noncollideables:
            self.__blit_spr__(spr, wsurf)
        for spr in self.collideables:
            self.__blit_spr__(spr, wsurf)
        for spr in self.enemies:
            self.__blit_spr__(spr, wsurf)
        for spr in self.players:
            self.__blit_spr__(spr, wsurf)
        for spr in self.items:
            self.__blit_spr__(spr, wsurf)
        surf.blit(wsurf, [self.x, self.y])
开发者ID:emelent,项目名称:pistol,代码行数:104,代码来源:world.py

示例6: Wizderp

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]
class Wizderp(pygame.sprite.Sprite):


 def __init__(self, screen):
		pygame.sprite.Sprite.__init__(self)
		
		self.left_w = Animation( [pygame.image.load('../images/wiz_left_still.png'),
								  pygame.image.load('../images/wiz_left_walk1.png'),
								  pygame.image.load('../images/wiz_left_walk2.png')] )

		self.right_w = Animation( [pygame.image.load('../images/wiz_right_still.png'),
								   pygame.image.load('../images/wiz_right_walk1.png'),
								   pygame.image.load('../images/wiz_right_walk2.png')] )

		self.down_w = Animation( [pygame.image.load('../images/wiz_front_still.png'),
								  pygame.image.load('../images/wiz_front_walk1.png'),
								  pygame.image.load('../images/wiz_front_walk2.png')] )

		self.up_w = Animation( [pygame.image.load('../images/wiz_back_still.png'),
								pygame.image.load('../images/wiz_back_walk1.png'),
								pygame.image.load('../images/wiz_back_walk2.png')] )
								
		self.tele1 = pygame.image.load('../images/wiztele1.png')
		self.tele2 = pygame.image.load('../images/wiztele2.png')
		self.tele3 = pygame.image.load('../images/wiztele3.png')
		self.tele4 = pygame.image.load('../images/wiztele4.png')
		self.tele5 = pygame.image.load('../images/wiztele5.png')

		self.image = self.left_w.update()
		self.walking_timer = 0
		self.rect = self.image.get_rect()
		self.rect.topleft = 50, 80
		
		self.attack_group = pygame.sprite.RenderPlain()
		self.attack_timer = 2
		self.screen = screen
		
		
		self.immortal_timer = 2
		self.health = 5
		self.tele_spots = [(100, 50), (300, 100), (400, 200), (500, 50)]
		self.tele_loc = 0
		
		self.decided = False
		self.will_fight = True
		self.tele_done = True
		self.tele_tick = 1
		self.tele_wait = 0
		

 def update(self, player, rocks):
 	
 	if self.decided and self.tele_done:
		self.direction =  direction = helpers.checkOrient(player, self)
		if self.attack_timer <= 0:
			self.__loadShot(player)
			self.attack_timer = 130
		elif self.attack_timer <15:
			self.attack_timer -=1
			self.image = self.tele1
		else:
			self.__move(player)
			self.attack_timer -=1
		if self.immortal_timer > 0:
			self.immortal_timer -=1
			self.attack_timer -= 1
 	elif self.decided and (not self.tele_done):
 		self.__teleport()
 	
 	elif (not self.decided) and (helpers.distance(player.rect.topleft, self.rect.topleft) < 12):
 		self.__decide()
 	
 	self.attack_group.update(player, rocks)
 	self.attack_group.draw(self.screen)
 	hit_player = pygame.sprite.spritecollide(player, self.attack_group, False)
 	if hit_player:
 		player.getHit("none", 1)
 		hit_player[0].kill()
 	
 	
 def __loadShot(self, player):
 	self.immortal_timer = 2
	attack = Fire_Attack((self.rect.center[0], self.rect.center[1]), player.rect.center, helpers.checkOrient(player, self))
	self.attack_group.add(attack)


 def __decide(self):
 	self.dialogHandle = HandleDialog(self.screen, DialogBox((440, 51), 
 		(255, 255, 204),(102, 0, 0), pygame.font.SysFont('Verdana', 15)))
 	self.will_fight = self.dialogHandle.wizardChoice(self.screen)
 	self.decided = True


 def __move(self, player):
 	if self.walking_timer <= 0:
 		self.__walk()
 		self.walking_timer = 5
 	else:
 		self.walking_timer -= 1
 	
#.........这里部分代码省略.........
开发者ID:Broccooli,项目名称:RockGame,代码行数:103,代码来源:wizderp.py

示例7: Player

# 需要导入模块: from animation import Animation [as 别名]
# 或者: from animation.Animation import update [as 别名]
class Player(pygame.sprite.Sprite):





    def __init__(self, position, screen):

        pygame.sprite.Sprite.__init__(self)



        self.left_w = Animation( [pygame.image.load('../images/hero_left_still.png'),

                                  pygame.image.load('../images/hero_left_walk1.png'),

                                  pygame.image.load('../images/hero_left_walk2.png')] )



        self.right_w = Animation( [pygame.image.load('../images/hero_right_still.png'),

                                   pygame.image.load('../images/hero_right_walk1.png'),

                                   pygame.image.load('../images/hero_right_walk2.png')] )



        self.down_w = Animation( [pygame.image.load('../images/hero_front_still.png'),

                                  pygame.image.load('../images/hero_front_walk1.png'),

                                  pygame.image.load('../images/hero_front_walk2.png')] )



        self.up_w = Animation( [pygame.image.load('../images/hero_back_still.png'),

                                pygame.image.load('../images/hero_back_walk1.png'),

                                pygame.image.load('../images/hero_back_walk2.png')] )



        self.image = self.left_w.update()



        # -------- Player positioning --------

        self.rect = self.image.get_rect()

        self.position = position

        self.rect.topleft = position[0], position[1]



        # -------- Player states --------

        self.alive = True

        self.has_belt = False

        self.has_gaunt = False

        self.attacking = False

        self.hasFriend = False

        self.aiming = False



        # -------- Attack --------

        self.attack = Attack()



        # -------- Timers --------

        self.clock = 0

        self.push_timer = 0 #slows rocks down



        # -------- Player attributes --------

        self.direction = "left"

        self.health = 500

        self.invul = 0 #typical invulnerable period

        self.old_position = position



#.........这里部分代码省略.........
开发者ID:Broccooli,项目名称:RockGame,代码行数:103,代码来源:player.py


注:本文中的animation.Animation.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。