-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameoverSystem.go
63 lines (54 loc) · 1.58 KB
/
gameoverSystem.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
52
53
54
55
56
57
58
59
60
61
62
63
package foodzy
import (
"github.com/co0p/foodzy/component"
"github.com/co0p/foodzy/internal/ecs"
"github.com/co0p/foodzy/internal/sound"
"github.com/hajimehoshi/ebiten/v2"
)
type GameoverSystem struct {
entityManager *ecs.EntityManager
soundManager *sound.SoundManager
count int
startAction ActionType
original *ebiten.Image
}
func NewGameoverSystem(manager *ecs.EntityManager, soundManager *sound.SoundManager, startAction ActionType) *GameoverSystem {
return &GameoverSystem{
entityManager: manager,
soundManager: soundManager,
startAction: startAction,
}
}
func (s *GameoverSystem) Update() error {
// decrease sound level, until exit
if s.count%ebiten.MaxTPS() == 0 {
s.soundManager.Volume(SoundBackground, -0.1)
}
vol := s.soundManager.Volume(SoundBackground, 0)
if vol < 0 {
s.startAction(s.entityManager)
}
s.count++
// title animation
title := s.entityManager.QueryFirstByTag("gameovertitle")
titleVelocity := title.GetComponent(component.VelocityType).(*component.Velocity)
titleTransform := title.GetComponent(component.TransformType).(*component.Transform)
// stop animation of title
if titleVelocity.Y != 0 && titleTransform.Y > float64(ScreenHeight/2) {
titleVelocity.Y = 0.0
}
return nil
}
func (s *GameoverSystem) Draw(screen *ebiten.Image) {
if s.original == nil {
s.original = ebiten.NewImageFromImage(screen)
}
for j := -3; j <= 3; j++ {
for i := -3; i <= 3; i++ {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(i), float64(j))
op.ColorM.Scale(1, 1, 1, 1.0/25.0)
screen.DrawImage(s.original, op)
}
}
}