usg/src/main.zig

50 lines
1.3 KiB
Zig
Raw Normal View History

2022-06-28 12:42:28 +00:00
const std = @import("std");
const SDL = @import("sdl2");
const Game = @import("Game.zig");
2022-06-28 12:42:28 +00:00
pub fn main() !void {
const stderr = std.io.getStdErr();
defer stderr.close();
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// defer _ = gpa.deinit();
// const allocator = gpa.allocator();
_ = SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_AUDIO);
defer SDL.SDL_Quit();
var window = SDL.SDL_CreateWindow(
"USG",
SDL.SDL_WINDOWPOS_CENTERED,
SDL.SDL_WINDOWPOS_CENTERED,
2022-07-07 14:49:15 +00:00
1280,
720,
2022-06-28 12:42:28 +00:00
SDL.SDL_WINDOW_SHOWN,
2022-07-05 18:26:57 +00:00
) orelse return;
2022-06-28 12:42:28 +00:00
defer _ = SDL.SDL_DestroyWindow(window);
var renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RENDERER_PRESENTVSYNC | SDL.SDL_RENDERER_ACCELERATED) orelse return;
defer _ = SDL.SDL_DestroyRenderer(renderer);
var game = Game.init(renderer);
2022-07-05 18:26:57 +00:00
_ = SDL.SDL_SetRenderDrawBlendMode(renderer, SDL.SDL_BLENDMODE_BLEND);
2022-06-28 12:42:28 +00:00
mainLoop: while (true) {
var ev: SDL.SDL_Event = undefined;
while (SDL.SDL_PollEvent(&ev) != 0) {
if (ev.type == SDL.SDL_QUIT)
break :mainLoop;
}
2022-07-07 14:23:16 +00:00
_ = SDL.SDL_SetRenderDrawColor(renderer, 231, 247, 255, 0xFF);
2022-06-28 12:42:28 +00:00
_ = SDL.SDL_RenderClear(renderer);
game.tick();
SDL.SDL_RenderPresent(renderer);
}
}