Arkadodge/gameover.odin

121 lines
2.2 KiB
Odin

package main
import "core:math/ease"
import "ntween"
import rl "vendor:raylib"
GameOver :: struct {
using state: GameState,
position: Vec2,
size: Vec2,
ready_to_go: bool,
}
gameover_init :: proc(prev: ^GameState = nil) -> ^GameState {
state := new(GameOver)
state.variant = state
state.position = Vec2{WINDOWF.x / 2, WINDOWF.y + 300}
state.size = {700, 500}
state.update = gameover_update
state.draw = gameover_draw
state.free = gameover_free
state.previous = prev
ntween.animate(
&v2tween,
&state.position,
WINDOWF.y,
1,
ease.Ease.Back_Out,
state,
gameover_ready,
)
return state
}
gameover_update :: proc(state: ^GameState, delta: f32) {
gameover := transmute(^GameOver)state
if gameover.ready_to_go {
if rl.IsKeyPressed(rl.KeyboardKey.ESCAPE) {
stack_pop()
stack_pop()
return
}
if rl.IsKeyPressed(rl.KeyboardKey.ENTER) {
stack_pop()
game := transmute(^Game)stack_top()
game_setup(game)
}
}
}
gameover_draw :: proc(state: ^GameState) {
gameover := transmute(^GameOver)state
if state.previous != nil {
state.previous->draw()
}
TitleFontSize :: 96
TitleSpacing :: 3
TitleText :: "ИГРА ОКОНЧЕНА"
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
SubtitleText := [3]cstring {
"Нажмите Enter",
"чтобы начать сначала",
"Или Escape для выхода",
}
SubtitleFontSize :: 48
SubtitleSpacing :: 2
SubtitleSizes := [3]Vec2{}
for c, i in SubtitleText {
SubtitleSizes = rl.MeasureTextEx(FontUI, c, SubtitleFontSize, SubtitleSpacing)
}
rl.DrawRectangleV(
gameover.position - gameover.size / 2,
gameover.size,
rl.Color{90, 30, 150, 255},
)
rl.DrawTextPro(
FontTitle,
TitleText,
gameover.position - {0, 100},
TitleSize / 2,
0,
TitleFontSize,
TitleSpacing,
rl.WHITE,
)
for c, i in SubtitleText {
rl.DrawTextPro(
FontUI,
c,
gameover.position - {0, f32(10 - i * 50)},
SubtitleSizes[i] / 2,
0,
SubtitleFontSize,
SubtitleSpacing,
rl.WHITE,
)
}
}
gameover_free :: proc(state: ^GameState) {
free(state)
}
gameover_ready :: proc(state: rawptr) {
gameover := transmute(^GameOver)state
gameover.ready_to_go = true
}