last_light/game/game_context.go

31 lines
437 B
Go
Raw Permalink Normal View History

package game
import (
"time"
)
const TICK_RATE int64 = 50 // tick every 50ms ( 20 ticks per second )
type GameContext struct {
2024-05-18 20:38:46 +03:00
world *GameWorld
}
func CreateGameContext() *GameContext {
gc := new(GameContext)
2024-05-18 20:38:46 +03:00
gc.world = CreateGameWorld()
return gc
}
func (gc *GameContext) Run() {
2024-05-06 18:59:14 +03:00
lastLoop := time.Now()
for {
2024-05-18 20:38:46 +03:00
deltaTime := 1 + time.Since(lastLoop).Milliseconds()
2024-05-06 18:59:14 +03:00
lastLoop = time.Now()
2024-05-18 20:38:46 +03:00
gc.world.Tick(deltaTime)
}
}