-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapple.go
42 lines (35 loc) · 870 Bytes
/
apple.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
package main
import "github.com/firefly-zero/firefly-go/firefly"
var apple Apple
const (
appleRadius = 5
appleDiameter = appleRadius * 2
)
type Apple struct {
// Coordinates of the apple center
Pos firefly.Point
}
func NewApple() Apple {
a := Apple{}
a.Move()
return a
}
// move the apple into a new place
func (a *Apple) Move() {
a.Pos = firefly.Point{
X: int(firefly.GetRandom()%(firefly.Width-appleRadius*2)) + appleRadius,
Y: int(firefly.GetRandom()%(firefly.Height-appleRadius*2)) + appleRadius,
}
}
func (a *Apple) Render() {
firefly.DrawCircle(
firefly.Point{X: a.Pos.X - appleRadius, Y: a.Pos.Y - appleRadius},
appleDiameter,
firefly.Style{FillColor: firefly.ColorRed},
)
firefly.DrawLine(
a.Pos,
firefly.Point{X: a.Pos.X + appleRadius, Y: a.Pos.Y - appleRadius},
firefly.LineStyle{Color: firefly.ColorGreen, Width: 3},
)
}