Arkadodge/pause.odin

101 lines
2.3 KiB
Odin
Raw Normal View History

2024-09-09 00:18:35 +03:00
package main
import rl "vendor:raylib"
import "core:math/ease"
Pause_Buttons :: enum {
RESUME,
FULLSCREEN,
EXIT
}
pause_strings := [Pause_Buttons]cstring {
.RESUME = "Старт",
.FULLSCREEN = "Полный экран",
.EXIT = "Выход"
}
Pause :: struct {
using state: GameState,
menu_pos: Vec2,
menu_element_offset: f32,
active_element: Pause_Buttons,
active_marker: Vec2,
marker_tween: ^Tween,
}
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
state := new(Pause)
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
}
pause_update :: proc(state: ^GameState, delta: f32) {
menu := transmute(^Pause)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(Pause_Buttons) -1 }
if cur_element == len(Pause_Buttons) { cur_element = 0 }
menu.active_element = cast(Pause_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 .RESUME:
stack_pop()
case .FULLSCREEN:
case .EXIT:
stack_pop()
stack_pop()
}
}
}
pause_draw :: proc(state: ^GameState) {
menu := transmute(^Pause)state
TitleFontSize :: 96
TitleSpacing :: 3
TitleText :: "ПАУЗА"
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)
}
}
pause_free :: proc(state: ^GameState) {
free(state)
}