oakes.play-cljs

https://github.com/oakes/play-cljs.git

git clone 'https://github.com/oakes/play-cljs.git'

(ql:quickload :oakes.play-cljs)
288

Note: I am focusing my efforts on play-cljc, a library for games that run on both the desktop and the web.

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 Clojure CLI template below is preconfigured with it.

Getting Started

There are several ways to create a project:

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))

Development

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.