在pygame中计算重力的最佳方法是什么?我基本上只需要它,所以当玩家按下“向上”时,角色就会跳起来。这是我目前为止的代码(只有一个白色屏幕和一个移动的红色块)import pygame
import random
# Define colors
black = ( 0, 0, 0)
white = ( 255, 255, 255)
green = ( 0, 255, 0)
red = ( 255, 0, 0)
#Classes
class Player(pygame.sprite.Sprite):
def __init__(self, color, width, height):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([width, height])
self.image.fill(color)
self.rect = self.image.get_rect()
def move(self, x_change, y_change):
self.rect.x += x_change
self.rect.y += y_change
#Lists
all_sprites_list = pygame.sprite.Group()
#Spawn player
player = Player(red,16,16)
all_sprites_list.add(player)
player.rect.x = 0
player.rect.y = 484