| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package game
- import "github.com/gdamore/tcell/v3"
- func (game *Game) keyboardProcessor() {
- defer close(game.keypresses)
- for game.gameover == 0 {
- // Poll for an event
- ev := <-game.screen.EventQ()
- // Fetch the type, and check if any other actions are required.
- switch ev := ev.(type) {
- case *tcell.EventResize:
- game.screen.Sync()
- case *tcell.EventKey:
- // Keys to bug out
- if ev.Key() == tcell.KeyEscape || ev.Key() == tcell.KeyCtrlC {
- game.gameover = 1
- return
- } else if ev.Key() == tcell.KeyCtrlL {
- game.screen.Sync()
- } else if ev.Key() == 'q' {
- game.keypresses <- upleft
- } else if ev.Key() == 'e' {
- game.keypresses <- upright
- } else if ev.Key() == 'z' {
- game.keypresses <- downleft
- } else if ev.Key() == 'c' {
- game.keypresses <- downright
- } else if ev.Key() == tcell.KeyUp || ev.Key() == 'w' {
- game.keypresses <- up
- } else if ev.Key() == tcell.KeyRight || ev.Key() == 'd' {
- game.keypresses <- right
- } else if ev.Key() == tcell.KeyDown || ev.Key() == 's' || ev.Key() == 'x' {
- game.keypresses <- down
- } else if ev.Key() == tcell.KeyLeft || ev.Key() == 'a' {
- game.keypresses <- left
- } else if ev.Key() == 'r' {
- game.keypresses <- rotateleft
- } else if ev.Key() == 't' {
- game.keypresses <- rotateright
- } else if ev.Key() == tcell.Key(0x2c) { // Spacebar?
- game.keypresses <- action
- }
- }
- }
- }
|