mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Keyboard and mouse input system
This commit is contained in:
14
main.go
14
main.go
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user