Skip to content

Commit dd307e8

Browse files
author
vilmibm
committed
sprites working but gotta slow em down
1 parent c7a28bd commit dd307e8

File tree

2 files changed

+84
-58
lines changed

2 files changed

+84
-58
lines changed

pkg/cmd/protip/protip.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ loop:
9494
break loop
9595
case <-time.After(time.Millisecond * 50):
9696
}
97-
w, h := s.Size()
97+
//w, h := s.Size()
98+
//w, _ := s.Size()
9899
s.Clear()
99-
emitStr(s, w/2-7, h/2, tcell.StyleDefault, "TODO a protip and stuff")
100+
//emitStr(s, w/2-7, h/2, tcell.StyleDefault, "TODO a protip and stuff")
101+
drawSprite(s, 0, 0, tcell.StyleDefault, opts.Sprite)
100102
s.Show()
101103
}
102104

@@ -119,5 +121,17 @@ func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) {
119121
}
120122
}
121123

124+
func drawSprite(s tcell.Screen, x, y int, st tcell.Style, sp *Sprite) {
125+
// TODO worry about animation later
126+
cells := sp.Cells()
127+
for y := 0; y < len(cells); y++ {
128+
row := cells[y]
129+
for x := 0; x < len(row); x++ {
130+
s.SetContent(x, y, cells[y][x], nil, st)
131+
}
132+
}
133+
sp.IncrFrame()
134+
}
135+
122136
// Want to be able to have a sprite that occupies a rectangle and can animate internally relative to
123137
// its own geometry.

pkg/cmd/protip/sprites.go

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package protip
22

3+
import "strings"
4+
35
type Sprite struct {
46
Width int
57
Height int
@@ -15,93 +17,103 @@ func (s *Sprite) IncrFrame() {
1517
s.frameIx = (s.frameIx + 1) % len(s.Frames)
1618
}
1719

20+
func (s *Sprite) Cells() [][]rune {
21+
out := [][]rune{}
22+
curFrame := s.Frames[s.frameIx]
23+
lines := strings.Split(curFrame, "\n")
24+
for _, line := range lines {
25+
out = append(out, []rune(line))
26+
}
27+
return out
28+
}
29+
1830
func Clippy() *Sprite {
1931
s := &Sprite{
2032
Width: 15,
2133
Height: 15,
2234
}
2335
s.AddFrame(`
24-
___
25-
^ ^
26-
O O
27-
| |
36+
___
37+
^ ^
38+
O O
39+
| |
2840
|| |
29-
||_/ /
30-
| |
31-
| |
32-
\___/
41+
||_/ /
42+
| |
43+
| |
44+
\___/
3345
3446
`)
3547
s.AddFrame(`
36-
___
37-
^ ^
38-
O O
39-
| |
48+
___
49+
^ ^
50+
O O
51+
| |
4052
|| |
41-
||_/ -
42-
| |
43-
| |
44-
\___/
53+
||_/ -
54+
| |
55+
| |
56+
\___/
4557
4658
`)
4759
s.AddFrame(`
48-
___
49-
^ ^
50-
O O
51-
| |
60+
___
61+
^ ^
62+
O O
63+
| |
5264
|| |
53-
||_/ /
54-
| |
55-
| |
56-
\___/
65+
||_/ /
66+
| |
67+
| |
68+
\___/
5769
5870
`)
5971
s.AddFrame(`
60-
___
61-
^ ^
62-
o O
63-
| |
72+
___
73+
^ ^
74+
o O
75+
| |
6476
|| |
65-
||_/ /
66-
| |
67-
| |
68-
\___/
77+
||_/ /
78+
| |
79+
| |
80+
\___/
6981
7082
`)
7183
s.AddFrame(`
72-
___
73-
^ ^
74-
- O
75-
| |
84+
___
85+
^ ^
86+
- O
87+
| |
7688
|| |
77-
||_/ /
78-
| |
79-
| |
80-
\___/
89+
||_/ /
90+
| |
91+
| |
92+
\___/
8193
8294
`)
8395
s.AddFrame(`
84-
___
85-
^ ^
86-
o O
87-
| |
96+
___
97+
^ ^
98+
o O
99+
| |
88100
|| |
89-
||_/ /
90-
| |
91-
| |
92-
\___/
101+
||_/ /
102+
| |
103+
| |
104+
\___/
93105
94106
`)
95107
s.AddFrame(`
96-
___
97-
^ ^
98-
O O
99-
| |
108+
___
109+
^ ^
110+
O O
111+
| |
100112
|| |
101-
||_/ /
102-
| |
103-
| |
104-
\___/
113+
||_/ /
114+
| |
115+
| |
116+
\___/
105117
106118
`)
107119

0 commit comments

Comments
 (0)