Port MainMenu to OpenGL
This commit is contained in:
parent
fb09ef0b6e
commit
7921471b96
|
@ -13,9 +13,9 @@ const Self = @This();
|
|||
action_list: [3]Action = .{
|
||||
// Action.init(SDL.SDL_SCANCODE_RIGHT, actionRight), // Tab Right
|
||||
// Action.init(SDL.SDL_SCANCODE_LEFT, actionLeft), // Tab left
|
||||
Action.init(SDL.SDL_SCANCODE_DOWN, actionSelDown), // Go down
|
||||
Action.init(SDL.SDL_SCANCODE_UP, actionSelUp), // Go up
|
||||
Action.init(SDL.SDL_SCANCODE_RETURN, actionSelect), // Select
|
||||
Action.init(SDL.Scancode.down, actionSelDown), // Go down
|
||||
Action.init(SDL.Scancode.up, actionSelUp), // Go up
|
||||
Action.init(SDL.Scancode.@"return", actionSelect), // Select
|
||||
},
|
||||
|
||||
tab_list: [2]MenuTab = [2]MenuTab{
|
||||
|
@ -40,7 +40,7 @@ state: State = State.main_menu,
|
|||
holding_down: 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)};
|
||||
}
|
||||
|
||||
|
@ -55,14 +55,14 @@ fn getTab(self: *Self) MenuTab {
|
|||
pub fn tick(self: *Self) State {
|
||||
const sel = self.getSel();
|
||||
const tab = self.getTab();
|
||||
var key_state = SDL.SDL_GetKeyboardState(null);
|
||||
var key_state = SDL.getKeyboardState();
|
||||
|
||||
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.*.activate = true;
|
||||
}
|
||||
if (key_state[action.*.code] == 0) {
|
||||
if (!key_state.isPressed(action.*.scancode)) {
|
||||
action.*.holding = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,14 @@ const SDL = @import("sdl2");
|
|||
|
||||
const MainMenu = @import("../MainMenu.zig");
|
||||
|
||||
pub const Renderer = @import("../Renderer.zig");
|
||||
const color = @import("../color.zig");
|
||||
|
||||
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 {
|
||||
.renderer = renderer,
|
||||
};
|
||||
|
|
20
src/main.zig
20
src/main.zig
|
@ -3,20 +3,20 @@ const SDL = @import("sdl2");
|
|||
|
||||
const Renderer = @import("Renderer.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 {
|
||||
var renderer = try Renderer.init();
|
||||
defer renderer.deinit();
|
||||
|
||||
//var main_menu = MainMenu.init();
|
||||
var main_menu = MainMenu.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) {
|
||||
while (SDL.pollEvent()) |ev| {
|
||||
|
@ -26,12 +26,10 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
|
||||
_ = game.tick();
|
||||
|
||||
//current_state = switch (current_state) {
|
||||
//.main_menu => main_menu.tick(),
|
||||
//.game => game.tick(),
|
||||
//};
|
||||
current_state = switch (current_state) {
|
||||
.main_menu => main_menu.tick(),
|
||||
.game => game.tick(),
|
||||
};
|
||||
|
||||
renderer.render();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue