This commit is contained in:
jonathan santis 2024-11-15 16:14:46 +01:00
parent 8452d41247
commit c3b9fbc298
2 changed files with 15 additions and 10 deletions

View File

@ -28,6 +28,8 @@ test "random" {
} }
} }
} }
const screenWidth = 800;
const screenHeight = 450;
const Particle = struct { const Particle = struct {
const Self = @This(); const Self = @This();
@ -46,29 +48,29 @@ const Particle = struct {
self.lifespan -= 1; self.lifespan -= 1;
} else { } else {
const xrnr = randMinMaxFloat(-1,1); const xrnr = randMinMaxFloat(-1,1);
const yrnr = randMinMaxFloat(-1,1); const yrnr = randMinMaxFloat(-0.5,0.5);
std.debug.print("rngx:{}\nyrng:{}\n",.{xrnr,yrnr});
self.lifespan = rand.intRangeAtMost(u8,1,100); self.lifespan = rand.intRangeAtMost(u8,1,100);
self.acceleration.a.x = xrnr; self.acceleration.a.x = xrnr;
self.acceleration.a.y = yrnr; self.acceleration.a.y = yrnr;
self.position.a.x = 0; self.position.a.x = @floatFromInt(rl.getMouseX()-screenWidth/2);
self.position.a.y = 0; self.position.a.y = @floatFromInt(rl.getMouseY()-screenHeight/2);
self.velocity.a.x = 0; self.velocity.a.x = 0;
self.velocity.a.y = 0; self.velocity.a.y = -20;
self.position.a.color.r = rand.intRangeAtMost(u8,0,255); self.position.a.color.r = rand.intRangeAtMost(u8,0,255);
self.position.a.color.g = rand.intRangeAtMost(u8,0,255); self.position.a.color.g = rand.intRangeAtMost(u8,0,255);
self.position.a.color.b = rand.intRangeAtMost(u8,0,255); self.position.a.color.b = rand.intRangeAtMost(u8,0,255);
} }
}
pub fn applyGravity(self : *Self,val : f32) void {
self.velocity.a.y += val;
} }
}; };
pub fn main() anyerror!void { pub fn main() anyerror!void {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const screenWidth = 800;
const screenHeight = 450;
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 rect2 = rl.Rectangle{ .x = @as(f32, @floatFromInt(10)), .y = @as(f32, @floatFromInt(10)), .width = @as(f32, @floatFromInt(300)), .height = @as(f32, @floatFromInt(100)) };
var msg_res : i32=-1; var msg_res : i32=-1;
var state : i32=-1; var state : i32=-1;
@ -83,13 +85,15 @@ pub fn main() anyerror!void {
var posx : i32 = 0; var posx : i32 = 0;
var posy : i32 = 0; var posy : i32 = 0;
var p1 : [100]Particle = undefined; var p1 : [1000]Particle = undefined;
for (&p1) |*p| { for (&p1) |*p| {
xrnr = rand.float(f32); xrnr = rand.float(f32);
yrnr = rand.float(f32); yrnr = rand.float(f32);
p.* = Particle{.velocity = .{.a = .{.x = 5,.y = 1}},.acceleration = .{.a = .{.x=xrnr,.y=yrnr}}}; p.* = Particle{.velocity = .{.a = .{.x = 1,.y = -3}},.acceleration = .{.a = .{.x=xrnr,.y=yrnr}}};
} }
const img : rl.Texture = rl.loadTexture("img.png");
rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window"); rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
defer rl.closeWindow(); // Close window and OpenGL context defer rl.closeWindow(); // Close window and OpenGL context
@ -123,6 +127,7 @@ pub fn main() anyerror!void {
} }
for (&p1) |*p| { for (&p1) |*p| {
p.update(); p.update();
p.applyGravity(2);
if(p.position.a.x >= -(screenWidth/2)){ if(p.position.a.x >= -(screenWidth/2)){
posx = @intFromFloat(screenWidth / 2 + p.position.a.x); posx = @intFromFloat(screenWidth / 2 + p.position.a.x);
} else { } else {

Binary file not shown.