-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
118 lines (90 loc) · 2.42 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"flag"
"log"
"os"
"os/signal"
"sync/atomic"
"syscall"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)
const (
MODE_SPLASH = iota
MODE_PLAY_TWITCH
MODE_PLAY_SINGLE
MODE_SETTINGS
)
var (
ServerRunning atomic.Bool
gameMode atomic.Int32
playerMoveTime time.Duration = time.Second * 10
cpuMoveTime time.Duration = time.Second * 2
skipTwitch, vfastMode, fastMode, noTowers, smartMove, debugMode, skipMenu *bool
gameLoaded atomic.Bool
signalHandle chan os.Signal
)
func main() {
skipTwitch = flag.Bool("skipTwitch", false, "don't connect to twitch")
fastMode = flag.Bool("fast", false, "fast mode")
vfastMode = flag.Bool("vfast", false, "very fast mode")
noTowers = flag.Bool("noTower", false, "don't spawn towers")
smartMove = flag.Bool("smartMove", false, "Use intelligent moves to simulate a coordinated audiance.")
debugMode = flag.Bool("debug", false, "print debug info")
skipMenu = flag.Bool("skipMenu", false, "Skips main menu")
flag.Parse()
ServerRunning.Store(true)
// After starting loops, wait here for process signals
signalHandle = make(chan os.Signal, 1)
signal.Notify(signalHandle, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
var err error
splash, _, err = ebitenutil.NewImageFromFile("data/sprites/splash.png")
if err != nil {
log.Fatal(err)
}
go startEbiten()
loadAssets()
readSettings()
if !*skipTwitch {
readPlayers()
connectTwitch()
go playersAutosave()
}
go handleMoves()
go aniTimer()
board.towerMap = make(map[xyi]*objectData)
board.goblinMap = make(map[xyi]*objectData)
votes.Users = make(map[int64]*userMsgData)
board.fFrame = ebiten.NewImage(defaultWindowWidth, defaultWindowHeight)
board.checkerCache = ebiten.NewImage(defaultWindowWidth, defaultWindowHeight)
board.deadCache = ebiten.NewImage(defaultWindowWidth, defaultWindowHeight)
preDrawCheckerboard()
setupButtons()
gameLoaded.Store(true)
if *skipMenu {
gameMode.Store(MODE_PLAY_TWITCH)
}
<-signalHandle
//End all loops
ServerRunning.Store(false)
//Stop all sounds
for _, item := range sounds {
if item.player != nil {
item.player.Pause()
item.player.Close()
}
}
//Write out player scores
writePlayers()
//Wait a moment for stuff to finish up
time.Sleep(time.Second)
//Bye!
}
// Used for action animations
func aniTimer() {
for ServerRunning.Load() {
aniCount.Add(1)
time.Sleep(time.Second / 3)
}
}