Compare commits

..

No commits in common. "d368a4c09a09df968b66658eb5d2d8d2e424ae45" and "bd824f8a10c684b98c50e5f13ceba0f538756f00" have entirely different histories.

4 changed files with 12 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -59,10 +59,10 @@ const Particle = struct {
self.show = 0; self.show = 0;
} }
} }
pub fn spawn(self:*Self,xaccel : f32,yaccel : f32) void pub fn spawn(self:*Self) void
{ {
const xrnr = randMinMaxFloat(-1-xaccel,1+xaccel); const xrnr = randMinMaxFloat(-1,1);
const yrnr = randMinMaxFloat(-0.5-yaccel,0.5+yaccel); const yrnr = randMinMaxFloat(-0.5,0.5);
self.lifespan = rand.intRangeAtMost(u8,75,255); self.lifespan = rand.intRangeAtMost(u8,75,255);
self.acceleration.a.x = xrnr; self.acceleration.a.x = xrnr;
@ -98,7 +98,7 @@ const Emitter = struct
p.* = Particle{.velocity = .{.a = .{.x = 1,.y = -3}},.acceleration = .{.a = .{.x=xrnr,.y=yrnr}}}; p.* = Particle{.velocity = .{.a = .{.x = 1,.y = -3}},.acceleration = .{.a = .{.x=xrnr,.y=yrnr}}};
} }
} }
pub fn emit(self:*Emitter,count : u32,xaccel : f32,yaccel : f32) void pub fn emit(self:*Emitter,count : u32) void
{ {
var i : u32 = 0; var i : u32 = 0;
for(self.particles) |*p| for(self.particles) |*p|
@ -106,7 +106,7 @@ const Emitter = struct
if(p.show == 0) if(p.show == 0)
{ {
i+=1; i+=1;
p.spawn(xaccel,yaccel); p.spawn();
} }
if(i >= count) if(i >= count)
{ {
@ -114,11 +114,12 @@ const Emitter = struct
} }
} }
} }
pub fn update(self:*Emitter,texture : rl.Texture2D) void pub fn update(self:*Emitter) void
{ {
var posx : i32 = 0; var posx : i32 = 0;
var posy : i32 = 0; var posy : i32 = 0;
for (self.particles) |*p| { for (self.particles) |*p| {
if(p.show == 1) if(p.show == 1)
{ {
@ -134,9 +135,7 @@ const Emitter = struct
} else { } else {
posy = 0; posy = 0;
} }
//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.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);
} }
} }
} }
@ -145,10 +144,6 @@ fn ItoF(x:i32) f32
{ {
return @as(f32,@floatFromInt(x)); return @as(f32,@floatFromInt(x));
} }
fn rectangle(x : u16,y : u16,width : u16,height : u16) rl.Rectangle
{
return rl.Rectangle{ .x = @as(f32, @floatFromInt(x)), .y = @as(f32, @floatFromInt(y)), .width = @as(f32, @floatFromInt(width)), .height = @as(f32, @floatFromInt(height)) };
}
pub fn main() anyerror!void { pub fn main() anyerror!void {
// Initialization // Initialization
@ -156,8 +151,6 @@ pub fn main() anyerror!void {
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)) };
const rect3 = rl.Rectangle{ .x = @as(f32, @floatFromInt(10)), .y = @as(f32, @floatFromInt(150)), .width = @as(f32, @floatFromInt(600)), .height = @as(f32, @floatFromInt(10)) }; const rect3 = rl.Rectangle{ .x = @as(f32, @floatFromInt(10)), .y = @as(f32, @floatFromInt(150)), .width = @as(f32, @floatFromInt(600)), .height = @as(f32, @floatFromInt(10)) };
const rect4 = rectangle(10,170,600,10);
const rect5 = rectangle(10,190,600,10);
var msg_res : i32=-1; var msg_res : i32=-1;
var state : i32=-1; var state : i32=-1;
@ -167,31 +160,15 @@ pub fn main() anyerror!void {
prng = std.rand.DefaultPrng.init(seed); prng = std.rand.DefaultPrng.init(seed);
var value : f32 = 0; var value : f32 = 0;
var value2 : f32 = 0;
var value3 : f32 = 0;
var emitter = Emitter{}; var emitter = Emitter{};
try emitter.init(); try emitter.init();
//const img : rl.Texture = rl.loadTexture("img.png"); //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
var texture : rl.Texture2D = undefined;
const image : rl.Image = rl.loadImage("resources/test_64.png");
if(image.width > 0)
{
texture = rl.loadTextureFromImage(image);
}
else
{
std.debug.print("error opening resource",.{});
std.posix.exit(1);
}
rl.unloadImage(image);
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!rl.windowShouldClose()) { // Detect window close button or ESC key while (!rl.windowShouldClose()) { // Detect window close button or ESC key
@ -204,8 +181,6 @@ pub fn main() anyerror!void {
.a = 255, .a = 255,
}); });
if(state != 0){ if(state != 0){
msg_res = rg.guiMessageBox(rect2, "Title", "question?", "Nice;Cool"); msg_res = rg.guiMessageBox(rect2, "Title", "question?", "Nice;Cool");
if(msg_res > -1){ if(msg_res > -1){
@ -222,16 +197,14 @@ pub fn main() anyerror!void {
else =>{}, else =>{},
} }
} }
_ = rg.guiSlider(rect3,"0","5000",&value,ItoF(0),ItoF(500)); _ = rg.guiSlider(rect3,"0","5000",&value,ItoF(0),ItoF(5000));
_ = rg.guiSlider(rect4,"0","10",&value2,ItoF(0),ItoF(3));
_ = rg.guiSlider(rect5,"0","10",&value3,ItoF(0),ItoF(3));
if(rl.isMouseButtonDown(rl.MouseButton.mouse_button_left)) if(rl.isMouseButtonDown(rl.MouseButton.mouse_button_left))
{ {
emitter.emit(@as(u32,@intFromFloat(value)),value2,value3); emitter.emit(@as(u32,@intFromFloat(value)));
} }
emitter.update(texture); emitter.update();
} }
} }

Binary file not shown.