Common lisp interface to bearlibterminal https://bitbucket.org/cfyzium/bearlibterminal. Created with https://github.com/rpav/cl-autowrap.

movement.lisp 1.5KB

1234567891011121314151617181920212223242526272829303132
  1. (in-package :bearlibterminal-examples)
  2. (defun help-msg (player-char)
  3. (terminal-print 0 0 (format nil "Use arrow keys to move your character represented by ~C!" player-char))
  4. (terminal-print 0 1 "Exit with the escape button."))
  5. (defun movement (&key (player-codepoint #x2638) (window-x 80) (window-y 25))
  6. (let ((player-char (code-char player-codepoint)))
  7. (terminal-open)
  8. (terminal-set (format nil "window: size=~Dx~D, title='BearLibTerminal movement example';" window-x window-y))
  9. ;; Set separately so the other settings take even if the font isn't found
  10. ;; Make sure you are in the right directory/change the font path if it doesn't load.
  11. (terminal-set "font: ./fonts/DejaVuSansMono.ttf, size=12")
  12. (help-msg player-char)
  13. (terminal-put 5 5 player-codepoint)
  14. (terminal-refresh)
  15. (loop with player-x = 5
  16. with player-y = 5
  17. as key = (terminal-read) do
  18. (cond
  19. ((= key bearlibterminal-ffi:+tk-left+) (decf player-x))
  20. ((= key bearlibterminal-ffi:+tk-right+) (incf player-x))
  21. ((= key bearlibterminal-ffi:+tk-down+) (incf player-y))
  22. ((= key bearlibterminal-ffi:+tk-up+) (decf player-y)))
  23. (terminal-clear)
  24. (help-msg player-char)
  25. (terminal-put player-x player-y player-codepoint)
  26. (terminal-refresh)
  27. until (or (= key bearlibterminal-ffi:+tk-escape+)
  28. (= key bearlibterminal-ffi:+tk-close+)))
  29. (terminal-close)))