Hi

Nice. I have also created a snake game (not as complete as yours) in 
ClojureScript if you want to take a look and compare approaches: 
http://cljsfiddle.net/fiddle/jonase.snake

Jonas

On Thursday, January 30, 2014 11:23:59 AM UTC+2, Joaquín Oltra wrote:
> Hi!
> 
> I've mostly finished a game I've been writing the last couple of weeks. It is 
> a snake game written with clojurescript and canvas. It also uses core.async 
> for coordination and communication between the UI and the game logic.
> 
> 
> 
> 
> 
> 
> It is my first clojure/script program (I've dabbled with the language a lot 
> before not really doing anything). Here is the demo:
> 
> 
> 
> 
> 
> 
> http://chimeces.com/cnake/
> 
> 
> And the code: https://github.com/joakin/cnake/
> 
> 
> It is a bit more complex than it could be for that kind of game but I wanted 
> to experiment with certain ideas and core.async.
> 
> 
> 
> A bit about the architecture:
> 
> The game is separated in UI and Game logic.
> 
> 
> The UI instantiates the game logic, and they are separated by an input 
> channel (commands that the game receives) and an ouput channel (notifos that 
> the game logic spits).
> 
> Some of the whys are:
> 
> 
> With the commands I'm am able to directly map and filter key 
> events to commands and pipe those to the game via chan (which results in
>  a pretty elegant solution).
> https://github.com/joakin/cnake/blob/master/src/cnake/ui.cljs#L205
> 
> With the notifos, it would be easy for example to react to events of the game 
> (not just reading its state to paint), for example to play sounds when moved, 
> or when a pill is eaten (thats on the TODO)
> 
> 
> https://github.com/joakin/cnake/blob/master/src/cnake/game.cljs#L190
> https://github.com/joakin/cnake/blob/master/src/cnake/ui.cljs#L123
> 
> 
> 
> 
> 
> With this separation it should be easy to implement a different UI without 
> touching the game logic at all, and just by sending commands and listening to 
> notifications, which is pretty cool and simple.
> 
> 
> 
> 
> Another interesting thing (in my opinion) is that the game coordination and 
> state is enclosed in a state machine in the game/game! function that mutates 
> state in the fn listening to the commands and recuring. That way the rest of 
> the game is implemented through pure functions that get data, modify it and 
> return it.
> 
> 
> 
> 
> 
> The code is fairly commented, and it is not very long, 200 lines each ui and 
> game file.
> 
> 
> This is my first complete program in clojurescript (and also using canvas 
> btw). I would love to get feedback on code style, structure, idioms, or 
> whatever else.
> 
> 
> 
> Cheers

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to