-
Notifications
You must be signed in to change notification settings - Fork 1
/
apple.go
41 lines (32 loc) · 818 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
package main
import (
"github.com/hajimehoshi/ebiten"
"math/rand"
)
const appleSize = 8
const appleNutrition = 20
type Apple struct {
//this thing is heavy, so, careful
//when you deref
image *ebiten.Image
location Vector2
}
func (apple *Apple) amount() int {
return appleNutrition
}
func (apple *Apple) avatar() *ebiten.Image {
return apple.image
}
func (apple *Apple) position() Vector2 {
offset := apple.location.Add(Vector2{-appleSize / 2, -appleSize / 2})
return offset
}
func (apple *Apple) Collider() Rect {
offset := apple.location.Add(Vector2{-appleSize / 2, -appleSize / 2})
return Rect{offset, offset.Add(Vector2{appleSize, appleSize})}
}
func (apple *Apple) PlaceRandomly() {
apple.location = Vector2{
float64(rand.Intn(int(GameWidth))),
float64(rand.Intn(int(GameHeight)))}
}