コード例 #1
0
ファイル: main.go プロジェクト: anthonyrego/gosmf
func initFpsCounter(screen *window.Screen) func() int {
	const fpsBufferSize = 20
	var fpsBuffer [fpsBufferSize]int
	fpsCounter := 0
	currentFps := 0

	return func() int {
		if fpsCounter > (fpsBufferSize - 1) {
			fpsCounter = 0
			fpsSum := 0
			for _, val := range fpsBuffer {
				fpsSum += val
			}
			currentFps = int(math.Ceil((float64(fpsSum) / float64(fpsBufferSize))))
			if currentFps < 0 {
				currentFps = 0
			}
		}

		fpsBuffer[fpsCounter] = int(1 / screen.GetTimeSinceLastFrame())
		fpsCounter++
		return currentFps
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: anthonyrego/gosmf
func initCamera(screen *window.Screen) func() {
	cam1 := camera.New(true)
	cam1.SetOrtho(screen.Width, screen.Height, 200)
	cam1.SetPosition2D(0, 0)
	camx := 0.0
	camy := 0.0
	speed := 300.0
	return func() {
		if window.GetKeyState(window.KeyA) == window.KeyStatePressed {
			camx -= screen.AmountPerSecond(speed)
		}
		if window.GetKeyState(window.KeyD) == window.KeyStatePressed {
			camx += screen.AmountPerSecond(speed)
		}
		if window.GetKeyState(window.KeyW) == window.KeyStatePressed {
			camy -= screen.AmountPerSecond(speed)
		}
		if window.GetKeyState(window.KeyS) == window.KeyStatePressed {
			camy += screen.AmountPerSecond(speed)
		}
		cam1.SetPosition2D(float32(camx), float32(camy))
	}
}