本文整理汇总了Python中snake.Snake.respawn方法的典型用法代码示例。如果您正苦于以下问题:Python Snake.respawn方法的具体用法?Python Snake.respawn怎么用?Python Snake.respawn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snake.Snake
的用法示例。
在下文中一共展示了Snake.respawn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PlayerBase
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import respawn [as 别名]
#.........这里部分代码省略.........
elif tag == PWRUP_TAG:
for action in obj.actions:
target = self.pwrup_targets[action['target']]
if '.' in target:
target1, target2 = target.split('.')
attr = getattr(getattr(self, target1), target2)
setattr(getattr(self, target1),
target2, attr + action['value'])
else:
attr = getattr(self, target)
setattr(self, target, attr + action['value'])
obj.collect()
elif tag == SHOT_TAG:
self.handle_shot(obj)
def coll_check_body(self, collobjs):
"""Handle collisions for the snakes's body."""
for tag, obj in collobjs:
if tag == SHOT_TAG:
self.handle_shot(obj)
def handle_shot(self, shot):
"""Handle shot."""
self.snake.take_damage(shot.damage, shot.tag, False, True, 1.2,
slowdown=shot.slowdown, shrink=1)
shot.hit()
def update(self, delta_time):
"""Update player, move snake."""
if not self.snake:
return
self.snake.update(delta_time)
self.weapons[0].update(delta_time)
if self.snake.heading != self.snake.prev_heading:
self.snake.ismoving = True
if self.boost < BOOST_COST * delta_time:
self.boosting = False
self.snake.speed_bonus = 0
if self.boosting:
boost = self.boost - BOOST_COST * delta_time
if boost < BOOST_COST * delta_time:
self.boost = 0
else:
self.boost = boost
else:
self.boost = self.boost + BOOST_GAIN * delta_time
def draw(self, offset):
"""Draw snake and UI."""
if not self.snake:
return
self.snake.draw()
gfx = self.game.graphics
gfx.draw_string(add_vecs((2, 2), offset),
'Player{0}'.format(self.pid), self.color)
gfx.draw_string(add_vecs((56, 2), offset),
'{0:.2f}'.format(self.snake.speed), WHITE)
gfx.draw_string(add_vecs((2, 18), offset),
'Points: {0}'.format(self.points), WHITE)
pygame.draw.rect(self.game.screen, ORANGE,
pygame.Rect(add_vecs((100, 2), offset),
(104, 20)))
# Draw life bar. TODO: Make this some kinda class.
width = int(self.snake.hitpoints / float(MAX_HITPOINTS) * 100)
rect = pygame.Rect(add_vecs((102, 4), offset), (width, 7))
pygame.draw.rect(self.game.screen, RED, rect)
if self.boost_enabled:
width = int(self.boost / float(MAX_BOOST) * 100)
rect = pygame.Rect(add_vecs((102, 13), offset), (width, 7))
pygame.draw.rect(self.game.screen, BLUE, rect)
gfx.draw_string(add_vecs((208, 2), offset),
'{0} {1}'.format(self.weapons[0].wtype,
self.weapons[0].ammo), WHITE)
for index in range(self.lifes):
gfx.draw('life16x16', add_vecs((100, 24), offset),
gridcoords=False, offset=(index*18, 0))
def snake_killed(self, killed_by):
"""Snake killed event handler."""
if self.lifes > 0:
self.lifes -= 1
self.boost = MAX_BOOST
self.snake.respawn(self.tilemap.get_spawnpoint())
else:
self.dead_handler()
示例2: PlayerBase
# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import respawn [as 别名]
#.........这里部分代码省略.........
elif value < 0:
self._boost = 0
else:
self._boost = value
def coll_check_head(self, collobjs):
"""Handle collisions for the snake's head."""
for tag, obj in collobjs:
if (tag.endswith('-body') or tag.endswith('-head')) and \
tag != self.snake.head_tag:
obj.take_damage(35, self.snake.head_tag, False, True,
0.7, shrink=1, slowdown=0.03)
elif tag == PORTAL_TAG:
self.snake.heading = obj[1]
self.snake[0] = add_vecs(obj[0], self.snake.heading)
elif tag == PWRUP_TAG:
for action in obj.actions:
target = self.pwrup_targets[action['target']]
if '.' in target:
target1, target2 = target.split('.')
attr = getattr(getattr(self, target1), target2)
setattr(getattr(self, target1),
target2, attr + action['value'])
else:
attr = getattr(self, target)
setattr(self, target, attr + action['value'])
obj.collect()
elif tag == SHOT_TAG:
self.handle_shot(obj)
def coll_check_body(self, collobjs):
"""Handle collisions for the snakes's body."""
for tag, obj in collobjs:
if tag == SHOT_TAG:
self.handle_shot(obj)
def handle_shot(self, shot):
"""Handle shot."""
self.snake.take_damage(shot.damage, shot.tag, False, True, 1.2,
slowdown=shot.slowdown, shrink=1)
shot.hit()
def update(self, delta_time):
"""Update player, move snake."""
self.snake.update(delta_time)
self.weapons[0].update(delta_time)
if self.snake.heading != self.snake.prev_heading:
self.snake.ismoving = True
if self.boost < BOOST_COST * delta_time:
self.boosting = False
self.snake.speed_bonus = 0
if self.boosting:
boost = self.boost - BOOST_COST * delta_time
if boost < BOOST_COST * delta_time:
self.boost = 0
else:
self.boost = boost
else:
self.boost = self.boost + BOOST_GAIN * delta_time
def draw(self, offset):
"""Draw snake and UI."""
self.snake.draw()
self.game.draw_string('Player{0}'.format(self.pid),
add_vecs((2, 2), offset), self.color)
self.game.draw_string('{0:.2f}'.format(self.snake.speed),
add_vecs((56, 2), offset), WHITE)
self.game.draw_string('Points: {0}'.format(self.points),
add_vecs((2, 18), offset), WHITE)
pygame.draw.rect(self.game.screen, ORANGE,
pygame.Rect(add_vecs((100, 2), offset), (104, 20)))
pygame.draw.rect(self.game.screen, RED,
pygame.Rect(add_vecs((102, 4), offset), (int(
self.snake.hitpoints /
float(MAX_HITPOINTS) * 100), 7)))
pygame.draw.rect(self.game.screen, BLUE,
pygame.Rect(add_vecs((102, 13), offset), (int(
self.boost / float(MAX_BOOST) * 100), 7)))
self.game.draw_string('{0} {1}'.format(self.weapons[0].wtype,
self.weapons[0].ammo),
add_vecs((208, 2), offset), WHITE)
for i in range(self.lifes):
self.game.graphics.draw('life16x16', add_vecs((100, 24), offset),
gridcoords=False, offset=(i*18, 0))
def snake_killed(self, killed_by):
"""Snake killed event handler."""
if self.lifes > 0:
self.lifes -= 1
self.boost = MAX_BOOST
self.snake.respawn(self.game.get_spawnpoint())