本文整理汇总了Python中ai.AI.hitwall方法的典型用法代码示例。如果您正苦于以下问题:Python AI.hitwall方法的具体用法?Python AI.hitwall怎么用?Python AI.hitwall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ai.AI
的用法示例。
在下文中一共展示了AI.hitwall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Creature
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import hitwall [as 别名]
#.........这里部分代码省略.........
self.reload_time = time() - 10
self.reload_wait = .75 #This gets tampered with elsewhere
self.AI = AI()
def _turn(self, direction, reset_velocity = True):
""" Private method that turns the Creature in the given direction. This
is accomplished by setting the x velocity and flipping the Creature's image
so that is is oriented in the the direction of travel"""
if reset_velocity:
self.velocity.x = self.default_velocity.x * (-1 if direction == "left" else 1)
if self.motion != direction:
self.image = pygame.transform.flip(self.image, True, False)
self.motion = direction
def turn_around(self):
if self.motion == "left":
self._turn("right")
else:
self._turn("left")
def go_left(self):
""" Sets the Creature's velocity to its default speed in the left direction,
and flips the image such that is is facing left"""
self._turn("left")
def go_right(self):
""" Sets the Creature's velocity to its default speed in the left direction,
and flips the image such that is is facing left"""
self._turn("right")
def stand_still(self):
""" Stops horizontal movement"""
self.velocity.x = 0
def jump(self):
""" Performs the voodoo required to make the Creature jump. If the Creature
is already jumping, there will be *no* double-jumps"""
if self.jumping or not self.landed:
return
else:
self.landed = False
self.jumping = True
self.velocity.y = self.jump_amount
def make_contact(self):
"""To be called when the Creature first hits the ground."""
self.position.bottom = rect.bottom
self.velocity.y = 0
self.jumping = False
def take_a_hit(self, damage = 1):
self.health -= damage
if self.health <= 0:
self.dead = True
def right_p(self):
return True if self.velocity.x > 0 else False
def left_p(self):
return True if self.velocity.x < 0 else False
def up_p(self):
return True if self.velocity.y < 0 else False
def down_p(self):
return True if self.velocity.y > 0 else False
def fire(self, projectiles, image, speed, direction, offset=0):
"""Shoots, using the given image, speed, and direction, and adding the
projectile to the given group."""
time_ = time()
if (self.reload_time + self.reload_wait) < time_:
if self.motion == "left":
pos = self.position.topleft
sign = -1
else:
pos = self.position.topright
sign = 1
pos = (pos[0], pos[1] + offset)
proj = Projectile(pos, speed * sign, image, direction)
projectiles.add(proj)
self.reload_time = time_
return True
return False
def hitwall(self):
"""To be called when the Creature hits a wall."""
self.AI.hitwall(self)
def __str__(self):
return """
%s
Position: %s, %s
Height: %s
Width: %s
Relative Position: %s, %s
Velocity: %s, %s
"""%(type(self).__name__, self.position.left, self.position.top, self.rect.height, self.rect.width, self.rect.left, self.rect.top, self.velocity.x, self.velocity.y)