/
word.go
75 lines (62 loc) · 1.89 KB
/
word.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 vimman
import (
"github.com/nsf/termbox-go"
"time"
)
type Word struct {
*Entity
Content string
Speed float64
Direction Direction
CenterHorizontally bool
Fg termbox.Attribute
Bg termbox.Attribute
}
func (w *Word) ShouldCenterHorizontally() bool {
return w.CenterHorizontally
}
type WordOptions struct {
InitCallback func()
Fg termbox.Attribute
Bg termbox.Attribute
CollidesPhysically bool
CenterHorizontally bool
Tags []Tag
}
func ConvertStringToCells(s string, fg termbox.Attribute, bg termbox.Attribute) []*TermBoxCell {
var arr []*TermBoxCell
for i := 0; i < len([]rune(s)); i++ {
cell := &TermBoxCell{
Cell: &termbox.Cell{
[]rune(s)[i],
fg,
bg,
},
collidesPhysically: false,
cellData: TileMapCellData{}}
arr = append(arr, cell)
}
return arr
}
func NewWord(s *Stage, x, y int, content string, options WordOptions) *Word {
fg, bg, collidesPhysically, centerHorizontally := options.Fg, options.Bg, options.CollidesPhysically, options.CenterHorizontally
cells := ConvertStringToCells(content, fg, bg)
entityOptions := EntityOptions{2000, options.Tags, nil}
e := NewEntity(s, x, y, len(content), 1, ' ', fg, bg, cells, collidesPhysically, entityOptions)
return &Word{
Entity: e,
Content: content,
Direction: horizontal,
CenterHorizontally: centerHorizontally,
Fg: fg,
Bg: bg,
}
}
func DefaultWordOptions() WordOptions {
return WordOptions{InitCallback: nil, Fg: typedCharacterFg, Bg: typedCharacterBg, CollidesPhysically: false, CenterHorizontally: true}
}
func NewEmptyCharacter(s *Stage, x, y int, options WordOptions) *Word {
return NewWord(s, x, y, string(" "), options)
}
func (w *Word) Update(s *Stage, event termbox.Event, delta time.Duration) {
}