-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys_init_hives.go
40 lines (31 loc) · 941 Bytes
/
sys_init_hives.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
package bees
import (
"math/rand"
"github.com/mlange-42/arche-demo/common"
"github.com/mlange-42/arche/ecs"
"github.com/mlange-42/arche/generic"
)
// SysInitHives is a system that creates a number of randomly places hives.
type SysInitHives struct {
// Target number of hives.
Count int
}
// Initialize the system
func (s *SysInitHives) Initialize(world *ecs.World) {
canvasRes := generic.NewResource[common.Image](world)
canvas := canvasRes.Get()
w := float64(canvas.Width)
h := float64(canvas.Height)
builder := generic.NewMap3[Position, Hive, Random256](world)
query := builder.NewBatchQ(s.Count)
for query.Next() {
pos, _, r256 := query.Get()
pos.X = rand.Float64()*w*0.8 + w*0.1
pos.Y = rand.Float64()*h*0.8 + h*0.1
r256.Value = uint8(rand.Int31n(256))
}
}
// Update the system
func (s *SysInitHives) Update(world *ecs.World) {}
// Finalize the system
func (s *SysInitHives) Finalize(world *ecs.World) {}