-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.go
More file actions
123 lines (104 loc) · 3.3 KB
/
game.go
File metadata and controls
123 lines (104 loc) · 3.3 KB
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
package egriden
import (
"github.com/greenthepear/imggg"
"github.com/hajimehoshi/ebiten/v2"
)
// Egriden components to be embedded in your Game{} struct.
type EgridenAssets struct {
Levels []Level
CurrentLevelIndex int
}
// Get the current level, returns nil if there are no levels. Index starts at
// 0 so the first level added will be returned if
// (EgridenAssets).CurrentLevelIndex was not changed
func (g *EgridenAssets) Level() Level {
if g.CurrentLevelIndex >= len(g.Levels) {
return nil
}
return g.Levels[g.CurrentLevelIndex]
}
// Get a level by it's name. Returns nil if not found.
func (g *EgridenAssets) LevelByName(name string) Level {
for _, le := range g.Levels {
if le.Name() == name {
return le
}
}
return nil
}
// Append level to the end of the list and return it
func (g *EgridenAssets) AddLevel(le Level) Level {
g.Levels = append(g.Levels, le)
idx := len(g.Levels) - 1
le.setIndex(idx)
return g.Levels[idx]
}
// Sets the current game's level or adds it if it's not in the assets already
func (g *EgridenAssets) SetLevelTo(le Level) {
for i, rangeLe := range g.Levels {
if rangeLe == le {
g.CurrentLevelIndex = i
return
}
}
//If not found, add that level I guess
g.AddLevel(le)
g.CurrentLevelIndex = len(g.Levels) - 1
}
// Set the next level by iterating the level index
func (g *EgridenAssets) NextLevel() {
g.CurrentLevelIndex = (g.CurrentLevelIndex + 1) % len(g.Levels)
}
/// Deprecated
// Shorthand for [Level.CreateSimpleGridLayerOnTop]
// for the current level
//
// Deprecated: Just use CreateGridLayerOnTop.
func (g *EgridenAssets) CreateSimpleGridLayerOnTop(
name string, squareLength int, width, height int,
drawMode DrawMode, XOffset, YOffset float64) *GridLayer {
return g.Level().CreateSimpleGridLayerOnTop(
name, squareLength, width, height, drawMode, XOffset, YOffset)
}
// Shorthand for [Level.CreateGridLayerOnTop]
// for the current level
//
// Deprecated: Use method directly from Level
func (g *EgridenAssets) CreateGridLayerOnTop(
name string, params GridLayerParameters) *GridLayer {
return g.Level().CreateGridLayerOnTop(name, params)
}
// Run this while initializing the game, before adding any layers. Creates a
// level called `Default`
//
// Deprecated: just use g.AddLevel(NewBaseLevel("Default"))
func (g *EgridenAssets) InitEgridenAssets() {
g.AddLevel(NewBaseLevel("Default"))
}
// Returns a GridLayer at z in the current Level, returns nil if out of bounds.
//
// Deprecated: Use method directly from Level
func (g EgridenAssets) GridLayer(z int) *GridLayer {
return g.Level().GridLayer(z)
}
// Draw all GridLayers of the current Level in their Z order.
//
// Deprecated: Use method directly from Level
func (g EgridenAssets) DrawAllGridLayers(on *ebiten.Image) {
g.Level().DrawAllGridLayers(on)
}
// Draw all free layers of the current Level in their Z order.
//
// Deprecated: Use method directly from Level
func (g EgridenAssets) DrawAllFreeLayers(on *ebiten.Image) {
g.Level().DrawAllFreeLayers(on)
}
// Shortcut for g.Level().CreateFreeLayerOnTop().
// Level implementation must have BaseLevel component.
//
// Deprecated: Use method directly from Level
func (g *EgridenAssets) CreateFreeLayerOnTop(
name string, xOffset, yOffset float64) *FreeLayer {
return g.Level().CreateFreeLayerOnTop(name,
imggg.Point[float64]{X: xOffset, Y: yOffset})
}