mirror of
https://github.com/mvvasilev/last_light.git
synced 2025-04-19 12:49:52 +03:00
30 lines
437 B
Go
30 lines
437 B
Go
package game
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
const TICK_RATE int64 = 50 // tick every 50ms ( 20 ticks per second )
|
|
|
|
type GameContext struct {
|
|
world *GameWorld
|
|
}
|
|
|
|
func CreateGameContext() *GameContext {
|
|
gc := new(GameContext)
|
|
|
|
gc.world = CreateGameWorld()
|
|
|
|
return gc
|
|
}
|
|
|
|
func (gc *GameContext) Run() {
|
|
lastLoop := time.Now()
|
|
|
|
for {
|
|
deltaTime := 1 + time.Since(lastLoop).Milliseconds()
|
|
lastLoop = time.Now()
|
|
|
|
gc.world.Tick(deltaTime)
|
|
}
|
|
}
|