Compare commits
No commits in common. "master" and "Sineys" have entirely different histories.
|
@ -1,3 +0,0 @@
|
||||||
[submodule "ntween"]
|
|
||||||
path = ntween
|
|
||||||
url = https://git.nefrace.ru/nefrace/ntween.git
|
|
|
@ -1,8 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:math/ease"
|
|
||||||
import "ntween"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
import "core:math/ease"
|
||||||
|
|
||||||
|
|
||||||
GameOver :: struct {
|
GameOver :: struct {
|
||||||
|
@ -22,15 +21,7 @@ gameover_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
state.free = gameover_free
|
state.free = gameover_free
|
||||||
|
|
||||||
state.previous = prev
|
state.previous = prev
|
||||||
ntween.animate(
|
tween_to(&state.position.y, WINDOWF.y / 2, 1, ease.Ease.Back_Out, state, gameover_ready)
|
||||||
&v2tween,
|
|
||||||
&state.position,
|
|
||||||
WINDOWF.y,
|
|
||||||
1,
|
|
||||||
ease.Ease.Back_Out,
|
|
||||||
state,
|
|
||||||
gameover_ready,
|
|
||||||
)
|
|
||||||
|
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
@ -64,11 +55,7 @@ gameover_draw :: proc(state: ^GameState) {
|
||||||
TitleText :: "ИГРА ОКОНЧЕНА"
|
TitleText :: "ИГРА ОКОНЧЕНА"
|
||||||
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
||||||
|
|
||||||
SubtitleText := [3]cstring {
|
SubtitleText := [3]cstring{"Нажмите Enter", "чтобы начать сначала", "Или Escape для выхода"}
|
||||||
"Нажмите Enter",
|
|
||||||
"чтобы начать сначала",
|
|
||||||
"Или Escape для выхода",
|
|
||||||
}
|
|
||||||
SubtitleFontSize :: 48
|
SubtitleFontSize :: 48
|
||||||
SubtitleSpacing :: 2
|
SubtitleSpacing :: 2
|
||||||
SubtitleSizes := [3]Vec2{}
|
SubtitleSizes := [3]Vec2{}
|
||||||
|
@ -77,33 +64,11 @@ gameover_draw :: proc(state: ^GameState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rl.DrawRectangleV(
|
rl.DrawRectangleV(gameover.position - gameover.size / 2, gameover.size, rl.Color{90, 30, 150, 255})
|
||||||
gameover.position - gameover.size / 2,
|
|
||||||
gameover.size,
|
|
||||||
rl.Color{90, 30, 150, 255},
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.DrawTextPro(
|
rl.DrawTextPro(FontTitle, TitleText, gameover.position - {0, 100}, TitleSize / 2, 0, TitleFontSize, TitleSpacing, rl.WHITE)
|
||||||
FontTitle,
|
|
||||||
TitleText,
|
|
||||||
gameover.position - {0, 100},
|
|
||||||
TitleSize / 2,
|
|
||||||
0,
|
|
||||||
TitleFontSize,
|
|
||||||
TitleSpacing,
|
|
||||||
rl.WHITE,
|
|
||||||
)
|
|
||||||
for c, i in SubtitleText {
|
for c, i in SubtitleText {
|
||||||
rl.DrawTextPro(
|
rl.DrawTextPro(FontUI, c, gameover.position - {0, f32(10 - i * 50)}, SubtitleSizes[i] / 2, 0, SubtitleFontSize, SubtitleSpacing, rl.WHITE)
|
||||||
FontUI,
|
|
||||||
c,
|
|
||||||
gameover.position - {0, f32(10 - i * 50)},
|
|
||||||
SubtitleSizes[i] / 2,
|
|
||||||
0,
|
|
||||||
SubtitleFontSize,
|
|
||||||
SubtitleSpacing,
|
|
||||||
rl.WHITE,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,4 +82,3 @@ gameover_ready :: proc(state: rawptr) {
|
||||||
gameover := transmute(^GameOver)state
|
gameover := transmute(^GameOver)state
|
||||||
gameover.ready_to_go = true
|
gameover.ready_to_go = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:math/ease"
|
|
||||||
import "ntween"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
import "core:math/ease"
|
||||||
|
|
||||||
|
|
||||||
LevelDone :: struct {
|
LevelDone :: struct {
|
||||||
|
@ -22,15 +21,7 @@ leveldone_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
state.free = leveldone_free
|
state.free = leveldone_free
|
||||||
|
|
||||||
state.previous = prev
|
state.previous = prev
|
||||||
ntween.animate(
|
tween_to(&state.position.y, WINDOWF.y / 2, 1, ease.Ease.Back_Out, state, leveldone_ready)
|
||||||
&v2tween,
|
|
||||||
&state.position,
|
|
||||||
WINDOWF / 2,
|
|
||||||
1,
|
|
||||||
ease.Ease.Back_Out,
|
|
||||||
state,
|
|
||||||
leveldone_ready,
|
|
||||||
)
|
|
||||||
|
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
@ -71,32 +62,10 @@ leveldone_draw :: proc(state: ^GameState) {
|
||||||
SubtitleSize := rl.MeasureTextEx(FontUI, SubtitleText, SubtitleFontSize, SubtitleSpacing)
|
SubtitleSize := rl.MeasureTextEx(FontUI, SubtitleText, SubtitleFontSize, SubtitleSpacing)
|
||||||
|
|
||||||
|
|
||||||
rl.DrawRectangleV(
|
rl.DrawRectangleV(leveldone.position - leveldone.size / 2, leveldone.size, rl.Color{90, 30, 150, 255})
|
||||||
leveldone.position - leveldone.size / 2,
|
|
||||||
leveldone.size,
|
|
||||||
rl.Color{90, 30, 150, 255},
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.DrawTextPro(
|
rl.DrawTextPro(FontTitle, TitleText, leveldone.position - {0, 50}, TitleSize / 2, 0, TitleFontSize, TitleSpacing, rl.WHITE)
|
||||||
FontTitle,
|
rl.DrawTextPro(FontUI, SubtitleText, leveldone.position + {0, 20}, SubtitleSize / 2, 0, SubtitleFontSize, SubtitleSpacing, rl.WHITE)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,4 +77,3 @@ leveldone_ready :: proc(state: rawptr) {
|
||||||
leveldone := transmute(^LevelDone)state
|
leveldone := transmute(^LevelDone)state
|
||||||
leveldone.ready_to_go = true
|
leveldone.ready_to_go = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
main.odin
24
main.odin
|
@ -1,10 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
|
||||||
import "core:slice"
|
|
||||||
import "ntween"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
import rlgl "vendor:raylib/rlgl"
|
import rlgl "vendor:raylib/rlgl"
|
||||||
|
import "core:slice"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
import "core:math/ease"
|
import "core:math/ease"
|
||||||
|
|
||||||
|
@ -19,23 +18,15 @@ FontUI: rl.Font
|
||||||
|
|
||||||
WindowShouldExit := false
|
WindowShouldExit := false
|
||||||
|
|
||||||
f32tween: ntween.Tween_Map(f32)
|
|
||||||
v2tween: ntween.Tween_Map(Vec2)
|
|
||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
rl.SetConfigFlags(rl.ConfigFlags{.FULLSCREEN_MODE, .VSYNC_HINT})
|
rl.SetConfigFlags(rl.ConfigFlags{.FULLSCREEN_MODE, .VSYNC_HINT, })
|
||||||
monitor := rl.GetCurrentMonitor()
|
monitor := rl.GetCurrentMonitor()
|
||||||
rl.InitWindow(0, 0, "SinePong")
|
rl.InitWindow(0, 0, "SinePong")
|
||||||
rl.SetTargetFPS(9999)
|
rl.SetTargetFPS(9999)
|
||||||
|
|
||||||
|
|
||||||
f32tween = ntween.init(f32)
|
tween_init()
|
||||||
v2tween = ntween.init(Vec2)
|
defer tween_clean()
|
||||||
defer {
|
|
||||||
ntween.destroy_tweens(&f32tween)
|
|
||||||
ntween.destroy_tweens(&v2tween)
|
|
||||||
}
|
|
||||||
|
|
||||||
FontUI = rl.LoadFontEx("assets/monogram-extended.ttf", 96, nil, 2048)
|
FontUI = rl.LoadFontEx("assets/monogram-extended.ttf", 96, nil, 2048)
|
||||||
// FontUI = rl.LoadFont("assets/monogram-extended.ttf")
|
// FontUI = rl.LoadFont("assets/monogram-extended.ttf")
|
||||||
|
@ -71,8 +62,7 @@ main :: proc() {
|
||||||
current_state := state_stack[len(state_stack)-1]
|
current_state := state_stack[len(state_stack)-1]
|
||||||
|
|
||||||
delta := rl.GetFrameTime()
|
delta := rl.GetFrameTime()
|
||||||
ntween.process(&f32tween, delta)
|
tweens_process(delta)
|
||||||
ntween.process(&v2tween, delta)
|
|
||||||
|
|
||||||
current_state->update(delta)
|
current_state->update(delta)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +76,7 @@ main :: proc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
@ -101,4 +92,3 @@ main :: proc() {
|
||||||
[ ] Звуки
|
[ ] Звуки
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:fmt"
|
|
||||||
import "core:math/ease"
|
|
||||||
import "ntween"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
import "core:math/ease"
|
||||||
|
import "core:fmt"
|
||||||
|
|
||||||
MenuList :: struct($T: typeid) {
|
MenuList :: struct($T: typeid) {
|
||||||
state: ^GameState,
|
state: ^GameState,
|
||||||
|
@ -12,7 +11,7 @@ MenuList :: struct($T: typeid) {
|
||||||
font_size: f32,
|
font_size: f32,
|
||||||
active_element: T,
|
active_element: T,
|
||||||
active_marker: Vec2,
|
active_marker: Vec2,
|
||||||
tween: ^ntween.Tween(f32),
|
tween: ^Tween,
|
||||||
elements: ^[T]cstring,
|
elements: ^[T]cstring,
|
||||||
menu_pressed: proc(state: ^GameState, element: T),
|
menu_pressed: proc(state: ^GameState, element: T),
|
||||||
background: rl.Color,
|
background: rl.Color,
|
||||||
|
@ -30,10 +29,12 @@ menu_list_update :: proc(list: ^MenuList($T)) {
|
||||||
list.mouse_pos = rl.GetMousePosition()
|
list.mouse_pos = rl.GetMousePosition()
|
||||||
|
|
||||||
size := menu_list_get_size(list)
|
size := menu_list_get_size(list)
|
||||||
if rl.CheckCollisionPointRec(
|
if rl.CheckCollisionPointRec(list.mouse_pos, rl.Rectangle{
|
||||||
list.mouse_pos,
|
x = list.position.x,
|
||||||
rl.Rectangle{x = list.position.x, y = list.position.y, width = size.x, height = size.y},
|
y = list.position.y,
|
||||||
) {
|
width = size.x,
|
||||||
|
height = size.y,
|
||||||
|
}) {
|
||||||
if last_mouse_pos != list.mouse_pos {
|
if last_mouse_pos != list.mouse_pos {
|
||||||
mouse_relative := list.mouse_pos - list.position
|
mouse_relative := list.mouse_pos - list.position
|
||||||
cur_element = i8(mouse_relative.y / list.line_size)
|
cur_element = i8(mouse_relative.y / list.line_size)
|
||||||
|
@ -46,6 +47,7 @@ menu_list_update :: proc(list: ^MenuList($T)) {
|
||||||
last_mouse_pos = list.mouse_pos
|
last_mouse_pos = list.mouse_pos
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyboardKey.DOWN) {
|
if rl.IsKeyPressed(rl.KeyboardKey.DOWN) {
|
||||||
cur_element += 1
|
cur_element += 1
|
||||||
}
|
}
|
||||||
|
@ -57,10 +59,9 @@ menu_list_update :: proc(list: ^MenuList($T)) {
|
||||||
if cur_element == len(T) { cur_element = 0 }
|
if cur_element == len(T) { cur_element = 0 }
|
||||||
list.active_element = cast(T)cur_element
|
list.active_element = cast(T)cur_element
|
||||||
if list.tween != nil {
|
if list.tween != nil {
|
||||||
ntween.cancel(list.tween)
|
tween_cancel(list.tween)
|
||||||
}
|
}
|
||||||
list.tween = ntween.animate(
|
list.tween = tween_to(
|
||||||
&f32tween,
|
|
||||||
&list.active_marker.y,
|
&list.active_marker.y,
|
||||||
f32(list.active_element) * list.line_size,
|
f32(list.active_element) * list.line_size,
|
||||||
0.25,
|
0.25,
|
||||||
|
@ -96,4 +97,3 @@ menu_list_get_size :: proc(list: ^MenuList($T)) -> Vec2 {
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
ntween
1
ntween
|
@ -1 +0,0 @@
|
||||||
Subproject commit 7136c68f3e63470b9b1c80109dd0904151e08070
|
|
24
pause.odin
24
pause.odin
|
@ -1,23 +1,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "core:math/ease"
|
|
||||||
import "ntween"
|
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
import "core:math/ease"
|
||||||
|
|
||||||
|
|
||||||
Pause_Buttons :: enum {
|
Pause_Buttons :: enum {
|
||||||
RESUME,
|
RESUME,
|
||||||
EXIT,
|
EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
pause_strings := [Pause_Buttons]cstring {
|
pause_strings := [Pause_Buttons]cstring {
|
||||||
.RESUME = "Продолжить",
|
.RESUME = "Продолжить",
|
||||||
.EXIT = "Выход",
|
.EXIT = "Выход"
|
||||||
}
|
}
|
||||||
|
|
||||||
Pause :: struct {
|
Pause :: struct {
|
||||||
using state: GameState,
|
using state: GameState,
|
||||||
list: MenuList(Pause_Buttons),
|
|
||||||
|
list: MenuList(Pause_Buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
|
@ -35,7 +35,7 @@ pause_init :: proc(prev: ^GameState = nil) -> ^GameState {
|
||||||
state.draw = pause_draw
|
state.draw = pause_draw
|
||||||
state.free = pause_free
|
state.free = pause_free
|
||||||
state.previous = prev
|
state.previous = prev
|
||||||
ntween.animate(&f32tween, &state.list.position.x, 300, 1, ease.Ease.Back_Out)
|
tween_to(&state.list.position.x, 300, 1, ease.Ease.Back_Out)
|
||||||
|
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
@ -72,16 +72,7 @@ pause_draw :: proc(state: ^GameState) {
|
||||||
TitleSpacing :: 3
|
TitleSpacing :: 3
|
||||||
TitleText :: "ПАУЗА"
|
TitleText :: "ПАУЗА"
|
||||||
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
TitleSize := rl.MeasureTextEx(FontTitle, TitleText, TitleFontSize, TitleSpacing)
|
||||||
rl.DrawTextPro(
|
rl.DrawTextPro(FontTitle, "ПАУЗА", {WINDOWF.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)
|
||||||
FontTitle,
|
|
||||||
"ПАУЗА",
|
|
||||||
{WINDOWF.x - 50, 50},
|
|
||||||
{TitleSize.x, 0},
|
|
||||||
0,
|
|
||||||
96,
|
|
||||||
3,
|
|
||||||
rl.WHITE,
|
|
||||||
)
|
|
||||||
|
|
||||||
menu_list_draw(&menu.list)
|
menu_list_draw(&menu.list)
|
||||||
}
|
}
|
||||||
|
@ -90,4 +81,3 @@ pause_free :: proc(state: ^GameState) {
|
||||||
pause := transmute(^Pause)state
|
pause := transmute(^Pause)state
|
||||||
free(state)
|
free(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "core:math"
|
||||||
|
import "core:math/ease"
|
||||||
|
import "core:math/linalg"
|
||||||
|
import "core:slice"
|
||||||
|
|
||||||
|
|
||||||
|
Tween :: struct {
|
||||||
|
ptr: ^f32,
|
||||||
|
from: f32,
|
||||||
|
to: f32,
|
||||||
|
time: f32,
|
||||||
|
duration: f32,
|
||||||
|
ease_type: ease.Ease,
|
||||||
|
active: bool,
|
||||||
|
finished: proc(data: rawptr),
|
||||||
|
data: rawptr
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TWEEN_SIZE :: 128
|
||||||
|
tweens_buf: [TWEEN_SIZE]^Tween
|
||||||
|
tweens : [dynamic]^Tween
|
||||||
|
|
||||||
|
tween_init :: proc() {
|
||||||
|
tweens = slice.into_dynamic(tweens_buf[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
tween_clean :: proc() {
|
||||||
|
for tween, i in tweens {
|
||||||
|
free(tween)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tween_to :: proc(
|
||||||
|
value: ^f32, to: f32, duration: f32,
|
||||||
|
ease: ease.Ease = ease.Ease.Quartic_In_Out,
|
||||||
|
data: rawptr = nil,
|
||||||
|
callback: proc(data: rawptr) = nil
|
||||||
|
) -> ^Tween {
|
||||||
|
|
||||||
|
tween := new(Tween)
|
||||||
|
tween.ptr = value
|
||||||
|
tween.from = value^
|
||||||
|
tween.to = to
|
||||||
|
tween.duration = duration
|
||||||
|
tween.ease_type = ease
|
||||||
|
tween.active = true
|
||||||
|
tween.data = data
|
||||||
|
tween.finished = callback
|
||||||
|
|
||||||
|
append(&tweens, tween)
|
||||||
|
return tween
|
||||||
|
}
|
||||||
|
|
||||||
|
tween_cancel :: proc(t: ^Tween) {
|
||||||
|
t.active = false
|
||||||
|
}
|
||||||
|
|
||||||
|
tweens_process :: proc(delta: f32) {
|
||||||
|
#reverse for tween, i in tweens {
|
||||||
|
|
||||||
|
tween.time += delta
|
||||||
|
p := clamp(tween.time / tween.duration, 0, 1)
|
||||||
|
|
||||||
|
val := ease.ease(tween.ease_type, p)
|
||||||
|
if tween.ptr != nil {
|
||||||
|
tween.ptr^ = math.lerp(tween.from, tween.to, val)
|
||||||
|
} else {
|
||||||
|
tween.active = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if tween.time >= tween.duration {
|
||||||
|
tween.active = false
|
||||||
|
if tween.finished != nil {
|
||||||
|
tween.finished(tween.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !tween.active {
|
||||||
|
free(tween)
|
||||||
|
unordered_remove(&tweens, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue