2021-01-24 19:22:48 +01:00
|
|
|
const ray = @cImport({
|
|
|
|
@cInclude("raylib.h");
|
|
|
|
});
|
2021-01-26 17:44:40 +01:00
|
|
|
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
|
|
|
|
2021-01-26 13:10:16 +01:00
|
|
|
pub fn main() !void {
|
|
|
|
// Create allocator
|
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
defer {
|
2021-01-26 17:44:40 +01:00
|
|
|
const leaked: bool = gpa.deinit();
|
2021-01-26 13:10:16 +01:00
|
|
|
if (leaked) assert(false); //raise error
|
|
|
|
}
|
|
|
|
const allocator = &gpa.allocator;
|
2021-01-24 19:22:48 +01:00
|
|
|
|
2021-01-26 17:44:40 +01:00
|
|
|
// Create window.
|
2021-01-24 19:22:48 +01:00
|
|
|
ray.SetConfigFlags(ray.FLAG_WINDOW_RESIZABLE);
|
2021-01-26 13:10:16 +01:00
|
|
|
ray.InitWindow(640, 480, "KBLE");
|
2021-01-24 19:22:48 +01:00
|
|
|
defer ray.CloseWindow();
|
|
|
|
|
2021-01-26 17:44:40 +01:00
|
|
|
// Limit FPS for performance.
|
2021-01-24 19:22:48 +01:00
|
|
|
ray.SetTargetFPS(60);
|
|
|
|
|
2021-01-26 13:10:16 +01:00
|
|
|
// Create level
|
|
|
|
var level: Level = try Level.init(allocator, 128, 128);
|
|
|
|
defer level.deinit(allocator);
|
|
|
|
|
2021-01-26 17:44:40 +01:00
|
|
|
// Create camera
|
|
|
|
var camera: Vec2 = Vec2.init(0, 0);
|
|
|
|
|
2021-01-26 13:10:16 +01:00
|
|
|
while (!ray.WindowShouldClose()) {
|
2021-01-26 17:44:40 +01:00
|
|
|
// 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();
|
|
|
|
|
2021-01-26 17:44:40 +01:00
|
|
|
ray.ClearBackground(ray.BLACK);
|
|
|
|
level.draw(camera);
|
|
|
|
ray.DrawFPS(0, 0);
|
2021-01-24 19:22:48 +01:00
|
|
|
}
|
|
|
|
}
|