first of all, this is my first post, so if I ask FAQs or deserve to
RTFM, please tell me.
I am learning clojure, and trying to adapt some game code written in a
Java framework called Slick. After a couple of beginner's mistake (the
kind you do to learn ;) ), I got a working convestion of a Scoller
example. Still, there are some things that I don't find very elegant,
or where I'm pretty sure to be reinventing some wheel.
Code is here :
* The game is tile-based. I need to build up a collision map ("can the
tank walk on cell [3,2] ?"). Java does it with a two-dimensional array
of booleans. From discussion here :
, I choosed to use a vector of vector (i probably should'nt have, but
that's another point). I wrote this :
"Is a position blocked in the screen?"
[screen x y]
(let [i (int x)
j (int y)]
(true? (get (get (screen :blocked) i) j))))
(vec (map (fn [j] (cell-generator i j))
(range 0 w)))))
[w h cell-generator]
(vec (map (make-row-generator cell-generator w)
(range 0 h))))
"Builds a double dimensioned array telling
whether a cell is blocked"
[m w h]
(fn [i j]
(let [tileId (.getTileId m i j 0)]
(.getTileProperty m tileId "blocked" "false"))]
(the 'm' is a slick-specific stucture that holds the tile map).
Am I duplicating some existing library to build matrices ? Is there a
cleaner way to do it ?
* In a method I check for collisions :
"Try and move a player in the screen given a direction.
Returns a list with the moved player, and a
boolean indicating whether the move was successfull.
[player screen dx dy]
(let [new_x (+ (player :x) dx)
new_y (+ (player :y) dy)]
(let [bxy (blocked? screen new_x new_y)
bx (blocked? screen new_x (player :y))
by (blocked? screen (player :x) new_y)]
[(assoc player :y new_y), true])
[(assoc player :x new_x), true])
[(assoc player :x new_x :y new_y), true]))))
Will i get used to the nested 'if' blocks someday ? Any way to write
the equivalent of a switch case here, if only to improve
* Finally, my code starts with a rather ugly
(:import (org.newdawn.slick Animation
I know there is no way to import org.newdawn.slick.* (as discussed
). What do you do in programs that need huge list of imports ? I'm
kinda spoiled by the Eclipse way of doing this, which is roughly :
import everything, forget about it, and let you IDE clear up the list.
And at least for development part it make things easier. If I hadn't
had the exact list of import to copy paste in this case, I would
probably have gone bored and depressed by the second class to import
manually (lazyness is not only for evaluation ;) )
Thanks for any ideas, sorry if post is too long / newbie-like.