Skip to content

Instantly share code, notes, and snippets.

@saikyun
Created April 17, 2021 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saikyun/62bfecf2a8410e42859fa23826261ebd to your computer and use it in GitHub Desktop.
Save saikyun/62bfecf2a8410e42859fa23826261ebd to your computer and use it in GitHub Desktop.
(def mario @{:x 0 :y 0 :vx 0 :vy 0})
(defn physics
[dt mario]
(-> mario
(update :x + (* (mario :vx) dt))
(update :y + (* (mario :vy) dt))))
(defn walk
[x mario]
(update mario :vx * x 0.1))
(defn step
[[dt dir] mario]
(walk (dir :x) (physics dt mario)))
(defn render
[[w h] mario]
(draw-rectangle 0 0 w h :black)
(draw-rectangle (mario :x) (mario :y) 35 35 :green))
(def keyboard-arrows @{:x 0 :y 0})
(defn fps
[fps]
40)
(defn lift2
[f a1 a2]
# ???
)
(defn foldp
[f rec pushers]
# ???
)
(def input (lift2 array (fps 25) keyboard-arrows))
(defn main
[]
(render [500 500]
(foldp step mario input)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment