-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.go
90 lines (77 loc) · 2.39 KB
/
map.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
package main
import (
"math/rand"
"github.com/hajimehoshi/ebiten"
)
// Map is a map, it contains MapData, tiles, etc
type Map struct {
tiles []*Tile
lights []*Light // Background/level-specific lights
mapNodes []string
phases Phases
}
func initMaps(g *Game) {
g.maps = append(gameReference.maps, Map{})
g.maps[0] = initMapSpaceship() // Spaceship
g.currentMap = g.maps[0]
}
func updateMaps() {
for i := 0; i < len(gameReference.maps); i++ {
gameReference.maps[i].update()
}
}
func renderMaps(screen *ebiten.Image) {
for i := 0; i < len(gameReference.maps); i++ {
gameReference.maps[i].render(screen)
}
}
func (m *Map) update() {
gameReference.maps[0].phases.phaseHandler()
}
func (m *Map) render(screen *ebiten.Image) {
}
// Returns a random position that's on a walkable node (' ')
func (m *Map) randomPosition() Vec2f {
position := Vec2f{0, 0}
randomTile := Vec2i{0, 0}
for m.mapNodes[randomTile.x][randomTile.y] != ' ' {
randomTile = Vec2i{rand.Intn(len(m.mapNodes) - 2), rand.Intn(len(m.mapNodes[0]) - 2)}
}
position = Vec2f{float64(randomTile.y * smallTileSize.x), float64(randomTile.x * smallTileSize.y)}
return position
}
func initMapSpaceship() Map {
index := 0
gameReference.maps[index].phases = initPhases()
// Lights
for i := 0; i < 12; i++ {
offset := 17.
lightPosition := newVec2f(offset+float64(i)*50, 25)
lightRotation := 0.
rect := gameReference.lightHandler.lightImages.rectangleLight1
id := gameReference.lightHandler.addLightStatic(rect, lightRotation, lightPosition) // Create light
// Add it to the map's light reference array
gameReference.maps[index].lights = append(gameReference.maps[index].lights,
&gameReference.lightHandler.lights[gameReference.lightHandler.getLightIndex(id)],
)
}
gameReference.maps[index].mapNodes = []string{
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
return gameReference.maps[index]
}