api.scm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. (define (parse-input-object input-object)
  2. (define command-string (cdr (assq 'command input-object)))
  3. (cond
  4. ((string=? command-string "UP") 'up)
  5. ((string=? command-string "DOWN") 'down)
  6. ((string=? command-string "LEFT") 'left)
  7. ((string=? command-string "RIGHT") 'right)
  8. ((string=? command-string "A") 'a)
  9. ((string=? command-string "B") 'b)
  10. ((string=? command-string "X") 'x)
  11. ((string=? command-string "Y") 'y)
  12. (else
  13. (error "parse-input-object" "Value not recognized for command" command-string))))
  14. (define global-game-state #f)
  15. (define (current-level)
  16. (global-level global-game-state))
  17. (define (current-menu)
  18. (global-menu global-game-state))
  19. (define (api-push-input! input-object)
  20. (push-button! (parse-input-object input-object)))
  21. (define (push-button! button)
  22. (case button
  23. ((up)
  24. (cond
  25. ((current-menu)
  26. (menu-scroll! (current-menu) 'up))
  27. (else
  28. (move-player-and-check-complete! global-game-state 'up))))
  29. ((down)
  30. (cond
  31. ((current-menu)
  32. (menu-scroll! (current-menu) 'down))
  33. (else
  34. (move-player-and-check-complete! global-game-state 'down))))
  35. ((left)
  36. (cond
  37. ((current-menu)
  38. (display "Pressed left in a menu.\n"))
  39. (else
  40. (move-player-and-check-complete! global-game-state 'left))))
  41. ((right)
  42. (cond
  43. ((current-menu)
  44. (display "Pressed right in a menu.\n"))
  45. (else
  46. (move-player-and-check-complete! global-game-state 'right))))
  47. ((a)
  48. (cond
  49. ((current-menu)
  50. (menu-select! (current-menu)))
  51. (else
  52. (display "Pressed a outside a menu.\n"))))
  53. ((b)
  54. (cond
  55. ((current-menu)
  56. (menu-close! (current-menu)))
  57. (else
  58. (try-undo-last-move! global-game-state))))
  59. ((x)
  60. (cond
  61. ((current-menu)
  62. (display "Pressed x in a menu.\n"))
  63. (else
  64. (open-pause-menu! global-game-state))))
  65. ((y)
  66. (cond
  67. ((current-menu)
  68. (display "Pressed y in a menu.\n"))
  69. (else
  70. (display "Pressed y outside a menu.\n"))))
  71. (else (error "button not recognized" button)))
  72. "Accepted")