所以,我一直在尝试根据本教程在 pygame 中实现水物理
问题是,当我在 pygame 中实现这段代码时,水决定它不会产生很好的涟漪效应,而是会发疯并在整个屏幕上摆动,直到最终崩溃。
我环顾了一些不和谐的服务器,发现其他人试图实现同样的事情,并遇到了同样的问题。他们的代码基本上和我的一样,只是组织得更整齐,所以我会发布它而不是我的。
import pygame, random
import math as m
from pygame import *
pygame.init()
WINDOW_SIZE = (854, 480)
screen = pygame.display.set_mode(WINDOW_SIZE,0,32) # initiate the window
clock = pygame.time.Clock()
font = pygame.font.SysFont("Arial", 18)
class surface_water_particle():
def __init__(self, x,y):
self.x_pos = x
self.y_pos = y
self.target_y = y
self.velocity = 0
self.k = 0.02
self.d = 0.02
self.time = 1
def update(self):
x = -(self.target_y - self.y_pos)
a = -(self.k * x - self.d * self.velocity) …Run Code Online (Sandbox Code Playgroud)