-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (66 loc) · 1.92 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
package main
import (
"math/rand"
"time"
"github.com/gen2brain/raylib-go/raylib"
)
/* Game state updates */
func init_game() GameState {
rl.InitAudioDevice()
for i := 0; i < SFX_MAX; i++ {
SFX_Sounds[i] = rl.LoadSound(SFX_Resources[i])
}
rl.SetMasterVolume(0.75)
return GameState{
Update: menu_update,
Render: menu_render,
Running: true,
LeftPaddle: InitialLeftPaddle,
RightPaddle: InitialRightPaddle,
Ball: InitialBall,
BallDirection: vec2_from_angle(0),
LeftScore: 0,
RightScore: 0,
LeftInput: left_player_input,
LeftPlayerHuman: true,
RightInput: right_ai_input,
RightPlayerHuman: false,
SelectedPauseMenuOption: 0,
PauseMenuOptions: [2]MenuOptionData{
{Name: "Continue", Callback: on_continue},
{Name: "Quit", Callback: on_return_to_main_menu},
},
SelectedMainMenuOption: 0,
MainMenuOptions: [3]MenuOptionData{
{Name: "Player vs AI", Callback: on_player_vs_ai},
{Name: "Player vs Player", Callback: on_player_vs_player},
{Name: "Quit", Callback: on_quit},
}}
}
/* Entry Point */
func main() {
var RandSource = rand.NewSource(time.Now().UnixNano())
Random = rand.New(RandSource)
rl.InitWindow(WindowWidth, WindowHeight, "gong")
rl.SetExitKey(0)
//rl.SetTargetFPS(60)
var GS GameState = init_game()
restart_game(&GS)
for !rl.WindowShouldClose() && GS.Running {
var DeltaTime float32 = rl.GetFrameTime() // [s] frame time
/* Game Logic */
GS.Update(&GS, DeltaTime)
/* Rendering */
{
rl.BeginDrawing()
rl.ClearBackground(rl.Black)
GS.Render(&GS)
// Debugging
//rl.DrawLine(0, WindowHeight/2, WindowWidth, WindowHeight/2, rl.Gray)
//rl.DrawLine(WindowWidth/2, 0, WindowWidth/2, WindowHeight, rl.Gray)
//rl.DrawText(fmt.Sprintf("%.03f ms", DeltaTime*1000), 10, 10, 25, rl.Red)
rl.EndDrawing()
}
}
rl.CloseWindow()
}