Arkadodge/leveldone.odin

112 lines
2.2 KiB
Odin
Raw Normal View History

2024-09-09 23:41:16 +03:00
package main
import "core:math/ease"
2024-11-04 22:26:42 +03:00
import "ntween"
import rl "vendor:raylib"
2024-09-09 23:41:16 +03:00
LevelDone :: struct {
using state: GameState,
2024-11-04 22:26:42 +03:00
position: Vec2,
size: Vec2,
2024-09-09 23:41:16 +03:00
ready_to_go: bool,
}
leveldone_init :: proc(prev: ^GameState = nil) -> ^GameState {
state := new(LevelDone)
state.variant = state
state.position = Vec2{WINDOWF.x / 2, WINDOWF.y + 300}
state.size = {800, 400}
state.update = leveldone_update
state.draw = leveldone_draw
state.free = leveldone_free
state.previous = prev
2024-11-04 22:26:42 +03:00
ntween.animate(
&v2tween,
&state.position,
WINDOWF / 2,
1,
ease.Ease.Back_Out,
state,
leveldone_ready,
)
2024-09-09 23:41:16 +03:00
return state
}
leveldone_update :: proc(state: ^GameState, delta: f32) {
leveldone := transmute(^LevelDone)state
if leveldone.ready_to_go {
if rl.IsKeyPressed(rl.KeyboardKey.ENTER) {
stack_pop()
game := transmute(^Game)stack_top()
game.levels_done += 1
if game.levels_done > 0 && game.levels_done % 2 == 0 {
game.levelsize += {2, 1}
game.levelsize.x = min(game.levelsize.x, 13)
game.levelsize.y = min(game.levelsize.y, 8)
}
game_gen_level(game)
}
}
}
leveldone_draw :: proc(state: ^GameState) {
leveldone := transmute(^LevelDone)state
if state.previous != nil {
state.previous->draw()
}
TitleFontSize :: 96
TitleSpacing :: 3
TitleText :: "УРОВЕНЬ ПРОЙДЕН"
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
SubtitleText :: "Нажмите Enter чтобы продолжить"
SubtitleFontSize :: 48
SubtitleSpacing :: 2
SubtitleSize := rl.MeasureTextEx(FontUI, SubtitleText, SubtitleFontSize, SubtitleSpacing)
2024-11-04 22:26:42 +03:00
rl.DrawRectangleV(
leveldone.position - leveldone.size / 2,
leveldone.size,
rl.Color{90, 30, 150, 255},
)
rl.DrawTextPro(
FontTitle,
TitleText,
leveldone.position - {0, 50},
TitleSize / 2,
0,
TitleFontSize,
TitleSpacing,
rl.WHITE,
)
rl.DrawTextPro(
FontUI,
SubtitleText,
leveldone.position + {0, 20},
SubtitleSize / 2,
0,
SubtitleFontSize,
SubtitleSpacing,
rl.WHITE,
)
2024-09-09 23:41:16 +03:00
}
leveldone_free :: proc(state: ^GameState) {
free(state)
}
leveldone_ready :: proc(state: rawptr) {
leveldone := transmute(^LevelDone)state
leveldone.ready_to_go = true
}
2024-11-04 22:26:42 +03:00