-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.go
51 lines (42 loc) · 997 Bytes
/
sprite.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
package main
import (
"image/color"
"math/rand"
)
type Sprite struct {
clr color.Color
x, y float32
radius uint
}
//nolint:exhaustruct
func NewSprite() *Sprite {
spr := &Sprite{}
spr.setRandomColor()
spr.setRandomRadius()
spr.setRandomInitialPosition()
return spr
}
func (spr *Sprite) setRandomColor() {
// so that the color is not too dark
const min = 30
const max = 256
r := uint8(rand.Intn(max-min) + min)
g := uint8(rand.Intn(max-min) + min)
b := uint8(rand.Intn(max-min) + min)
spr.clr = color.RGBA{r, g, b, 255}
}
func (spr *Sprite) setRandomRadius() {
const min = 10
const max = 30
spr.radius = uint(rand.Intn(max-min) + min)
}
func (spr *Sprite) setRandomInitialPosition() {
min := int(spr.radius)
maxX := int(initialScreenWidth - spr.radius)
spr.x = float32(rand.Intn(maxX-min) + min)
maxY := int(initialScreenHeight - spr.radius)
spr.y = float32(rand.Intn(maxY-min) + min)
}
func (spr *Sprite) getPosition() (x, y float32) {
return spr.x, spr.y
}