Arkadodge/menu.odin

83 lines
1.6 KiB
Odin
Raw Normal View History

2024-09-04 22:43:27 +03:00
package main
import rl "vendor:raylib"
2024-09-09 00:18:35 +03:00
import "core:math/ease"
2024-09-04 22:43:27 +03:00
2024-09-09 00:18:35 +03:00
Menu_Buttons :: enum {
START,
HOW_TO_PLAY,
EXIT
}
menu_strings := [Menu_Buttons]cstring {
.START = "Старт",
.HOW_TO_PLAY = "Как играть?",
.EXIT = "Выход"
}
2024-09-04 22:43:27 +03:00
Menu :: struct {
using state: GameState,
2024-09-09 00:18:35 +03:00
2024-09-09 17:48:24 +03:00
list: MenuList(Menu_Buttons),
2024-09-09 00:18:35 +03:00
}
menu_init :: proc(prev: ^GameState = nil) -> ^GameState {
state := new(Menu)
state.variant = state
2024-09-09 17:48:24 +03:00
state.list = MenuList(Menu_Buttons){
state = state,
2024-09-09 23:41:16 +03:00
position = {100, WINDOWF.y / 2},
2024-09-09 17:48:24 +03:00
line_size = 60,
font_size = 48,
2024-09-09 17:48:24 +03:00
elements = &menu_strings,
menu_pressed = menu_button_pressed,
background = rl.Color{50, 10, 110, 255}
2024-09-09 17:48:24 +03:00
}
2024-09-09 00:18:35 +03:00
state.update = menu_update
state.draw = menu_draw
state.free = menu_free
state.previous = prev
return state
}
menu_update :: proc(state: ^GameState, delta: f32) {
menu := transmute(^Menu)state
2024-09-09 23:41:16 +03:00
menu.list.position.y = WINDOWF.y / 2
2024-09-09 17:48:24 +03:00
menu_list_update(&menu.list)
}
2024-09-09 00:18:35 +03:00
2024-09-09 17:48:24 +03:00
menu_button_pressed :: proc(state: ^GameState, el: Menu_Buttons) {
switch el {
case .START:
game := game_init(state)
stack_push(game)
case .HOW_TO_PLAY:
2024-09-09 23:41:16 +03:00
howtoplay := howtoplay_init(state)
stack_push(howtoplay)
2024-09-09 17:48:24 +03:00
case .EXIT:
WindowShouldExit = true
return
2024-09-09 00:18:35 +03:00
}
}
menu_draw :: proc(state: ^GameState) {
menu := transmute(^Menu)state
TitleFontSize :: 96
TitleSpacing :: 3
TitleText :: "ARKADODGE"
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
rl.DrawTextPro(FontTitle, "ARKADODGE", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
2024-09-09 17:48:24 +03:00
menu_list_draw(&menu.list)
2024-09-09 00:18:35 +03:00
}
menu_free :: proc(state: ^GameState) {
free(state)
2024-09-04 22:43:27 +03:00
}