-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.go
132 lines (118 loc) · 2.5 KB
/
game.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package kar
import (
"reflect"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Game struct {
Spawn *Spawn
Platform *Platform
Enemy *Enemy
Player *Player
Item *Item
Effects *Effects
Camera *Camera
Ui *UI
MainMenu *MainMenu
Menu *Menu
Debug *Debug
Projectile *Projectile
}
func (g *Game) Init() {
g.Spawn = &Spawn{}
g.Platform = &Platform{}
g.Enemy = &Enemy{}
g.Player = &Player{}
g.Item = &Item{}
g.Effects = &Effects{}
g.Camera = &Camera{}
g.Ui = &UI{}
g.MainMenu = &MainMenu{}
g.Menu = &Menu{}
g.Debug = &Debug{}
g.Projectile = &Projectile{}
// Initalize systems
val := reflect.ValueOf(g).Elem()
for i := range val.NumField() {
val.Field(i).MethodByName("Init").Call(nil)
}
colorM.ChangeHSV(1, 0, 0.5) // BW
textDO.ColorScale.Scale(0.5, 0.5, 0.5, 1)
}
func (g *Game) Update() error {
if ebiten.IsFocused() {
if inpututil.IsKeyJustPressed(ebiten.KeyP) {
if ebiten.IsKeyPressed(ebiten.KeyMeta) && ebiten.IsKeyPressed(ebiten.KeyShift) {
debugEnabled = !debugEnabled
}
}
// toggle menu
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
switch currentGameState {
case "menu":
currentGameState = "playing"
// previousGameState = "menu"
colorM.Reset()
textDO.ColorScale.Reset()
case "playing":
currentGameState = "menu"
// previousGameState = "playing"
colorM.ChangeHSV(1, 0, 0.5) // BW
textDO.ColorScale.Scale(0.5, 0.5, 0.5, 1)
}
}
// Update systems
switch currentGameState {
case "mainmenu":
g.MainMenu.Update()
case "menu":
g.Menu.Update()
case "playing":
g.Camera.Update()
g.Enemy.Update()
g.Player.Update()
g.Platform.Update()
g.Item.Update()
g.Effects.Update()
g.Ui.Update()
g.Projectile.Update()
g.Spawn.Update()
}
if debugEnabled {
g.Debug.Update()
}
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
if ebiten.IsFocused() {
Screen = screen
Screen.Fill(backgroundColor)
// Update systems
switch currentGameState {
case "mainmenu":
g.MainMenu.Draw()
case "menu":
g.Camera.Draw()
g.Menu.Draw()
case "playing":
g.Camera.Draw()
g.Platform.Draw()
g.Enemy.Draw()
g.Player.Draw()
g.Item.Draw()
g.Projectile.Draw()
g.Effects.Draw()
g.Ui.Draw()
}
if debugEnabled {
g.Debug.Draw()
}
}
}
func (g *Game) LayoutF(w, h float64) (float64, float64) {
return ScreenSize.X, ScreenSize.Y
}
func (g *Game) Layout(w, h int) (int, int) {
return 0, 0
}