-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (58 loc) · 1.33 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
package main
import (
"github.com/bytearena/ecs"
_ "image/png"
"log"
"github.com/hajimehoshi/ebiten/v2"
)
type Game struct {
Map GameMap
World *ecs.Manager
WorldTags map[string]ecs.Tag
Turn TurnState
TurnCounter int
}
// NewGame creates a new Game Object and initializes the data
// This is a pretty solid refactor candidate for later
func NewGame() *Game {
g := &Game{}
g.Map = NewGameMap()
world, tags := InitializeWorld(g.Map.CurrentLevel)
g.WorldTags = tags
g.World = world
g.Turn = PlayerTurn
g.TurnCounter = 0
return g
}
// Update is called each tic.
func (g *Game) Update() error {
g.TurnCounter++
if g.Turn == PlayerTurn && g.TurnCounter > 20 {
MovePlayer(g)
}
if g.Turn == MonsterTurn {
UpdateMonster(g)
}
return nil
}
// Draw is called each draw cycle and is where we will blit.
func (g *Game) Draw(screen *ebiten.Image) {
//Draw the Map
level := g.Map.CurrentLevel
level.DrawLevel(screen)
ProcessRenderables(g, level, screen)
ProcessUserLog(g, screen)
ProcessHUD(g, screen)
}
// Layout will return the screen dimensions.
func (g *Game) Layout(w, h int) (int, int) {
gd := NewGameData()
return gd.TileWidth * gd.ScreenWidth, gd.TileHeight * gd.ScreenHeight
}
func main() {
g := NewGame()
ebiten.SetWindowTitle("Tower")
if err := ebiten.RunGame(g); err != nil {
log.Fatal(err)
}
}