-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathentity.go
More file actions
132 lines (105 loc) · 2.58 KB
/
Copy pathentity.go
File metadata and controls
132 lines (105 loc) · 2.58 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
124
125
126
127
128
129
130
131
132
package vimman
import (
"github.com/nsf/termbox-go"
"time"
)
type Direction int
const (
horizontal Direction = iota
vertical
)
type Entity struct {
Stage *Stage
Position Point
Width int
Height int
Rune rune
Cell *TermBoxCell
Cells []*TermBoxCell
DrawPriority int
Tags []Tag
InitCallback func()
}
type EntityOptions struct {
DrawPriority int
Tags []Tag
InitCallback func()
}
type Tag struct {
Name string
}
func NewEntity(s *Stage, x, y, w, h int, r rune, fg termbox.Attribute, bg termbox.Attribute, cells []*TermBoxCell, collidesPhysically bool, options EntityOptions) *Entity {
drawPriority, tags, initCallback := options.DrawPriority, options.Tags, options.InitCallback
p := Point{x, y}
cell := &TermBoxCell{&termbox.Cell{r, fg, bg}, collidesPhysically, TileMapCellData{}}
return &Entity{s, p, w, h, r, cell, cells, drawPriority, tags, initCallback}
}
func (e *Entity) SetStage(s *Stage) {
e.Stage = s
}
func (e *Entity) GetStage() *Stage {
return e.Stage
}
func (e *Entity) SetCells(s *Stage) {
newPositionY := e.Position.y
for i := 0; i < e.Height; i++ {
newPositionX := e.Position.x
if i != 0 {
newPositionY += 1
}
for j := 0; j < e.Width; j++ {
if j != 0 {
newPositionX += 1
}
if e.Cells != nil {
index := j
tileMapCell := e.Cells[index]
if len(e.Cells) > index {
s.Canvas.OverWriteCanvasCell(newPositionX, newPositionY, tileMapCell)
}
} else {
tileMapCell := e.Cell
s.Canvas.OverWriteCanvasCell(newPositionX, newPositionY, tileMapCell)
}
}
}
}
func (e *Entity) GetCells() []*TermBoxCell {
return e.Cells
}
func (e *Entity) Update(s *Stage, event termbox.Event, time time.Duration) {
}
func (e *Entity) SetPosition(x, y int) {
e.SetPositionX(x)
e.SetPositionY(y)
}
func (e *Entity) SetPositionX(x int) {
e.Position.x = x
}
func (e *Entity) SetPositionY(y int) {
e.Position.y = y
}
func (e *Entity) GetPositionX() int {
return e.Position.x
}
func (e *Entity) GetPositionY() int {
return e.Position.y
}
func (e *Entity) GetPosition() (int, int) {
return e.Position.x, e.Position.y
}
func (e *Entity) GetScreenOffset() (int, int) {
screenWidth, screenHeight := e.Stage.Game.getScreenSize()
return (screenWidth - e.Width) / 2, (screenHeight - e.Height) / 2
}
func (e *Entity) Destroy() {
}
func (e *Entity) GetDrawPriority() int {
return e.DrawPriority
}
func (e *Entity) GetTags() []Tag {
return e.Tags
}
func (e *Entity) IsInsideOfCanvasBoundaries() bool {
return e.GetStage().Canvas.IsInsideOfBoundaries(e.GetPositionX(), e.GetPositionY())
}