如何解决我怎样才能让这些粒子在 Pygame 中跳跃
我想知道如何让这些粒子跳跃而不是移动 x 和 y 速度 (https://gyazo.com/c8923ec5366a5c110b735ccccb555863)
我怎样才能让他们跳起来然后又回到原来的位置?
这是我到目前为止所写的内容。粒子只在 y 和 x 方向移动,它们看起来根本没有跳跃。
import pygame,random
pygame.init()
window = pygame.display.set_mode((500,500))
pygame.display.set_caption("Particle Test")
class player:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window,self.color,self.rect)
white = 255,105,200
player1 = player(250,200,50,white)
class particle3:
def __init__(self,y):
self.x = x
self.y = y
self.x_vel = random.randrange(-10,13)//5
self.y_vel = random.randrange(-10,-1)//5
self.lifetime = 0
def draw(self,window):
self.lifetime += 1
if self.lifetime <60:
self.x -= self.x_vel
self.y -= self.y_vel
pygame.draw.circle(window,(127,140,141),(self.x,self.y),10)
particles = []
def redraw():
window.fill((0,0))
for particle3 in particles:
particle3.draw(window)
player1.draw()
fps = 60
clock = pygame.time.Clock()
run = True
render = True
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if player1.y < 350:
player1.y += 5
else:
if render:
for x in range(20):
particles.append( particle3(player1.x,player1.y) )
render = False
player1.y = 50
if player1.y == 50:
render = True
redraw()
pygame.display.update()
pygame.quit()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。