2024-04-27 22:32:05 +03:00
|
|
|
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
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateGameContext() *GameContext {
|
|
|
|
gc := new(GameContext)
|
|
|
|
|
2024-05-18 20:38:46 +03:00
|
|
|
gc.world = CreateGameWorld()
|
2024-04-27 22:32:05 +03:00
|
|
|
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gc *GameContext) Run() {
|
2024-05-06 18:59:14 +03:00
|
|
|
lastLoop := time.Now()
|
2024-04-27 22:32:05 +03:00
|
|
|
|
|
|
|
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-04-27 22:32:05 +03:00
|
|
|
|
2024-05-18 20:38:46 +03:00
|
|
|
gc.world.Tick(deltaTime)
|
2024-04-27 22:32:05 +03:00
|
|
|
}
|
|
|
|
}
|