本文整理汇总了Python中ai.AI.move方法的典型用法代码示例。如果您正苦于以下问题:Python AI.move方法的具体用法?Python AI.move怎么用?Python AI.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ai.AI
的用法示例。
在下文中一共展示了AI.move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import move [as 别名]
class Ship:
def __init__(self, screen):
self.hp = 100
self.ai = 1
self.ai_object = AI(screen, self)
self.x = 0
self.y = 0
self.xvel = 0
self.yvel = 0
self.pic = 0
self.screen = screen
self.fire_rate = 0
screen.add_ship(self)
def set_pic(self, number):
self.pic = number
def set_player(self):
self.ai = 0
def render(self):
self.screen.fast_display(self.x, self.y, self.pic)
def update(self):
self.x += self.xvel
self.y += self.yvel
if self.ai >= 0:
self.ai_object.move(self.ai)
if self.y > self.screen.max_y:
self.screen.explosion(self.x, self.y)
def damage(self, value):
self.hp -= value
if self.hp < 0:
self.screen.remove_ship(self)
self.screen.explosion(self.x, self.y)
def fire(self, rate, target=None):
if self.fire_rate > 0:
self.fire_rate -= 1
return
self.fire_rate = rate
shot = Shot(self.screen, self.x, self.y + 40, self, target)
player = self.screen.player
dx = player.x - self.x
dy = player.y - self.y - 15
total = sqrt(dx ** 2 + dy ** 2)
shot.xvel = dx / total * 15
shot.yvel = dy / total * 15
shot.range = 100