-
Notifications
You must be signed in to change notification settings - Fork 0
/
definitions.go
112 lines (86 loc) · 2.32 KB
/
definitions.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"math/rand"
"github.com/gen2brain/raylib-go/raylib"
)
type UpdateFunction func(*GameState, float32)
type RenderFunction func(*GameState)
type InputFunction func(*GameState, float32)
type OptionSelectedCallback func(*GameState)
type MenuOptionData struct {
Name string
Callback OptionSelectedCallback
}
type GameState struct {
// App state
Update UpdateFunction
Render RenderFunction
Running bool
// Main game stuff
LeftPaddle rl.Rectangle
RightPaddle rl.Rectangle
Ball rl.Rectangle
LeftInput InputFunction
LeftPlayerHuman bool
RightInput InputFunction
RightPlayerHuman bool
BallDirection rl.Vector2
LeftScore int32
RightScore int32
SelectedPauseMenuOption int
PauseMenuOptions [2]MenuOptionData
// Menu stuff
SelectedMainMenuOption int
MainMenuOptions [3]MenuOptionData
}
const PaddleWidth = 15
const PaddleHeight = 75
const BallWidth = 25
const BallHeight = 25
const ScoreFontSize = 85
const TextScoreSpacing = 30
const WindowWidth int32 = 1200
const WindowHeight int32 = 600
const PaddleSpeed float32 = float32(WindowHeight) * 0.35 // [px/s] Paddle speed as a percentage of the screen height
const BallSpeed float32 = float32(WindowWidth) * 0.45
const GameWonScore int32 = 5
const (
None = iota
TopCollision = iota
LeftCollision = iota
BottomCollision = iota
RightCollision = iota
)
//Sounds
const (
SFX_PaddleHit = iota
SFX_WallHit = iota
SFX_Goal = iota
SFX_OptionMove = iota
SFX_OptionSelect = iota
SFX_MAX = iota
)
var SFX_Resources [SFX_MAX]string = [SFX_MAX]string{
"assets/ball_paddle_hit.wav",
"assets/wall_hit.wav",
"assets/goal.wav",
"assets/option_move.wav",
"assets/option_selected.wav",
}
var SFX_Sounds [SFX_MAX]rl.Sound
var Random *rand.Rand
var InitialLeftPaddle rl.Rectangle = rl.Rectangle{
X: 20 + PaddleWidth,
Y: float32(WindowHeight-PaddleHeight) / 2.0,
Width: PaddleWidth,
Height: PaddleHeight}
var InitialRightPaddle rl.Rectangle = rl.Rectangle{
X: float32(WindowWidth) - 20 - 2*PaddleWidth,
Y: float32(WindowHeight-PaddleHeight) / 2.0,
Width: PaddleWidth,
Height: PaddleHeight}
var InitialBall = rl.Rectangle{
X: float32(WindowWidth-BallWidth) / 2.0,
Y: float32(WindowHeight-BallHeight) / 2.0,
Width: BallWidth,
Height: BallHeight}