mirror of
https://github.com/stevenhowes/GoRetro.git
synced 2026-05-26 15:53:31 +01:00
Ditch keyboard mover, shooter, interval shooter. All of that is game code not engine. Added key handler and scheduler. Can also now duplicate components on an element (key readers for example)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package GoRetro
|
||||
|
||||
/*
|
||||
* --------------------
|
||||
* KeyboardReader
|
||||
* --------------------
|
||||
* Checks for a keyboard event and fires the callback on the
|
||||
* element it is attached to
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
||||
type inputKeyboard struct {
|
||||
container *Element
|
||||
key int
|
||||
keyFunc func(element *Element, key int)
|
||||
}
|
||||
|
||||
func NewInputKeyboard(container *Element, keyCode int, Keyhandle func(element *Element, key int)) *inputKeyboard {
|
||||
return &inputKeyboard{
|
||||
container: container,
|
||||
key: keyCode,
|
||||
keyFunc: Keyhandle,
|
||||
}
|
||||
}
|
||||
|
||||
func (input *inputKeyboard) onDraw() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (input *inputKeyboard) onUpdate() error {
|
||||
keys := sdl.GetKeyboardState()
|
||||
|
||||
if keys[input.key] == 1 {
|
||||
input.keyFunc(input.container, input.key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (input *inputKeyboard) onCollision(other *Element) error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user