snake-hacks.el 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;; If the game is paused, then move the snake left.
  2. ;; If the game is already paused, move the snake one square.
  3. (defun my/snake-move-up ()
  4. (interactive)
  5. (if snake-paused
  6. (progn
  7. (snake-pause-game)
  8. (snake-move-up)
  9. (snake-update-game "*Snake*")
  10. (snake-pause-game))
  11. (progn
  12. (snake-move-up)
  13. (snake-update-game "*Snake*")
  14. (snake-pause-game))))
  15. (defun my/snake-move-down ()
  16. (interactive)
  17. (if snake-paused
  18. (progn
  19. (snake-pause-game)
  20. (snake-move-down)
  21. (snake-update-game "*Snake*")
  22. (snake-pause-game))
  23. (progn
  24. (snake-move-down)
  25. (snake-update-game "*Snake*")
  26. (snake-pause-game))))
  27. (defun my/snake-move-left ()
  28. (interactive)
  29. (if snake-paused
  30. (progn
  31. (snake-pause-game)
  32. (snake-move-left)
  33. (snake-update-game "*Snake*")
  34. (snake-pause-game))
  35. (progn
  36. (snake-move-left)
  37. (snake-update-game "*Snake*")
  38. (snake-pause-game))))
  39. (defun my/snake-move-right ()
  40. (interactive)
  41. (if snake-paused
  42. (progn
  43. (snake-pause-game)
  44. (snake-move-right)
  45. (snake-update-game "*Snake*")
  46. (snake-pause-game))
  47. (progn
  48. (snake-move-right)
  49. (snake-update-game "*Snake*")
  50. (snake-pause-game))))
  51. ;; call a new snake game and in some new keybindings
  52. (defun my/snake ()
  53. (interactive)
  54. (define-key snake-mode-map (kbd "t") 'my/snake-move-down)
  55. (define-key snake-mode-map (kbd "c") 'my/snake-move-up)
  56. (define-key snake-mode-map (kbd "h") 'my/snake-move-left)
  57. (define-key snake-mode-map (kbd "n") 'my/snake-move-right)
  58. (snake))