-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmapobj.go
136 lines (114 loc) · 2.12 KB
/
mapobj.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
133
134
135
136
// Copyright 2017 Daniel Salvadori. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/g3n/engine/core"
"github.com/g3n/engine/graphic"
"github.com/g3n/engine/light"
)
// MapObj describes the bare minimum needed by a game object that occupies a grid cell
type MapObj struct {
*core.Node
loc GridLoc
pushable bool
}
func (mo *MapObj) Location() GridLoc {
return mo.loc
}
func (mo *MapObj) SetLocation(l GridLoc) {
mo.loc = l
}
func (mo *MapObj) IsPushable() bool {
return mo.pushable
}
type IMapObj interface {
core.INode
Location() GridLoc
SetLocation(GridLoc)
IsPushable() bool
}
// Box
type Box struct {
MapObj
mesh *graphic.Mesh
light *light.Point
}
func NewBox(loc GridLoc) *Box {
b := new(Box)
b.loc = loc
b.pushable = true
return b
}
func (b *Box) SetMeshAndLight(mesh *graphic.Mesh, light *light.Point) {
b.mesh = mesh
b.Node = &mesh.Node
mesh.SetPositionVec(b.loc.Vec3())
b.light = light
b.Add(light)
}
// Block
type Block struct {
MapObj
mesh *graphic.Mesh
}
func NewBlock(loc GridLoc) *Block {
b := new(Block)
b.loc = loc
b.pushable = false
return b
}
func (b *Block) SetMesh(mesh *graphic.Mesh) {
b.mesh = mesh
b.Node = &mesh.Node
mesh.SetPositionVec(b.loc.Vec3())
}
// Elevator
type Elevator struct {
MapObj
mesh *graphic.Mesh
low int
high int
}
func NewElevator(loc GridLoc, low, high int) *Elevator {
b := new(Elevator)
b.loc = loc
b.pushable = false
b.low = low
b.high = high
return b
}
func (b *Elevator) SetMesh(mesh *graphic.Mesh) {
b.mesh = mesh
b.Node = &mesh.Node
mesh.SetPositionVec(b.loc.Vec3())
}
// Gopher
type Gopher struct {
MapObj
}
func NewGopher(loc GridLoc) *Gopher {
g := new(Gopher)
g.loc = loc
g.pushable = true
return g
}
func (b *Gopher) SetNode(node *core.Node) {
b.Node = node
}
// Pad
type Pad struct {
MapObj
mesh *graphic.Mesh
}
func NewPad(loc GridLoc) *Pad {
b := new(Pad)
b.loc = loc
b.pushable = false
return b
}
func (b *Pad) SetMesh(mesh *graphic.Mesh) {
b.mesh = mesh
b.Node = &mesh.Node
mesh.SetPositionVec(b.loc.Vec3())
}