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


Python Square.velocity方法代码示例

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


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

示例1: Square

# 需要导入模块: from square import Square [as 别名]
# 或者: from square.Square import velocity [as 别名]
import pygame
from vector import Vector
from square import Square
import random

pygame.init()

screen = pygame.display.set_mode((700, 500))
pygame.display.set_caption("Studsaren")

square = Square(screen, random.randint(0, screen.get_size()[0] - 50), random.randint(0, screen.get_size()[1] - 50), 50, 50)
square.velocity = 200 * Vector(random.uniform(-10, 10), random.uniform(-10, 10)).normalized()

clock = pygame.time.Clock()
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    t = clock.get_time() / 1000

    width, height = screen.get_size()
    if square.pos.x <= 0 or square.pos.x >= width - square.w:
        square.velocity = Vector(-square.velocity.x, square.velocity.y)
    if square.pos.y <= 0 or square.pos.y >= height - square.h:
        square.velocity = Vector(square.velocity.x, -square.velocity.y)
    square.update(t)

    screen.fill((0, 0, 0))
开发者ID:gkraften,项目名称:Programmering-1,代码行数:32,代码来源:studsaren.py

示例2: Square

# 需要导入模块: from square import Square [as 别名]
# 或者: from square.Square import velocity [as 别名]
pygame.init()

screen = pygame.display.set_mode((700, 500))
pygame.display.set_caption("Gravitation")

square = Square(screen, 325, 0, 50, 50)
square.acceleration = Vector(0, 200)

clock = pygame.time.Clock()
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

    t = clock.get_time() / 1000

    if square.pos.y >= screen.get_size()[1] - 50:
        square.pos = Vector(325, screen.get_size()[1] - 50)
        square.velocity = -square.velocity/1.2
        if abs(square.velocity) <= 10:
            square.velocity = Vector(0, 0)
            square.acceleration = Vector(0, 0)
    square.update(t)

    screen.fill((0, 0, 0))

    square.draw()

    pygame.display.flip()
    clock.tick(60)
开发者ID:gkraften,项目名称:Programmering-1,代码行数:33,代码来源:gravitation.py


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