added config file support
This commit is contained in:
@@ -80,26 +80,28 @@ type game struct {
|
||||
kill chan bool
|
||||
repair_hp int
|
||||
repair_rate float32
|
||||
tick_duration int
|
||||
}
|
||||
|
||||
func NewGame(id string, width, height float32) *game {
|
||||
func NewGame(id string, width, height float32, tick int) *game {
|
||||
g := &game{
|
||||
id: id,
|
||||
register: make(chan *player),
|
||||
unregister: make(chan *player, maxPlayer),
|
||||
projectiles: make(map[*Projectile]bool),
|
||||
splosions: make(map[*Splosion]bool),
|
||||
obstacles: GenerateObstacles(*obstacle_count, width, height),
|
||||
players: make(map[*player]bool),
|
||||
turn: 0,
|
||||
width: width,
|
||||
height: height,
|
||||
spectators: make(map[*Spectator]bool),
|
||||
sregister: make(chan *Spectator),
|
||||
sunregister: make(chan *Spectator),
|
||||
kill: make(chan bool, maxPlayer),
|
||||
repair_hp: 5,
|
||||
repair_rate: 3.0,
|
||||
id: id,
|
||||
register: make(chan *player),
|
||||
unregister: make(chan *player, maxPlayer),
|
||||
projectiles: make(map[*Projectile]bool),
|
||||
splosions: make(map[*Splosion]bool),
|
||||
obstacles: GenerateObstacles(conf.Obstacles, width, height),
|
||||
players: make(map[*player]bool),
|
||||
turn: 0,
|
||||
width: width,
|
||||
height: height,
|
||||
spectators: make(map[*Spectator]bool),
|
||||
sregister: make(chan *Spectator),
|
||||
sunregister: make(chan *Spectator),
|
||||
kill: make(chan bool, maxPlayer),
|
||||
repair_hp: 5,
|
||||
repair_rate: 3.0,
|
||||
tick_duration: tick,
|
||||
}
|
||||
return g
|
||||
}
|
||||
@@ -251,7 +253,7 @@ func (g *game) sendUpdate(payload *Boardstate) {
|
||||
|
||||
func (g *game) run() {
|
||||
var t0, t1 time.Time
|
||||
ticker := time.NewTicker(time.Duration(*tick) * time.Millisecond)
|
||||
ticker := time.NewTicker(time.Duration(conf.Tick) * time.Millisecond)
|
||||
for {
|
||||
select {
|
||||
case <-g.kill:
|
||||
|
||||
Reference in New Issue
Block a user