forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (69 loc) · 2.85 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"github.com/gen2brain/raylib-go/easings"
"github.com/gen2brain/raylib-go/raygui"
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.SetConfigFlags(rl.FlagVsyncHint)
rl.InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings")
currentTime := 0
duration := float32(60)
startPositionX := float32(screenWidth) / 4
finalPositionX := startPositionX * 3
currentPositionX := startPositionX
ballPosition := rl.NewVector2(startPositionX, float32(screenHeight)/2)
comboActive := 0
comboLastActive := 0
easingTypes := []string{"SineIn", "SineOut", "SineInOut", "BounceIn", "BounceOut", "BounceInOut", "BackIn", "BackOut", "BackInOut"}
ease := easingTypes[comboActive]
//rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
if rl.IsKeyDown(rl.KeyR) {
currentTime = 0
currentPositionX = startPositionX
ballPosition.X = currentPositionX
}
if comboLastActive != comboActive {
currentTime = 0
currentPositionX = startPositionX
ballPosition.X = currentPositionX
ease = easingTypes[comboActive]
comboLastActive = comboActive
}
if currentPositionX < finalPositionX {
switch ease {
case "SineIn":
currentPositionX = easings.SineIn(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "SineOut":
currentPositionX = easings.SineOut(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "SineInOut":
currentPositionX = easings.SineInOut(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "BounceIn":
currentPositionX = easings.BounceIn(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "BounceOut":
currentPositionX = easings.BounceOut(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "BounceInOut":
currentPositionX = easings.BounceInOut(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "BackIn":
currentPositionX = easings.BackIn(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "BackOut":
currentPositionX = easings.BackOut(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
case "BackInOut":
currentPositionX = easings.BackInOut(float32(currentTime), startPositionX, finalPositionX-startPositionX, duration)
}
ballPosition.X = currentPositionX
currentTime++
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
raygui.Label(rl.NewRectangle(20, 20, 200, 20), "Easing Type:")
comboActive = raygui.ComboBox(rl.NewRectangle(20, 40, 200, 20), easingTypes, comboActive)
raygui.Label(rl.NewRectangle(20, 80, 200, 20), "Press R to reset")
rl.DrawCircleV(ballPosition, 50, rl.Maroon)
rl.EndDrawing()
}
rl.CloseWindow()
}