A ClojureScript game library
Clojure HTML
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Introduction

A ClojureScript library for making games. It uses p5.js underneath. And then the terrifying, irrational monstrosity of the web underneath that.

Try the interactive docs!

If you want to make music for your game, edna is a good companion library and the Boot template below is preconfigured with it.

Getting Started

There are several ways to create a project:

  • Boot: boot -d boot/new new -t play-cljs -n hello-world
  • Nightcode: Choose "Game Project" from its start menu
  • Nightcoders.net: Choose "Game" when creating a new project
  • Lightmod: Choose one of the game templates

Documentation

(ns hello-world.core
  (:require [play-cljs.core :as p]))

(defonce game (p/create-game 500 500))
(defonce state (atom {}))

; define a screen, where all the action takes place
(def main-screen
  (reify p/Screen
  
    ; runs when the screen is first shown
    (on-show [this]
      ; start the state map with the x and y position of the text we want to display
      (reset! state {:text-x 20 :text-y 30}))

    ; runs when the screen is hidden
    (on-hide [this])

    ; runs every time a frame must be drawn (about 60 times per sec)
    (on-render [this]
      ; we use `render` to display a light blue background and black text
      ; as you can see, everything is specified as a hiccup-style data structure
      (p/render game
        [[:fill {:color "lightblue"}
          [:rect {:x 0 :y 0 :width 500 :height 500}]]
         [:fill {:color "black"}
          [:text {:value "Hello, world!" :x (:text-x @state) :y (:text-y @state) :size 16 :font "Georgia" :style :italic}]]])
      ; increment the x position of the text so it scrolls to the right
      (swap! state update :text-x inc))))

; start the game
(doto game
  (p/start)
  (p/set-screen main-screen))

Licensing

All files that originate from this project are dedicated to the public domain. I would love pull requests, and will assume that they are also dedicated to the public domain.