104 lines
2.4 KiB
Odin
104 lines
2.4 KiB
Odin
package main
|
|
|
|
import rl "vendor:raylib"
|
|
import "core:math/ease"
|
|
|
|
|
|
Menu_Buttons :: enum {
|
|
START,
|
|
HOW_TO_PLAY,
|
|
FULLSCREEN,
|
|
EXIT
|
|
}
|
|
|
|
menu_strings := [Menu_Buttons]cstring {
|
|
.START = "Старт",
|
|
.HOW_TO_PLAY = "Как играть?",
|
|
.FULLSCREEN = "Полный экран",
|
|
.EXIT = "Выход"
|
|
}
|
|
|
|
Menu :: struct {
|
|
using state: GameState,
|
|
|
|
menu_pos: Vec2,
|
|
menu_element_offset: f32,
|
|
active_element: Menu_Buttons,
|
|
active_marker: Vec2,
|
|
marker_tween: ^Tween,
|
|
}
|
|
|
|
menu_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
|
state := new(Menu)
|
|
state.variant = state
|
|
state.menu_pos = {300, 300}
|
|
state.menu_element_offset = 60
|
|
state.active_marker = state.menu_pos + Vec2{0, f32(state.active_element) * state.menu_element_offset}
|
|
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
|
|
|
|
prev_element := cast(i8)menu.active_element
|
|
cur_element := prev_element
|
|
|
|
if rl.IsKeyPressed(rl.KeyboardKey.DOWN) {
|
|
cur_element += 1
|
|
}
|
|
if rl.IsKeyPressed(rl.KeyboardKey.UP) {
|
|
cur_element -= 1
|
|
}
|
|
if prev_element != cur_element {
|
|
if cur_element < 0 { cur_element = len(Menu_Buttons) -1 }
|
|
if cur_element == len(Menu_Buttons) { cur_element = 0 }
|
|
menu.active_element = cast(Menu_Buttons)cur_element
|
|
if menu.marker_tween != nil {
|
|
tween_cancel(menu.marker_tween)
|
|
}
|
|
menu.marker_tween = tween_to(
|
|
&menu.active_marker.y,
|
|
menu.menu_pos.y + f32(menu.active_element) * menu.menu_element_offset,
|
|
0.5,
|
|
ease.Ease.Back_Out,
|
|
)
|
|
}
|
|
if rl.IsKeyPressed(rl.KeyboardKey.ENTER) || rl.IsKeyPressed(rl.KeyboardKey.SPACE) {
|
|
switch menu.active_element {
|
|
case .START:
|
|
game := game_init(state)
|
|
stack_push(game)
|
|
case .FULLSCREEN:
|
|
case .HOW_TO_PLAY:
|
|
case .EXIT:
|
|
WindowShouldExit = true
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
|
|
rl.DrawTextEx(FontUI, ">", menu.active_marker + {-30, 0}, 48, 2, rl.WHITE)
|
|
for el, i in menu_strings {
|
|
pos := menu.menu_pos + {0, f32(i) * menu.menu_element_offset}
|
|
rl.DrawTextEx(FontUI, el, pos, 48, 2, rl.WHITE)
|
|
}
|
|
}
|
|
|
|
menu_free :: proc(state: ^GameState) {
|
|
free(state)
|
|
}
|