kble/src/main.zig

58 lines
1.6 KiB
Zig
Raw Normal View History

2021-01-24 19:22:48 +01:00
const ray = @cImport({
@cInclude("raylib.h");
});
const std = @import("std");
const assert = std.debug.assert;
const format = std.fmt.format;
const maxInt = std.math.maxInt;
const Level = @import("level.zig");
const Vec2 = @import("vec2.zig");
2021-01-24 19:22:48 +01:00
pub fn main() !void {
// Create allocator
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer {
const leaked: bool = gpa.deinit();
if (leaked) assert(false); //raise error
}
const allocator = &gpa.allocator;
2021-01-24 19:22:48 +01:00
// Create window.
2021-01-24 19:22:48 +01:00
ray.SetConfigFlags(ray.FLAG_WINDOW_RESIZABLE);
ray.InitWindow(640, 480, "KBLE");
2021-01-24 19:22:48 +01:00
defer ray.CloseWindow();
// Limit FPS for performance.
2021-01-24 19:22:48 +01:00
ray.SetTargetFPS(60);
// Create level
var level: Level = try Level.init(allocator, 128, 128);
defer level.deinit(allocator);
// Create camera
var camera: Vec2 = Vec2.init(0, 0);
while (!ray.WindowShouldClose()) {
// Temp code: move camera with arrow keys.
if (ray.IsKeyDown(ray.KEY_LEFT) and camera.x > 0)
camera.x -= 1;
if (ray.IsKeyDown(ray.KEY_RIGHT) and
camera.x < comptime maxInt(Vec2.int_type))
camera.x += 1;
if (ray.IsKeyDown(ray.KEY_UP) and camera.y > 0)
camera.y -= 1;
if (ray.IsKeyDown(ray.KEY_DOWN) and
camera.y < comptime maxInt(Vec2.int_type))
camera.y += 1;
// Put all draw code after this.
2021-01-24 19:22:48 +01:00
ray.BeginDrawing();
defer ray.EndDrawing();
ray.ClearBackground(ray.BLACK);
level.draw(camera);
ray.DrawFPS(0, 0);
2021-01-24 19:22:48 +01:00
}
}