create assets and split scene
parent
d9ef89495b
commit
eab2c63855
|
|
@ -0,0 +1,20 @@
|
|||
const assets = @import("assets.zig");
|
||||
const Recti = @import("geometry/Recti.zig");
|
||||
const Layer = @import("Layer.zig");
|
||||
const Color = @import("Color.zig");
|
||||
const std = @import("std");
|
||||
|
||||
const Scene = @This();
|
||||
// const DrawFunction = fn() void;
|
||||
// const UpdateFunction = fn(f32) void;
|
||||
|
||||
// draw: DrawFunction,
|
||||
// update:
|
||||
|
||||
pub fn draw() void {
|
||||
assets.heart.draw(&Recti.from_xywh(120, 100, 32, 64), Layer.ENTITIES, Color.LIGHT_BLUE);
|
||||
assets.heart.draw(&Recti.from_xywh(100, 100, 32, 64), Layer.FLOOR, Color.WHITE);
|
||||
assets.heart.draw(&Recti.from_xywh(80, 100, 32, 64), Layer.ENTITIES, Color.INDIGO);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
const Texture = @import("Texture.zig");
|
||||
const Sprite = @import("Sprite.zig");
|
||||
const Recti = @import("geometry/Recti.zig");
|
||||
const std = @import("std");
|
||||
|
||||
const Assets = struct {
|
||||
tree: Sprite,
|
||||
heart: Sprite,
|
||||
};
|
||||
|
||||
var assets: Assets = undefined;
|
||||
var texture: Texture = undefined;
|
||||
|
||||
pub fn load() !void {
|
||||
texture = try Texture.create("textures.png");
|
||||
|
||||
assets = .{
|
||||
.tree = Sprite.create(&texture, Recti.from_xywh(8*27, 8*4, 8, 16)),
|
||||
.heart = Sprite.create(&texture, Recti.from_xywh(8*27, 8*4, 8, 16)),
|
||||
};
|
||||
}
|
||||
|
||||
pub const tree: *const Sprite = &assets.tree;
|
||||
pub const heart: *const Sprite = &assets.heart;
|
||||
|
|
@ -6,6 +6,8 @@ const Texture = @import("Texture.zig");
|
|||
const Sprite = @import("Sprite.zig");
|
||||
const Layer = @import("Layer.zig");
|
||||
const Color = @import("Color.zig");
|
||||
const Scene = @import("Scene.zig");
|
||||
const assets = @import("assets.zig");
|
||||
|
||||
const c = @cImport({
|
||||
@cInclude("glad/glad.h");
|
||||
|
|
@ -66,9 +68,8 @@ pub fn run() !void {
|
|||
// compile shaders...
|
||||
try shaders.load();
|
||||
|
||||
const texture = try Texture.create("textures.png");
|
||||
// texture.bind(c.GL_TEXTURE0);
|
||||
const sprite = Sprite.create(&texture, Recti.from_xywh(8*27, 8*4, 8, 16));
|
||||
try assets.load();
|
||||
|
||||
|
||||
const clearBrightness: f32 = 0.09;
|
||||
c.glClearColor(clearBrightness, clearBrightness, clearBrightness, 1.0);
|
||||
|
|
@ -89,28 +90,11 @@ pub fn run() !void {
|
|||
// run the main loop
|
||||
while (c.glfwWindowShouldClose(window) == 0) {
|
||||
shaders.set_projection_matrix(&projection);
|
||||
|
||||
// std.debug.print("size: {d} x {d}\n", .{width, height});
|
||||
// c.glViewport(0, 0, width, height);
|
||||
c.glClear(c.GL_COLOR_BUFFER_BIT | c.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// c.glBegin(c.GL_TRIANGLES);
|
||||
//
|
||||
// c.glVertex2f(0, 1);
|
||||
// // c.glVertexAttrib4f(1, 1, 0, 0, 1);
|
||||
// c.glVertex2f(-1, -1);
|
||||
// // c.glVertexAttrib4f(1, 0, 1, 0, 1);
|
||||
// c.glVertex2f(1, -1);
|
||||
// // c.glVertexAttrib4f(1, 0, 0, 1, 1);
|
||||
//
|
||||
// c.glEnd();
|
||||
sprite.draw(&Recti.from_xywh(120, 100, 32, 64), Layer.ENTITIES, Color.LIGHT_BLUE);
|
||||
sprite.draw(&Recti.from_xywh(100, 100, 32, 64), Layer.FLOOR, Color.WHITE);
|
||||
sprite.draw(&Recti.from_xywh(80, 100, 32, 64), Layer.ENTITIES, Color.INDIGO);
|
||||
// draw.rect(&geometry.Rect.from_xywh(100, 100, 256, 256), draw.Layer.FLOOR);
|
||||
|
||||
Scene.draw();
|
||||
// game.render();
|
||||
// game.update(1.0);
|
||||
|
||||
c.glfwSwapBuffers(window);
|
||||
c.glfwPollEvents();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,8 @@ const std = @import("std");
|
|||
const engine = @import("engine.zig");
|
||||
|
||||
pub fn main() !void {
|
||||
|
||||
// engine.preload
|
||||
|
||||
try engine.run();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue