Skip to Main Content
Hands-On Reactive Programming with Clojure - Second Edition
book

Hands-On Reactive Programming with Clojure - Second Edition

by Konrad Szydlo, Leonardo Borges
January 2019
Intermediate to advanced content levelIntermediate to advanced
298 pages
7h 46m
English
Packt Publishing
Content preview from Hands-On Reactive Programming with Clojure - Second Edition

Game entities

Our game will have only two entities – one representing the spaceship and the other representing bullets. To better organize the code, we will put all entity-related code in its own file, src/reagi_game/entities.cljs. This file will also contain some of the rendering logic, so we'll need to require monet:

(ns reagi-game.entities 
  (:require [monet.canvas :as canvas] 
            [monet.geometry :as geom])) 

Next, we'll add a few helper functions so that we avoid repeating ourselves too much:

(defn shape-x [shape] 
  (-> shape :pos deref :x)) 
 
(defn shape-y [shape] 
  (-> shape :pos deref :y)) 
 
(defn shape-angle [shape] 
  @(:angle shape)) 
 
 
(defn shape-data [x y angle] 
  {:pos   (atom {:x x :y y}) 
   :angle (atom angle)}) 

The first three functions are simply ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Clojure Programming

Clojure Programming

Chas Emerick, Brian Carper, Christophe Grand
Clojure in Action, Second Edition

Clojure in Action, Second Edition

Amit Rathore, Francis Avila
Programming Clojure, 2nd Edition

Programming Clojure, 2nd Edition

Stuart Halloway, Aaron Bedra

Publisher Resources

ISBN: 9781789346138Supplemental Content