当前位置: 首页>>代码示例>>Python>>正文


Python Vector.as_point方法代码示例

本文整理汇总了Python中Vector.Vector.as_point方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.as_point方法的具体用法?Python Vector.as_point怎么用?Python Vector.as_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector.Vector的用法示例。


在下文中一共展示了Vector.as_point方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import as_point [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())
开发者ID:Furaeva,项目名称:SpaceShip,代码行数:41,代码来源:Game_Objects.py

示例2: __init__

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import as_point [as 别名]
class Snow:
    def __init__(self, pos, wind_power=50):
        self.image = helpers.load_image('Bez_imeni.png', 1, IMAGE_PATH)
        self.pos = Vector(pos)
        self.speed = Vector((0, 5))
        self.transform()
        # self.angle = 6
        self.snow_list = []
        self.status = MOVE_DOWN
        wind1 = StrongWind(0.01, 0, 1, 0)
        wind2 = ConstantWind(-1*wind_power/1000, 0, random.randint(2000, 3000), 7000)
        self.winds = [wind1, wind2]
        w, h = 20, 20
        self.area = pygame.Rect(0, 0, w, h)

    def draw_rect(self, screen):
        self.area.center = self.pos.as_point()
        pygame.draw.rect(screen, (0, 200, 0), self.area, 2)

    def update(self, dt):

        if self.pos.x > PLATFORM[0]:
            self.pos.x = 0
        if self.pos.x < 0:
            self.pos.x = PLATFORM[0]
        elif self.pos.y > PLATFORM[1]:
            # print("recreate --> ", self.check_area_list(self.snow_list))
            self.pos.y = random.randint(-100, -50)
            self.pos.x = random.randint(0, PLATFORM[0])
            self.speed = Vector((0, random.randint(4, 5)))  # меняем скорость при пересоздании
            # проверка списка с пересечениями при пересоздании
            while len(self.check_area_list(self.snow_list)) >= 2:
                self.pos.y = random.randint(-100, -50)
                self.pos.x = random.randint(0, PLATFORM[0])
                self.speed = Vector((0, random.randint(3, 5)))  # меняем скорость при пересоздании
        self.move()
        self.speed += self.winds[0].dir + self.winds[1].dir

    def check_area_list(self, obj_list):
        obj_list = [obj.area.move(obj.pos.as_point()) for obj in obj_list if
                    not obj is self]  # создается список с пересекаемыми объектами
        area = self.area.move(self.pos.as_point())
        return area.collidelistall(obj_list)

    def move(self):
        if self.status == MOVE_DOWN:
            self.pos += self.speed

    def render(self, screen):
        if MODE == 'debug':  # отладочный материал
            # ресуем  вектор скорости
            # ВЕКТОР
            dv = Vector((self.image.get_rect().w / 2, self.image.get_rect().h / 2))
            p1 = self.pos.as_point()
            p2 = (self.pos + self.speed * 10).as_point()
            pygame.draw.line(screen, (100, 200, 200), p1, p2)

        self.rect = self.image.get_rect()  # создаем прямоугольник вокруг объекта
        self.rect.center = self.pos.as_point()  # центрируем в нем объект
        # ПРЯМОУГОЛЬНИК
        if MODE == 'debug':  # отладочный материал
            pygame.draw.rect(screen, (100, 0, 100), self.rect, 1)
        screen.blit(self.image, self.rect)

    def transform(self):
        self.image = pygame.transform.scale(self.image, (15, 15))
开发者ID:kotland,项目名称:Snow,代码行数:68,代码来源:Snow.py

示例3: __init__

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import as_point [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())
开发者ID:Furaeva,项目名称:SpaceShip,代码行数:72,代码来源:SpaceShip.py


注:本文中的Vector.Vector.as_point方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。