小编Eve*_*lyn的帖子

Pygame 水物理无法按预期工作

所以,我一直在尝试根据本教程在 pygame 中实现水物理

https://gamedevelopment.tutsplus.com/tutorials/make-a-splash-with-dynamic-2d-water-effects--gamedev-236

问题是,当我在 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)

pygame physics python-3.x pygame-surface

5
推荐指数
1
解决办法
282
查看次数

标签 统计

physics ×1

pygame ×1

pygame-surface ×1

python-3.x ×1