Recently I have been learning about the Entity-Component-System architecture for video game programming. I think it will help out with my “World’s Tiniest RTS” game. I learned about it here, in Robert Nystrom’s Game Programming Patterns. I also heard on the Exploding Rabbit podcast how Jay Pavlina (of Super Mario Bros. Crossover fame) uses the pattern. Here is my Clojure code for it, currently:

(defn create-game []
  {:entities {}})

(defn create-entity []
  [(java.util.UUID/randomUUID)
   {}])

(defn add-entity [game entity]
  (update-in game [:entities] conj entity))

(defn add-component [game entity com data]
  (assoc-in game [:entities (first entity) com] data))

;;example
(let [e1 (create-entity)]
  (->
    (create-game)
    (add-entity e1)
    (add-component e1 :position [3 4])
    (add-component e1 :name "ball")))