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:
stevenhowes
2022-01-04 22:00:31 +00:00
parent 45c553150c
commit bc5cd16447
7 changed files with 98 additions and 223 deletions
+44
View File
@@ -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
}