usg/src/main.zig

59 lines
1.6 KiB
Zig

const std = @import("std");
const SDL = @import("sdl2");
const Game = @import("Game.zig");
const MainMenu = @import("MainMenu.zig");
const State = @import("flow.zig").State;
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,
1280,
720,
SDL.SDL_WINDOW_SHOWN,
) orelse return;
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 main_menu = MainMenu.init();
var game = Game.init(renderer);
var current_state: State = main_menu.state;
_ = SDL.SDL_SetRenderDrawBlendMode(renderer, SDL.SDL_BLENDMODE_BLEND);
mainLoop: while (true) {
var ev: SDL.SDL_Event = undefined;
while (SDL.SDL_PollEvent(&ev) != 0) {
if (ev.type == SDL.SDL_QUIT)
break :mainLoop;
}
_ = SDL.SDL_SetRenderDrawColor(renderer, 231, 247, 255, 0xFF);
_ = SDL.SDL_RenderClear(renderer);
current_state = switch (current_state) {
State.main_menu => main_menu.tick(),
State.game => game.tick(),
};
SDL.SDL_RenderPresent(renderer);
}
}