sdf
This commit is contained in:
parent
1f06051e0a
commit
7295b4deaf
32
src/main.zig
32
src/main.zig
@ -61,8 +61,8 @@ const Particle = struct {
|
||||
}
|
||||
pub fn spawn(self:*Self,xaccel : f32,yaccel : f32) void
|
||||
{
|
||||
const xrnr = randMinMaxFloat(-1-xaccel,1+xaccel);
|
||||
const yrnr = randMinMaxFloat(-0.5-yaccel,0.5+yaccel);
|
||||
const xrnr = randMinMaxFloat(-xaccel,xaccel);
|
||||
const yrnr = randMinMaxFloat(-yaccel,yaccel);
|
||||
|
||||
self.lifespan = rand.intRangeAtMost(u8,75,255);
|
||||
self.acceleration.a.x = xrnr;
|
||||
@ -70,7 +70,7 @@ const Particle = struct {
|
||||
self.position.a.x = @floatFromInt(rl.getMouseX()-screenWidth/2);
|
||||
self.position.a.y = @floatFromInt(rl.getMouseY()-screenHeight/2);
|
||||
self.velocity.a.x = 0;
|
||||
self.velocity.a.y = -20;
|
||||
self.velocity.a.y = 0;
|
||||
self.position.a.color.r = rand.intRangeAtMost(u8,0,30);
|
||||
self.position.a.color.g = rand.intRangeAtMost(u8,0,255);
|
||||
self.position.a.color.b = rand.intRangeAtMost(u8,0,255);
|
||||
@ -123,23 +123,24 @@ const Emitter = struct
|
||||
{
|
||||
var posx : i32 = 0;
|
||||
var posy : i32 = 0;
|
||||
const att : Attractor = .{.vec = .{.a=.{.x=200,.y=200,.z=0}}};
|
||||
const att2 : Attractor = .{.vec = .{.a=.{.x=400,.y=400,.z=0}}};
|
||||
const att : Attractor = .{.vec = .{.a=.{.x=10,.y=10,.z=10}}};
|
||||
const att2 : Attractor = .{.vec = .{.a=.{.x=-100,.y=-100,.z=0}}};
|
||||
|
||||
att.draw();
|
||||
att2.draw();
|
||||
for (self.particles) |*p| {
|
||||
if(p.show == 1)
|
||||
{
|
||||
p.update();
|
||||
|
||||
p.applyGravity(0);
|
||||
p.applyForce(att.attract(p.*));
|
||||
p.applyForce(att2.attract(p.*));
|
||||
p.update();
|
||||
|
||||
posx = @intFromFloat(screenWidth / 2 + p.position.a.x);
|
||||
posy = @intFromFloat(screenHeight / 2 + p.position.a.y);
|
||||
//rl.drawRectangle(posx,posy,2,2,rl.Color{.r=p.position.a.color.r,.g=p.position.a.color.g,.b=p.position.a.color.b,.a=255});
|
||||
rl.drawTexture(texture,posx,posy,rl.Color.white);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,15 +150,20 @@ const Attractor = struct
|
||||
vec : pr.Vec,
|
||||
pub fn attract(self:Attractor,particle : Particle) pr.Vec
|
||||
{
|
||||
|
||||
var vec = self.vec.sub(particle.position);
|
||||
vec.a.x /= 100;
|
||||
vec.a.y /= 100;
|
||||
vec.a.z /= 100;
|
||||
if( vec.a.x != 0 and vec.a.y != 0)
|
||||
{
|
||||
vec.a.x = vec.a.x/20;
|
||||
vec.a.y = vec.a.y/20;
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
pub fn draw(self:Attractor) void
|
||||
{
|
||||
rl.drawRectangle(@intFromFloat(self.vec.a.x),@intFromFloat(self.vec.a.y),10,10,rl.Color{.r=10,.g=10,.b=120,.a=255});
|
||||
const posx : i32 = @intFromFloat(screenWidth / 2 + self.vec.a.x);
|
||||
const posy : i32 = @intFromFloat(screenHeight / 2 + self.vec.a.y);
|
||||
rl.drawRectangle(posx,posy,10,10,rl.Color{.r=10,.g=10,.b=120,.a=255});
|
||||
}
|
||||
};
|
||||
fn ItoF(x:i32) f32
|
||||
@ -219,8 +225,8 @@ pub fn main() anyerror!void {
|
||||
});
|
||||
|
||||
_ = rg.guiSlider(rect3,"0","500",&value,ItoF(0),ItoF(500));
|
||||
_ = rg.guiSlider(rect4,"-3","3",&value2,ItoF(-3),ItoF(3));
|
||||
_ = rg.guiSlider(rect5,"-3","3",&value3,ItoF(-3),ItoF(3));
|
||||
_ = rg.guiSlider(rect4,"-3","3",&value2,ItoF(-10),ItoF(10));
|
||||
_ = rg.guiSlider(rect5,"-3","3",&value3,-10,10);
|
||||
|
||||
if(rl.isMouseButtonDown(rl.MouseButton.mouse_button_left))
|
||||
{
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user