Port MainMenu to OpenGL

This commit is contained in:
Dendy 2022-07-25 16:12:57 +02:00
parent fb09ef0b6e
commit 7921471b96
3 changed files with 19 additions and 20 deletions

View File

@ -13,9 +13,9 @@ const Self = @This();
action_list: [3]Action = .{ action_list: [3]Action = .{
// Action.init(SDL.SDL_SCANCODE_RIGHT, actionRight), // Tab Right // Action.init(SDL.SDL_SCANCODE_RIGHT, actionRight), // Tab Right
// Action.init(SDL.SDL_SCANCODE_LEFT, actionLeft), // Tab left // Action.init(SDL.SDL_SCANCODE_LEFT, actionLeft), // Tab left
Action.init(SDL.SDL_SCANCODE_DOWN, actionSelDown), // Go down Action.init(SDL.Scancode.down, actionSelDown), // Go down
Action.init(SDL.SDL_SCANCODE_UP, actionSelUp), // Go up Action.init(SDL.Scancode.up, actionSelUp), // Go up
Action.init(SDL.SDL_SCANCODE_RETURN, actionSelect), // Select Action.init(SDL.Scancode.@"return", actionSelect), // Select
}, },
tab_list: [2]MenuTab = [2]MenuTab{ tab_list: [2]MenuTab = [2]MenuTab{
@ -40,7 +40,7 @@ state: State = State.main_menu,
holding_down: bool = false, holding_down: bool = false,
holding_enter: bool = false, holding_enter: bool = false,
pub fn init(renderer: *SDL.SDL_Renderer) Self { pub fn init(renderer: Renderer.Renderer) Self {
return Self{.renderer = Renderer.init(renderer)}; return Self{.renderer = Renderer.init(renderer)};
} }
@ -55,14 +55,14 @@ fn getTab(self: *Self) MenuTab {
pub fn tick(self: *Self) State { pub fn tick(self: *Self) State {
const sel = self.getSel(); const sel = self.getSel();
const tab = self.getTab(); const tab = self.getTab();
var key_state = SDL.SDL_GetKeyboardState(null); var key_state = SDL.getKeyboardState();
for (self.action_list) |*action| { for (self.action_list) |*action| {
if (key_state[action.*.code] == 1 and !action.*.holding) { if (key_state.isPressed(action.*.scancode) and !action.*.holding) {
action.*.holding = true; action.*.holding = true;
action.*.activate = true; action.*.activate = true;
} }
if (key_state[action.*.code] == 0) { if (!key_state.isPressed(action.*.scancode)) {
action.*.holding = false; action.*.holding = false;
} }

View File

@ -2,13 +2,14 @@ const SDL = @import("sdl2");
const MainMenu = @import("../MainMenu.zig"); const MainMenu = @import("../MainMenu.zig");
pub const Renderer = @import("../Renderer.zig");
const color = @import("../color.zig"); const color = @import("../color.zig");
const Self = @This(); const Self = @This();
renderer: *SDL.SDL_Renderer, renderer: Renderer,
pub fn init(renderer: *SDL.SDL_Renderer) Self { pub fn init(renderer: Renderer) Self {
return Self { return Self {
.renderer = renderer, .renderer = renderer,
}; };

View File

@ -3,20 +3,20 @@ const SDL = @import("sdl2");
const Renderer = @import("Renderer.zig"); const Renderer = @import("Renderer.zig");
const Game = @import("Game.zig"); const Game = @import("Game.zig");
//const MainMenu = @import("MainMenu.zig"); const MainMenu = @import("MainMenu.zig");
//const State = @import("flow.zig").State; const State = @import("flow.zig").State;
pub fn main() !void { pub fn main() !void {
var renderer = try Renderer.init(); var renderer = try Renderer.init();
defer renderer.deinit(); defer renderer.deinit();
//var main_menu = MainMenu.init(); var main_menu = MainMenu.init(renderer);
var game = Game.init(renderer); var game = Game.init(renderer);
//var current_state: State = main_menu.state; var current_state: State = main_menu.state;
//_ = SDL.IMG_Init(SDL.IMG_INIT_JPG); try SDL.image.init(.{ .jpg = true });
mainLoop: while (true) { mainLoop: while (true) {
while (SDL.pollEvent()) |ev| { while (SDL.pollEvent()) |ev| {
@ -26,12 +26,10 @@ pub fn main() !void {
} }
} }
_ = game.tick(); current_state = switch (current_state) {
.main_menu => main_menu.tick(),
//current_state = switch (current_state) { .game => game.tick(),
//.main_menu => main_menu.tick(), };
//.game => game.tick(),
//};
renderer.render(); renderer.render();
} }