Hey, I'm writing some Clojure game stuff, and I'm having trouble coming up with a sensible model for the game objects.
The basic idea is that I have a bunch of objects that represent the game, and call 'act' on them, supplying the current world to get their next state. The objects have a few properties, like an ID, a position, a sprite and any extra information an object might need. I also want to make it implement java.awt.Shape for collision detection using an internal Rectangle. To write a game, one must define new types of objects, and implement their 'act' function. My initial thought was to use a record and an actor protocol. The first problem with this is that the properties of the record are not embedded in the actor protocol, so there might be actors that blow up rendering by having no sprite for example. Another problem is that subclasses would need to implement Shape themselves. Yet another one is that updating the position of a record via assoc does not update the Rectangle. Then I considered using a multimethod on type, which can use the :type metadata. This leads to a model where no subclasses of the game object are made, but merely given a different type on their meta. To integrate the Rectangle with the object, I considered using a type instead, and use classic getters and setters. This has the advantage that I can manage the Rectangle and that the properties of the object are embedded in the protocol. Problem #1 here is that I lose the ability to store arbitrary data on the object. This can be circumvented by using the extension model. But having now defined even more methods, I place an even larger implementation burden on the child type. What would be a clean way to do this? Groeten, Pepijn de Vos -- Sent from my iPod Shuffle http://pepijndevos.nl -- 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
