-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanupSystem.go
45 lines (35 loc) · 895 Bytes
/
cleanupSystem.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
package foodzy
import (
"github.com/co0p/foodzy/component"
"github.com/co0p/foodzy/internal/ecs"
"github.com/hajimehoshi/ebiten/v2"
)
type CleanupSystem struct {
manager *ecs.EntityManager
runFrequency int
coolDown int
}
func NewCleanupSystem(manager *ecs.EntityManager, frequency int) *CleanupSystem {
return &CleanupSystem{
manager: manager,
runFrequency: frequency,
coolDown: frequency,
}
}
func (s *CleanupSystem) Draw(image *ebiten.Image) {}
func (s *CleanupSystem) Update() error {
candidates := s.manager.QueryByComponents(component.TransformType)
for _, e := range candidates {
position := e.GetComponent(component.TransformType).(*component.Transform)
if int(position.Y) > ScreenHeight {
e.Active = false
}
}
if s.coolDown > 0 {
s.coolDown--
return nil
}
s.manager.RemoveInactive()
s.coolDown = s.runFrequency
return nil
}