sdofi
This commit is contained in:
parent
a1694c8209
commit
2d7cd53437
31
src/main.zig
31
src/main.zig
@ -38,20 +38,27 @@ const Particle = struct {
|
||||
velocity : pr.Vec = .{.a = .{.x=0,.y=0,.z=0}},
|
||||
acceleration : pr.Vec = .{.a = .{.x=0,.y=0,.z=0}},
|
||||
lifespan : u8 = 0,
|
||||
spawm : u8 = 1,
|
||||
pub fn new(self:Self) void {
|
||||
_ = self;
|
||||
}
|
||||
pub fn update(self:*Self) void {
|
||||
self.velocity.add(self.acceleration);
|
||||
self.position.add(self.velocity);
|
||||
if (self.position.a.y > screenHeight)
|
||||
{
|
||||
self.velocity.a.y *= -0.9;
|
||||
// self.acceleration.a.y *= -0.5;
|
||||
}
|
||||
|
||||
if (self.lifespan > 0) {
|
||||
self.lifespan -= 1;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
const xrnr = randMinMaxFloat(-1,1);
|
||||
const yrnr = randMinMaxFloat(-0.5,0.5);
|
||||
|
||||
self.lifespan = rand.intRangeAtMost(u8,1,100);
|
||||
self.lifespan = rand.intRangeAtMost(u8,75,255);
|
||||
self.acceleration.a.x = xrnr;
|
||||
self.acceleration.a.y = yrnr;
|
||||
self.position.a.x = @floatFromInt(rl.getMouseX()-screenWidth/2);
|
||||
@ -67,12 +74,17 @@ const Particle = struct {
|
||||
self.velocity.a.y += val;
|
||||
}
|
||||
};
|
||||
fn ItoF(x:i32) f32
|
||||
{
|
||||
return @as(f32,@floatFromInt(x));
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
const rect2 = rl.Rectangle{ .x = @as(f32, @floatFromInt(10)), .y = @as(f32, @floatFromInt(10)), .width = @as(f32, @floatFromInt(300)), .height = @as(f32, @floatFromInt(100)) };
|
||||
const rect3 = rl.Rectangle{ .x = @as(f32, @floatFromInt(200)), .y = @as(f32, @floatFromInt(150)), .width = @as(f32, @floatFromInt(600)), .height = @as(f32, @floatFromInt(10)) };
|
||||
var msg_res : i32=-1;
|
||||
var state : i32=-1;
|
||||
|
||||
@ -85,8 +97,9 @@ pub fn main() anyerror!void {
|
||||
|
||||
var posx : i32 = 0;
|
||||
var posy : i32 = 0;
|
||||
var value : f32 = 0;
|
||||
|
||||
const p1 = try allocator.alloc(Particle,5000);
|
||||
const p1 = try allocator.alloc(Particle,500000);
|
||||
for (p1) |*p| {
|
||||
xrnr = rand.float(f32);
|
||||
yrnr = rand.float(f32);
|
||||
@ -126,7 +139,14 @@ pub fn main() anyerror!void {
|
||||
else =>{},
|
||||
}
|
||||
}
|
||||
for (p1) |*p| {
|
||||
_ = rg.guiSlider(rect3,"0","500000",&value,ItoF(0),ItoF(500000));
|
||||
for (0..,p1) |i,*p| {
|
||||
if(i<@as(usize,@intFromFloat(value)))
|
||||
{
|
||||
if(rl.isMouseButtonPressed(rl.MouseButton.mouse_button_left))
|
||||
{
|
||||
p.spawm = 1;
|
||||
}
|
||||
p.update();
|
||||
p.applyGravity(2);
|
||||
if(p.position.a.x >= -(screenWidth/2)){
|
||||
@ -139,7 +159,8 @@ pub fn main() anyerror!void {
|
||||
} else {
|
||||
posy = 0;
|
||||
}
|
||||
rl.drawRectangle(posx,posy,5,5,rl.Color{.r=p.position.a.color.r,.g=p.position.a.color.g,.b=p.position.a.color.b,.a=255});
|
||||
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});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user