2022-06-28 12:42:28 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const SDL = @import("sdl2");
|
|
|
|
|
2022-07-12 14:20:15 +00:00
|
|
|
const Game = @import("Game.zig");
|
2022-07-12 18:27:40 +00:00
|
|
|
const MainMenu = @import("MainMenu.zig");
|
2022-06-28 12:42:28 +00:00
|
|
|
|
2022-07-13 20:59:54 +00:00
|
|
|
const State = @import("flow.zig").State;
|
|
|
|
|
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);
|
|
|
|
|
2022-07-12 18:27:40 +00:00
|
|
|
var main_menu = MainMenu.init();
|
2022-07-13 20:59:54 +00:00
|
|
|
var game = Game.init(renderer);
|
|
|
|
|
|
|
|
var current_state: State = main_menu.state;
|
2022-06-28 12:42:28 +00:00
|
|
|
|
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);
|
|
|
|
|
2022-07-13 20:59:54 +00:00
|
|
|
current_state = switch (current_state) {
|
|
|
|
State.main_menu => main_menu.tick(),
|
|
|
|
State.game => game.tick(),
|
|
|
|
};
|
2022-06-28 12:42:28 +00:00
|
|
|
|
|
|
|
SDL.SDL_RenderPresent(renderer);
|
|
|
|
}
|
|
|
|
}
|