本文整理汇总了Python中Vector.Vector.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.rotate方法的具体用法?Python Vector.rotate怎么用?Python Vector.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.rotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import rotate [as 别名]
class Game_Object:
def __init__(self, coords=(0, 0), speed=(0, 0)):
self.coords = Vector(coords)
self.speed = Vector(speed)
self.color = (250, 0, 0)
self.acsel = Vector((0, 0))
self.status = MOVE
self.angle_speed = 0.1
def event(self, event):
"""
Обработка событий объектом
"""
if event.type == KEYDOWN:
if event.key == K_LEFT:
self.status = TURN_LEFT
elif event.key == K_RIGHT:
self.status = TURN_RIGHT
elif event.type == KEYUP:
if event.key == K_LEFT:
self.status = MOVE
elif event.key == K_RIGHT:
self.status = MOVE
def move(self):
self.coords += self.speed
def update(self):
"""
Обновление состояния объкта (вызывается каждый кадр)
"""
if self.status == TURN_LEFT:
self.speed.rotate(self.angle_speed)
elif self.status == TURN_RIGHT:
self.speed.rotate(-self.angle_speed)
self.move()
def render(self, screen):
pygame.draw.line(screen, self.color, (self.coords.as_point()), (self.coords + self.speed).as_point())
示例2: __init__
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import rotate [as 别名]
class SpaceShip:
def __init__(self, coords):
self.coords = Vector(coords)
self.image = pygame.Surface((50, 40), pygame.SRCALPHA)
self.speed = Vector((10, 0))
self.boost = 1
self.direction = self.speed
self.state = NORMAL
self.draw()
def events(self, event):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.state = TURN_LEFT
if event.key == pygame.K_RIGHT:
self.state = TURN_RIGHT
if event.key == pygame.K_UP:
self.state = SPEED_UP
if event.key == pygame.K_DOWN:
self.state = SPEED_DOWN
if event.type == pygame.KEYUP:
self.state = NORMAL
def update(self, delta_time):
# Анализ состояния корабля
if self.state == TURN_LEFT:
self.speed.rotate(-ROTATION_ANGLE * (delta_time / 1000))
if self.speed.len != 0:
self.direction = self.speed
if self.state == TURN_RIGHT:
self.speed.rotate(ROTATION_ANGLE * (delta_time / 1000))
if self.speed.len != 0:
self.direction = self.speed
if self.state == SPEED_UP:
if self.speed.len != 0:
self.direction = self.speed
self.speed += self.speed.normalize() * self.boost
else:
self.speed = self.direction
if self.state == SPEED_DOWN:
if self.speed.len != 0:
self.direction = self.speed
self.speed -= self.speed.normalize() * self.boost
if self.speed.len < self.boost:
self.speed = Vector((0, 0))
# Пересечение экрана
if self.coords.x > RES_X:
self.coords.x = -50
if self.coords.y > RES_Y:
self.coords.y = -50
if self.coords.x < -50:
self.coords.x = RES_X
if self.coords.y < -50:
self.coords.y = RES_Y
self.coords += self.speed * (delta_time / 1000)
def draw(self):
pygame.draw.circle(self.image, (200, 0, 0), (20, 20), 20)
pygame.draw.circle(self.image, (200, 150, 0), (40, 20), 10)
# pygame.draw.rect(self.image, (0, 200, 0), self.image.get_rect(), 1)
def render(self, screen):
rotate_image = pygame.transform.rotate(self.image, self.direction.angle)
rect = rotate_image.get_rect(center=self.image.get_rect().center)
rect.move_ip(self.coords.as_point())
screen.blit(rotate_image, rect)
dv = Vector(self.image.get_rect().center)
pygame.draw.line(screen, (0, 255, 0), (self.coords + dv).as_point(), (self.coords + self.speed + dv).as_point())