-
Notifications
You must be signed in to change notification settings - Fork 1
/
infantry_sprite.go
75 lines (60 loc) · 1.48 KB
/
infantry_sprite.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
package render
import (
_ "image/png"
"github.com/harbdog/raycaster-go/geom"
"github.com/pixelmek-3d/pixelmek-3d/game/model"
"github.com/hajimehoshi/ebiten/v2"
"github.com/jinzhu/copier"
)
type InfantrySprite struct {
*Sprite
// TODO: move to separate AI handler
PatrolPathIndex int
PatrolPath [][2]float64
}
func NewInfantrySprite(
infantry *model.Infantry, scale float64, img *ebiten.Image,
) *InfantrySprite {
var p *Sprite
sheet := infantry.Resource.ImageSheet
if sheet == nil {
p = NewSprite(
infantry, scale, img,
)
} else {
p = NewAnimatedSprite(infantry, scale, img, sheet.Columns, sheet.Rows, sheet.AnimationRate)
if len(sheet.AngleFacingRow) > 0 {
facingMap := make(map[float64]int, len(sheet.AngleFacingRow))
for degrees, index := range sheet.AngleFacingRow {
rads := geom.Radians(degrees)
facingMap[rads] = index
}
p.SetTextureFacingMap(facingMap)
}
p.staticTexNum = infantry.Resource.ImageSheet.StaticIndex
}
s := &InfantrySprite{
Sprite: p,
}
return s
}
func (t *InfantrySprite) Infantry() *model.Infantry {
if t.Entity == nil {
return nil
}
return t.Entity.(*model.Infantry)
}
func (t *InfantrySprite) Clone(asUnit model.Unit) *InfantrySprite {
tClone := &InfantrySprite{}
sClone := &Sprite{}
copier.Copy(tClone, t)
copier.Copy(sClone, t.Sprite)
tClone.Sprite = sClone
if asUnit == nil {
eClone := t.Entity.Clone()
tClone.Sprite.Entity = eClone
} else {
tClone.Sprite.Entity = asUnit
}
return tClone
}