Using Quil for a game jam

141 views
Skip to first unread message

Gary Deer

unread,
Dec 11, 2013, 4:25:22 PM12/11/13
to clj-pro...@googlegroups.com
At work we're having our annual game jam.  From Friday night to Sunday morning two other team mates and I will be trying to build a simple game in Clojure.

I'm trying to use Chris Granger's Component Entity System and I was wondering if anyone has used Quil in this way?

I've been experimenting with Quil to get a better feel for it and it seems my code is ending up very imperative.

I'd really appreciate some advice on what I would need to do to have a more declarative style. 

Here's an example to show you what I'm talking about https://github.com/LeonKni/gamejam2013/blob/master/src/gamejam/paddle-ball.clj

Thanks

-Gary


Nikita Beloglazov

unread,
Dec 11, 2013, 6:12:07 PM12/11/13
to clj-pro...@googlegroups.com
Hi Gary

1. Take a look at state functions in quil. They allow you to store anything in map-like manner in sketch. You can store there all of your atoms. Advantage of this would be the fact that you don't have global vars and all game state bounded to specific sketch. You run multiple sketches at the same time. Link.

2. You can store game state as single map in atom and update the map on each iteration instead of using 6 atoms. Single-map approach is more functional-style but it's probably slower and requires more code.

3. I would separate updating of game state and drawing. Currently they both happen in same "draw" function. Basically on each iteration first you call "update-state" function that changes speed, position, hit/miss and then you call draw-state.

Here is my version using all three advices: https://gist.github.com/nbeloglazov/7920049
It's bigger than your solution and probably a little slower due to using single map instead of bunch of vars. Though update-* functions are pure they are not deterministic because they depend on global state: (width), (height), (mouse-x) so it's not ideal FP functions :) But I think it's closer to FP style.

Thank you,
Nikita


--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Gary Deer

unread,
Dec 12, 2013, 11:20:41 AM12/12/13
to clj-pro...@googlegroups.com
Yes! That is exactly what I was looking for.  I think I'm on the right track now.  

I'm not sure if your solution is slower because it still maintains 60 fps.  I monitored this on the game screen with (text (str (int (current-frame-rate))) 10 30)
On my current box I did not take an fps hit by using the big map.  I'll definitely have to see how it scales.

So the next thing I need to do is write some functions so I can compose state.  Going with the example in Chris Granger's talk at the 2012 Conj, I would want to take ball-x and ball-y and generalize that as the component "position"  like:
(component position [x y]
           :x x
           :y y)

then my render would have 
(defn render-ball [ent]
(letc ent [pos :position

letc is the neat macro that lets you just specify the entity once and pass in a vector of components to look up for it

It's a rough example to try to follow because he was targeting node and had to write everything in 48 hours, but I think it's a good way to write games, so I'm hoping after this weekend I'll come away with a greater understanding of Quil and the component entity system so that I could write a library for using Quil in this way.

Anyway, thanks for taking the time to write that example. I don't know how I missed the state functions, but that was exactly what I needed.

Gary Deer

unread,
Dec 19, 2013, 4:55:20 PM12/19/13
to clj-pro...@googlegroups.com
Here is our final product https://github.com/LeonKni/tube-defender

We used simplecs for the ces "framework" and Quil for the rendering.  Its pretty awful but we were a 3-man team working with new libraries and paradigms. 

I've had about a year of Clojure experience, Peter has about half that, Leon was writing Clojure code for the first time.  Quil was new to all of us and using Simplecs was especially new to all of us. 

All things considering we were lucky to have anything working at all. 

Everyone at the demo was pretty amazed as well. 
Reply all
Reply to author
Forward
0 new messages