-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasteboids.go
55 lines (48 loc) · 1.09 KB
/
asteboids.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
package asteboids
import (
"os"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/jtbonhomme/asteboids/internal/config"
"github.com/jtbonhomme/asteboids/internal/game"
"github.com/jtbonhomme/asteboids/internal/sounds"
"github.com/sirupsen/logrus"
)
func Run(log *logrus.Logger, conf *config.Config) error {
os.Setenv("EBITEN_SCREENSHOT_KEY", "s")
g := game.New(log, conf)
log.Infof("Game: %s", g)
ebiten.SetWindowSize(int(conf.ScreenWidth), int(conf.ScreenHeight))
ebiten.SetWindowTitle("Asteboids")
sounds.Init()
if conf.Mute {
sounds.Mute()
}
g.StartGame()
playSoundTrack()
if conf.Optim {
ebiten.SetVsyncEnabled(false)
ebiten.SetInitFocused(false)
}
if conf.MaxTPS != 0 {
ebiten.SetMaxTPS(conf.MaxTPS)
}
// Call ebiten.RunGame to start your game loop.
err := ebiten.RunGame(g)
if err != nil {
return err
}
return nil
}
func playSoundTrack() {
go func() {
for {
time.Sleep(1 * time.Second)
_ = sounds.Beat1Player.Rewind()
sounds.Beat1Player.Play()
time.Sleep(1 * time.Second)
_ = sounds.Beat2Player.Rewind()
sounds.Beat2Player.Play()
}
}()
}