Esempio n. 1
0
func handleGameEvents(c chan struct{}, g *agario.Game) {
	for {
		g.RunOnce(false)
		for g.RunOnce(true) {
		}
		c <- struct{}{}
	}
}
Esempio n. 2
0
func run(ig *agario.Game) {
	gameEvents := make(chan struct{})
	quitChan := make(chan struct{})

	g := &Game{
		g:        ig,
		quitChan: quitChan,
	}
	/*ai := &AI{
		g: ig,
	}*/
	ka := &keepAlive{
		g: ig,
	}

	go handleGameEvents(gameEvents, ig)
	go engi.Open("agariobot", 1280, 800, false, g)

	lastTick := time.Now()

mainLoop:
	for {
		select {
		case _, ok := <-quitChan:
			if !ok {
				break mainLoop
			}
		case <-gameEvents:
			dt := time.Now().Sub(lastTick)

			ig.Lock()

			ka.Update(dt)
			//ai.Update(dt)

			ig.Unlock()

			lastTick = time.Now()
		}
	}

	log.Printf("Gracefully stopped")
}