示例#1
0
文件: state.go 项目: stojg/pants
func NewStateMachine(initial StateMachineState) *StateMachine {
	sm := &StateMachine{
		timer: timer.NewTimer(),
	}
	sm.initialState = initial
	return sm
}
示例#2
0
文件: world.go 项目: stojg/pants
func (w *World) worldTick() {
	var gameTime float64
	var accumulator float64
	var frameTime float64
	dt := 0.01
	timer := timer.NewTimer()
	currentTime := timer.Seconds()
	for {
		newTime := timer.Seconds()
		frameTime = newTime - currentTime
		currentTime = newTime

		accumulator += frameTime
		for accumulator >= dt {
			// Individual entities
			w.entityManager.Update(w, dt)
			accumulator -= (dt)
			gameTime += dt
		}

		// world AI
		w.director.Update(w, dt, gameTime)

		// tell the event manager to dispatch all queued events
		events.DispatchEvents()
	}

}