Keyboard and mouse input system

This commit is contained in:
bloeys
2021-10-09 05:32:17 +04:00
parent fae453db37
commit b03a017a7f
4 changed files with 207 additions and 0 deletions

14
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/bloeys/go-sdl-engine/input"
"github.com/bloeys/go-sdl-engine/timing"
"github.com/go-gl/gl/v4.6-compatibility/gl"
"github.com/veandco/go-sdl2/sdl"
@ -105,6 +106,7 @@ func gameLoop() {
timing.FrameStarted()
handleEvents()
update()
draw()
window.GLSwap()
@ -116,10 +118,18 @@ func gameLoop() {
func handleEvents() {
input.EventLoopStarted()
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch e := event.(type) {
case *sdl.KeyboardEvent:
input.HandleKeyboardEvent(e)
case *sdl.MouseButtonEvent:
input.HandleMouseBtnEvent(e)
case *sdl.QuitEvent:
println("Quit at ", e.Timestamp)
isRunning = false
@ -127,6 +137,10 @@ func handleEvents() {
}
}
func update() {
println(input.AnyKeyDown(), ";", input.AnyMouseBtnDown())
}
func draw() {
//Clear screen and depth buffers
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)