+1 for Daniels suggestion.
Swing can be quite bothersome if you just want a canvas and key-events.
I would avoid multimethods:
(defn calc-new-pos [xy prev-pos dir]
(condp = [xy dir]
[:x :right] (+ prev-pos step)
[:x :left]) (- prev-pos step)
[:y :down] (+ prev-pos step)
[:y :up] (- prev-pos step)
:default prev-pos)
But really I think you should see the current 'velocity' as 2d vector eg:
[x y] [step 0] [0 -step]
Both speed and direction integrated.
so:
(defn calc-new-pos [pos vel]
(map + pos vel))
I would avoid multimethods:
(defn inside-window? [dir canvas [x y]]
(condp = dir
:left (>= x (.getX canvas))
:right (<= x (+ (.getX canvas) (.getWidth canvas)))
:up (>= y (.getY canvas))
:down (<= y (+ (.getY canvas) (.getHeight canvas)))))
inside-window? depends on information from the actual window, I would
decouple the game-state from swing.
Remember: functional is good :)
alternative:
(defn inside-window? [[x y]]
(and
(< -1 x max-x)
(< -1 y max-y)))
Also look up the 'doto' macro.
And I should go read up on what core.async does, I have ignored it for too
long.
On Sun, Aug 4, 2013 at 5:56 PM, Daniel <[email protected]> wrote:
> Or quil, a processing wrapper, would be well suited to this application.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.