Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

> Quite addicting. Good job!

Thanks!

> If you hold right, then tap down, then release down, holding right the entire time, I expect to move down only once then continue moving right. But currently you will keep going down for as long as right is held.

Unfortunately, this is a limitation with Quil/JavaScript (e.g. see the official Quil example which exhibits a similar behavior when you press/hold multiple keys and release one by one: link) and I was unable to work around it. You will experience similar misbehavior even if you press/hold some completely unrelated (unused) key.

If somebody reading this know if there's a solution for this problem, I'm eager to hear it.

(+1)

Hi, it is related to my previous comment:
your post in aMAZE jam comments


There is a solution. You save pressed keys into the state and then you reduce on top of them. 
You can see the implementation in this framework based on top of Quill.
https://github.com/Kimbsy/quip/blob/master/src/quip/input.clj

(defn key-pressed
  "Reduce applying a handler function:
    (f state e)
  accross the collection of `:key-pressed-fns` in the current scene."
  [{:keys [input-enabled? scenes current-scene] :as state} e]
  (if input-enabled?
    (let [default-handled-state (default-key-pressed state e)
          scene-handlers        (get-in scenes [current-scene :key-pressed-fns])]
      (reduce (fn [acc-state f]
                (f acc-state e))
              default-handled-state
              scene-handlers))
    state))
(defn key-released
  "Reduce applying a handler function:
    (f state e)
  accross the collection of `:key-released-fns` in the current scene."
  [{:keys [input-enabled? scenes current-scene] :as state} e]
  (if input-enabled?
    (let [default-handled-state (default-key-released state e)
          scene-handlers        (get-in scenes [current-scene :key-released-fns])]
      (reduce (fn [acc-state f]
                (f acc-state e))
              default-handled-state
              scene-handlers))
    state))
(+1)

Thanks for the link and the example! I will take a look, and try to implement it this way.

The "set of held keys + reduce" idea worked like a charm! Thank you very much!

As we are in the voting phase, I cannot upload the new version, but if you would like to try it, you can do it on this link.