Added Holes to the mix

This commit is contained in:
Elias Stepanik 2022-10-25 08:56:48 +02:00
parent 2a742b170b
commit 0b7fa3e99f
5 changed files with 103 additions and 7 deletions

20
PixelEngine/BlackHole.cs Normal file
View File

@ -0,0 +1,20 @@
using System.Numerics;
namespace PixelEngine;
public class BlackHole : Hole
{
public BlackHole(Vector2 position, int radius, float mass) : base(position, mass)
{
this.radius = radius;
}
public override void Spawn(Fluid fluid)
{
fluid.reduceDensity((int)position.X, (int)position.Y, mass, radius);
}
public override Vector2 position { get; set; }
public int radius { get; set; }
public override float mass { get; set; }
}

View File

@ -112,11 +112,11 @@ public class Fluid
this.density[index] += amount;
}
public void reduceDensity(int x, int y, float amount) {
public void reduceDensity(int x, int y, float amount, int rSize) {
for (int i = -10; i < 10; i++)
for (int i = -rSize; i < rSize; i++)
{
for (int j = -10; j < 10; j++)
for (int j = -rSize; j < rSize; j++)
{
int index = IX(x + i, y + j);

15
PixelEngine/Hole.cs Normal file
View File

@ -0,0 +1,15 @@
using System.Numerics;
namespace PixelEngine;
public abstract class Hole
{
public Hole(Vector2 position, float mass)
{
this.position = position;
this.mass = mass;
}
public abstract void Spawn(Fluid fluid);
public abstract Vector2 position { get; set; }
public abstract float mass { get; set; }
}

View File

@ -15,6 +15,8 @@ var N = 64;
var Scale = 10;
var Iter = 10;
float t = 0;
int whiteholes = 4;
int blackholes = 1;
Fluid fluid;
@ -23,10 +25,32 @@ InitWindow(N * Scale, N * Scale, "Raylib_CsLo");
SetTargetFPS(60);
Random rd = new Random();
var pMouseX = GetMouseX();
var pMouseY = GetMouseY();
var whiteholesA = new WhiteHole[whiteholes];
var blackholesA = new BlackHole[blackholes];
for (int i = 0; i < whiteholes; i++)
{
whiteholesA[i] = new WhiteHole(
new Vector2(rd.Next(3, N - 3), rd.Next(3, N - 3)),
new Vector2(rd.Next(50, 100), rd.Next(50, 100)),
rd.Next(0, 100),
rd.Next(0, 100)
);
}
for (int i = 0; i < blackholes; i++)
{
blackholesA[i] = new BlackHole(
new Vector2(rd.Next(3, N - 3), rd.Next(3, N - 3)),
rd.Next(0, 3),
rd.Next(0,200)
);
}
while (!WindowShouldClose())
{
@ -58,7 +82,7 @@ while (!WindowShouldClose())
fluid.addDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100);
else if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_RIGHT))
{
fluid.reduceDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100);
fluid.reduceDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100, 5);
//TODO: Suction for Density Reduction
@ -67,11 +91,25 @@ while (!WindowShouldClose())
fluid.addVelocity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, amtX, amtY);*/
}
foreach (var hole in blackholesA)
{
hole.Spawn(fluid);
}
foreach (var hole in whiteholesA)
{
hole.Spawn(fluid);
}
/*fluid.addDensity(N - 3 , 3, 100);
fluid.addVelocity(N - 3 , 3, -10f, 0);*/
fluid.addDensity(N - 3, 3, 200);
fluid.addVelocity(N - 3 , 3, -10f, -10f);
/*if (GetMouseX() != pMouseX || GetMouseY() != pMouseY)

23
PixelEngine/WhiteHole.cs Normal file
View File

@ -0,0 +1,23 @@
using System.Numerics;
namespace PixelEngine;
public class WhiteHole : Hole
{
public override void Spawn(Fluid fluid)
{
fluid.addDensity((int) position.X, (int) position.Y, mass);
fluid.addVelocity((int) position.X, (int) position.Y, direction.X * speed, direction.Y * speed);
}
public override Vector2 position { get; set; }
public Vector2 direction { get; set; }
public override float mass { get; set; }
public float speed { get; set; }
public WhiteHole(Vector2 position, Vector2 direction, float mass, float speed) : base(position, mass)
{
this.direction = direction;
this.speed = speed;
}
}