0

我正在使用这些游戏的通常物理规则制作一个类似落沙的游戏。

它适用于我从文件加载关卡的事实。

因此,要检查一个地方是否为空,它会检查已RGB加载级别的值。

但由于某种原因,它返回几乎每个单元格(除了相同的几个单元格)都被某些东西占用,即使它不是。

物理是通过最初加载文件来处理的,然后对其进行修改。

文件类型为PNG格式,BufferedImage类型为TYPE_INT_ARGB

这是主类中的所有物理处理代码。

public static void updateParticles()
    {
    for(int i=0;i<100;i++)
        {
        for(int j=0;j<75;j++)
        {
        int rgb = levels.getRGB(i,j);
        int sx = getMappedCoordX(levels.getRGB(i,j));
        int sy = getMappedCoordY(levels.getRGB(i,j));
        try{
            if(materialRGBmap[(i*32)+j]==solRGB)
                {
                int[] coords = physicsRules.getSolidMovableStatic(getFree(i,j+1),getFree(i-1,j),getFree(i+1,j),getFree(i-1,j+1),getFree(i+1,j+1),i*8,j*8);
                levels.setRGB(i,j,map_null.getRGB(0,0));
                levels.setRGB(coords[0]/8,coords[1]/8,rgb);
                }
            if(materialRGBmap[(i*32)+j]==liqRGB)
                {
                int[] coords = physicsRules.getLiquidMovableStatic(getFree(i,j+1),getFree(i-1,j),getFree(i+1,j),i*8,j*8);
                levels.setRGB(i,j,map_null.getRGB(0,0));
                levels.setRGB(coords[0]/8,coords[1]/8,rgb);
                }
            if(materialRGBmap[(i*32)+j]==gasRGB)
                {
                int[] coords = physicsRules.getGasMovableStatic(getFree(i,j+1),getFree(i-1,j),getFree(i+1,j),getFree(i+1,j),i*8,j*8);
                levels.setRGB(i,j,map_null.getRGB(0,0));
                levels.setRGB(coords[0]/8,coords[1]/8,rgb);
                }
            }catch(Exception e){
                System.out.println("lolcat error");
                }
            }
        }
    }

这是PhysicsRules. (如上图所示physicsRules

public int[] getLiquidMovable(boolean onGround, boolean leftFree, boolean rightFree, int x, int y)
{
return onGround?(rand.nextInt(2)==0 && leftFree?new int[]{x-8, y}:(rightFree?new int[]{x+8,y}:new int[]{x,y})):new int[]{x,y+8};
}

public static int[] getLiquidMovableStatic(boolean onGround, boolean leftFree, boolean rightFree, int x, int y)
{
return onGround?(Srand.nextInt(2)==0 && leftFree?new int[]{x-8, y}:(rightFree?new int[]{x+8,y}:new int[]{x,y})):new int[]{x,y+8};
}

public int[] getSolidMovable(boolean onGround, boolean leftFree, boolean rightFree, boolean leftUFree, boolean rightUFree, int x, int y)
{
return onGround?(rand.nextInt(2)==0 && leftFree && leftUFree?new int[]{x-8, y}:(rightFree && rightUFree?new int[]{x+8,y}:new int[]{x,y})):new int[]{x,y+8};
}

public int[] getSolidMovableStatic(boolean onGround, boolean leftFree, boolean rightFree, boolean leftUFree, boolean rightUFree, int x, int y)
{
return onGround?(Srand.nextInt(2)==0 && leftFree && leftUFree?new int[]{x-8, y}:(rightFree && rightUFree?new int[]{x+8,y}:new int[]{x,y})):new int[]{x,y+8};
}

public int[] getGasMovable(boolean leftFree, boolean rightFree, boolean upFree, boolean downFree, int x, int y)
{
int dir = rand.nextInt(4);
return dir==0 && upFree?new int[]{x,y-8}:(dir==1 && leftFree?new int[]{x+8,y}:(dir==2 && downFree?new int[]{x,y+8}:(dir==3 && rightFree?new int[]{x-8,y}:new int[]{x,y})));
}

public static int[] getGasMovableStatic(boolean leftFree, boolean rightFree, boolean upFree, boolean downFree, int x, int y)
{
int dir = Srand.nextInt(4);
return dir==0 && upFree?new int[]{x,y-8}:(dir==1 && leftFree?new int[]{x+8,y}:(dir==2 && downFree?new int[]{x,y+8}:(dir==3 && rightFree?new int[]{x-8,y}:new int[]{x,y})));
}
4

1 回答 1

0

J 是从 0 到 75,但 i 使用 32 步宽(乘以 32),因此 J 与下一个元素变量字段重叠。

materialRGBmap[(i*32)+j]

正在使用上次迭代使用的地图元素。如果将 j 的限制更改为 32,则每次 i 迭代只能计算/使用 32 宽的字段。

另外,您不会像并行那样进行逐元素计算。您正在一个一个地改变元素,而不是同时改变所有元素。您需要临时数组来存储结果,最后将全部复制到原始数组。

深注:当您使用 1000 x 1000 区域时,请远离放置单个点(绘画部分)。编辑图像然后绘图更快。

于 2013-06-30T15:48:02.740 回答