Skip to content

Instantly share code, notes, and snippets.

@timothypratley
Created December 27, 2018 11:59
Show Gist options
  • Save timothypratley/bd24a6da5874fb3fb62cd141b6750fee to your computer and use it in GitHub Desktop.
Save timothypratley/bd24a6da5874fb3fb62cd141b6750fee to your computer and use it in GitHub Desktop.

canvas: html

Hi!

Today we will build a rogue like game...


First we need to draw something on the "screen". We do this by calling html.

Try this out:

(html [:svg {:style {:background "red"}}])

You should see a red canvas get drawn.


Let's put our game inside a function so we can more easily render it:

(defn game []
  [:svg {:style {:background "red"}}])

Now we can update the view like so:

(html [game])

Try changing the game slightly:

(defn game[]
  [:svg {:style {:background "green"}}])

And then update the view:

(html [game])

We will be drawing charaters on a 200x200 grid...

(defn game []
  [:svg {:width  200
         :height 200
         :on-context-menu #(identity false)
         :view-box (str 0 " " 0 " " 200 " " 200)
         :pointer-events :all}
   (let [x 5
         y 4
         glyph "@"
         type :text]}]
     [type {:x (+ (* 20 x) 10) :y (+ (* 20 y) 10)} glyph])])

Update the view and you should see an "@" character displayed.


More to come later...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment