Added Config.json

This commit is contained in:
Elias Stepanik 2022-10-28 10:20:04 +02:00
parent f50dd3be04
commit 0e87a7e15d
7 changed files with 114 additions and 6 deletions

7
PixelEngine/Config.cs Normal file
View File

@ -0,0 +1,7 @@
namespace PixelEngine;
public class Config
{
public List<Density> Densities { get; set; }
public List<Velocity> Velocities { get; set; }
}

62
PixelEngine/Config.json Normal file
View File

@ -0,0 +1,62 @@
{
"Densities":[
{
"x":64,
"y":64,
"amount":200
}
],
"Velocities":[
{
"x":32,
"y":64,
"amountX":0.1,
"amountY":-0.1
},
{
"x":96,
"y":64,
"amountX":-0.1,
"amountY":0.1
},
{
"x":64,
"y":32,
"amountX":0.1,
"amountY":0.1
},
{
"x":64,
"y":96,
"amountX":-0.1,
"amountY":-0.1
},
{
"x":64,
"y":64,
"amountX":0.1,
"amountY":-0.1
},
{
"x":64,
"y":64,
"amountX":-0.1,
"amountY":0.1
},
{
"x":64,
"y":64,
"amountX":0.1,
"amountY":0.1
},
{
"x":64,
"y":64,
"amountX":-0.1,
"amountY":-0.1
}
]
}

8
PixelEngine/Density.cs Normal file
View File

@ -0,0 +1,8 @@
namespace PixelEngine;
public class Density
{
public int x { get; set; }
public int y{ get; set; }
public float amount { get; set; }
}

View File

@ -77,7 +77,8 @@ public class Fluid
}
}
public void renderD() {
public void renderD()
{
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
int x = i * scale;
@ -211,11 +212,11 @@ public class Fluid
if (x < 0.5f) x = 0.5f;
if (x > Nfloat + 0.5f) x = Nfloat + 0.5f;
i0 = RayMath.floorf(x);
i0 = floorf(x);
i1 = i0 + 1.0f;
if (y < 0.5f) y = 0.5f;
if (y > Nfloat + 0.5f) y = Nfloat + 0.5f;
j0 = RayMath.floorf(y);
j0 = floorf(y);
j1 = j0 + 1.0f;
s1 = x - i0;

View File

@ -1,4 +1,5 @@
using System.Numerics;
using Newtonsoft.Json;
using static Raylib_CsLo.Raylib;
using static Raylib_CsLo.RayGui;
using Raylib_CsLo;
@ -7,8 +8,8 @@ namespace PixelEngine;
public class Game
{
private const int Size = 256;
private const int Scale = 2;
private const int Size = 128;
private const int Scale = 7;
private const int Iter = 10;
private const float Dt = 0.2f;
private const float Diffusion = 0f;
@ -27,12 +28,26 @@ public class Game
InitWindow(Size * Scale, Size * Scale, WindowTitle);
SetTargetFPS(TargetFps);
}
public void HandleInput()
{
var config = JsonConvert.DeserializeObject<Config>(File.ReadAllText("Config.json"));
foreach (var configVelocity in config.Velocities)
{
DrawCircle(configVelocity.x * Scale, configVelocity.y *Scale, 5, RED);
DrawLine(configVelocity.x * Scale,configVelocity.y *Scale, (int) ((configVelocity.x * Scale) + (configVelocity.amountX)),(int) ((configVelocity.y * Scale) + (configVelocity.amountY)), RED);
_fluid.addVelocity(configVelocity.x, configVelocity.y, configVelocity.amountX, configVelocity.amountY);
}
foreach (var configDensity in config.Densities)
{
_fluid.addDensity(configDensity.x, configDensity.y, configDensity.amount);
}
// Add Density
if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_LEFT))
{
@ -61,7 +76,7 @@ public class Game
PMouse = GetMousePosition();
}
}

View File

@ -9,7 +9,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Raylib-CsLo" Version="4.2.0.3" />
</ItemGroup>
<ItemGroup>
<Content Include="Config.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>

10
PixelEngine/Velocity.cs Normal file
View File

@ -0,0 +1,10 @@
namespace PixelEngine;
public class Velocity
{
public int x { get; set; }
public int y { get; set; }
public float amountX { get; set; }
public float amountY { get; set; }
}