本文整理汇总了Python中Character.Character.move方法的典型用法代码示例。如果您正苦于以下问题:Python Character.move方法的具体用法?Python Character.move怎么用?Python Character.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Character.Character
的用法示例。
在下文中一共展示了Character.move方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move
# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import move [as 别名]
def move(self,task):
"""Update the character for one frame.
Pick a new direction for the character to turn in every second.
Also see Character.move().
Arguments:
See Character.move().
Return:
See Character.move().
"""
if task.time - self.prevTurnTime >= 1:
import random
direction = random.randint(1,3)
if direction == 1:
self.setControl('left',1)
self.setControl('right',0)
elif direction == 2:
self.setControl('left',0)
self.setControl('right',1)
elif direction == 3:
self.setControl('left',0)
self.setControl('right',0)
self.prevTurnTime = task.time
return Character.move(self,task)
示例2: move
# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import move [as 别名]
def move (self, walls):
'''in - (self, list of walls)
Determines what direction to move in and moves pacman.'''
if self.moveUp and self.canMove (0, walls):
Character.move (self, 0)
if self.moveLeft and self.canMove (1, walls):
Character.move (self, 1)
if self.moveDown and self.canMove (2, walls):
Character.move (self, 2)
if self.moveRight and self.canMove (3, walls):
Character.move (self, 3)
示例3: exit
# 需要导入模块: from Character import Character [as 别名]
# 或者: from Character.Character import move [as 别名]
pygame.key.set_repeat(1, 50) # if a key is held down, continue sending KEYDOWN events
while True:
# handle event queue
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
exit()
elif event.type == pygame.KEYDOWN:
# move head
if event.key == pygame.K_w:
me.move(PLAYER_MOVEMENT_SPEED, me.direction_enum["UP"])
elif event.key == pygame.K_a:
me.move(PLAYER_MOVEMENT_SPEED, me.direction_enum["LEFT"])
elif event.key == pygame.K_d:
me.move(PLAYER_MOVEMENT_SPEED, me.direction_enum["RIGHT"])
elif event.key == pygame.K_s:
me.move(PLAYER_MOVEMENT_SPEED, me.direction_enum["DOWN"])
# rotate head
#torso_vector = (me.bodies[me.bodies_enum["HEAD"]].position - me.bodies[me.bodies_enum["TORSO"]].position)
#torso_rotate_angle = torso_vector.angle
#elif event.key == pygame.K_q:
# me.rotate(CHARACTER_ANGULAR_VELOCITY_LIMIT, "TORSO")
#elif event.key == pygame.K_e:
# me.rotate(-CHARACTER_ANGULAR_VELOCITY_LIMIT, "TORSO")