added more items.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
@@ -1 +1 @@
|
||||
{:sound-volume 56.0, :music-volume 0.0}
|
||||
{:sound-volume 56.0, :music-volume 17.0}
|
||||
@@ -1,219 +0,0 @@
|
||||
(ns advent.utils
|
||||
(:refer-clojure :exclude [load])
|
||||
(:require [play-clj.core :refer :all]
|
||||
[play-clj.ui :refer :all]
|
||||
[play-clj.utils :refer :all]
|
||||
[play-clj.math :refer :all]
|
||||
[play-clj.g2d :refer :all]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.edn :as edn])
|
||||
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
|
||||
[com.badlogic.gdx.graphics.g2d TextureRegion]
|
||||
[com.badlogic.gdx.utils.viewport FitViewport]
|
||||
[com.badlogic.gdx.scenes.scene2d Actor Stage]
|
||||
[java.lang Object]))
|
||||
|
||||
(defn log-coords [screen entities]
|
||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
|
||||
(println (:input-x screen) (:input-y screen) "->" x y)))
|
||||
|
||||
(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :watch :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main])
|
||||
|
||||
(def settings (atom {:music-volume 50.0
|
||||
:sound-volume 75.0}))
|
||||
|
||||
(defn current-music-volume [& [factor]]
|
||||
(* (Math/pow (/ (:music-volume @settings) 100.0) 2)
|
||||
0.25
|
||||
(or factor 1.0)))
|
||||
|
||||
(defn current-sound-volume [& [factor]]
|
||||
(* (Math/pow (/ (:sound-volume @settings) 100.0) 2)
|
||||
0.5
|
||||
(or factor 1.0)))
|
||||
|
||||
(defn cursor [filename which]
|
||||
(let [scale 2
|
||||
base-cursor (pixmap filename)
|
||||
target-width (* 16 scale)
|
||||
target-height (* 16 scale)
|
||||
resized (Pixmap. target-width target-height (.getFormat base-cursor))
|
||||
index (.indexOf +all-cursors+ which)]
|
||||
#_(Pixmap/setFilter Pixmap$Filter/NearestNeighbour)
|
||||
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
|
||||
0 0 target-width target-height)
|
||||
resized ))
|
||||
|
||||
(defn save [entities]
|
||||
(spit "save.edn" (entities :state)))
|
||||
|
||||
(defn load []
|
||||
(assoc (edn/read-string (slurp "save.edn")) :active? true))
|
||||
|
||||
(defn load-settings! []
|
||||
(when (.exists (io/file "settings.edn"))
|
||||
(reset! settings (edn/read-string (slurp "settings.edn")))))
|
||||
|
||||
(defn save-settings! []
|
||||
(spit "settings.edn" @settings))
|
||||
|
||||
(defn get-font [filename]
|
||||
(let [font (bitmap-font filename)
|
||||
tr (bitmap-font! font :get-region)
|
||||
tx (.getTexture tr)]
|
||||
(texture! tx :set-filter Texture$TextureFilter/Linear Texture$TextureFilter/Linear)
|
||||
font))
|
||||
|
||||
(def +screen-width+ 320)
|
||||
(def +screen-height+ 240)
|
||||
|
||||
|
||||
(defn scaler-fn-with-baseline [baseline minimum-size & [maximum-size]]
|
||||
(let [maximum-size (or maximum-size 1.0)]
|
||||
(fn [[_ y]]
|
||||
(if (< y baseline) maximum-size
|
||||
(let [percent-complete (- 1.0 (/ (- y baseline) (- +screen-height+ baseline)))
|
||||
range (+ (* percent-complete (- maximum-size minimum-size)) minimum-size)]
|
||||
range)))))
|
||||
|
||||
(defn scaler-fn-from-image [image minimum-size maximum-size]
|
||||
(let [image (pixmap image)
|
||||
maximum-size (or maximum-size 1.0)]
|
||||
(fn [[x y]]
|
||||
(let [percent-complete (-> image
|
||||
(pixmap! :get-pixel x (- 240 y))
|
||||
color
|
||||
(.r))]
|
||||
(+ (* percent-complete (- maximum-size minimum-size)) minimum-size)))))
|
||||
|
||||
(defn dist [x1 y1 x2 y2 & {:keys [y-sign x-sign]}]
|
||||
(let [y-sign (or y-sign 1.0)
|
||||
x-sign (or x-sign 1.0)
|
||||
dx (* (- x1 x2) x-sign)
|
||||
dy (* y-sign (- y1 y2))]
|
||||
(Math/sqrt (+ (* dx dx) (* dy dy)))))
|
||||
|
||||
|
||||
(defn flip [anim]
|
||||
(animation (animation! anim :get-frame-duration)
|
||||
(for [src-frame (animation! anim :get-key-frames)
|
||||
:let [frame (texture (texture! src-frame :get-texture))]]
|
||||
(do
|
||||
(texture! frame :set-region src-frame)
|
||||
(texture! frame :flip true false)
|
||||
frame))))
|
||||
|
||||
(defn make-anim [file [w h] speed frames]
|
||||
(let [sheet (texture! (texture file) :split w h)]
|
||||
(animation speed (for [i frames]
|
||||
(aget sheet 0 i)))))
|
||||
(defn make-bird [screen p]
|
||||
(let [bird-sheet (texture! (texture "outside-castle/bird.png") :split 1 2)
|
||||
bird-stand (animation 0.15 (for [i [0 1]]
|
||||
(aget bird-sheet 0 i)))]
|
||||
(assoc (animation->texture screen bird-stand)
|
||||
:x 0
|
||||
:y 0
|
||||
:baseline 21
|
||||
:anim bird-stand
|
||||
:anim-start 0
|
||||
:path (catmull-rom-spline (map #(apply vector-2* %) p) true)
|
||||
:update-fn (fn [screen entities entity]
|
||||
(let [speed 0.05
|
||||
pos-f (- (* (:total-time screen) speed) (int (* (:total-time screen) speed)))
|
||||
v (vector-2 0 0)
|
||||
a (catmull-rom-spline! (:path entity) :value-at v pos-f)]
|
||||
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y)))))))
|
||||
|
||||
(defn update-path-location [speed screen entities entity]
|
||||
(let [pos-f (- (* (- (:total-time screen) (:path-start-time entity 0.0)) speed) (int (* (- (:total-time screen) (:path-start-time entity 0.0)) speed)))
|
||||
v (vector-2 0 0)
|
||||
a (catmull-rom-spline! (:path entity) :value-at v pos-f)]
|
||||
(assoc entity :x (vector-2! v :x) :y (vector-2! v :y))))
|
||||
|
||||
(defn find-override [entities [x y]]
|
||||
(first (concat (filter #(and ((:mouse-in? %) entities x y)
|
||||
|
||||
(:override %))
|
||||
(get-in entities [:room :interactions]))
|
||||
(filter #(and (:mouse-in? %)
|
||||
((:mouse-in? %) entities x y)
|
||||
(not= "ego" (:id %))
|
||||
(:script %))
|
||||
(vals (get-in entities [:room :entities])))
|
||||
(filter #(and ((:mouse-in? %) entities x y)
|
||||
(:script %))
|
||||
(get-in entities [:room :interactions])))))
|
||||
|
||||
|
||||
|
||||
(defn remove-interaction [entities id]
|
||||
(update-in entities [:room :interactions] (fn [i] (remove #(= id (:id %)) i))))
|
||||
|
||||
|
||||
(defn play-sound [snd]
|
||||
(music! snd :play))
|
||||
|
||||
(defn stop-sound [snd]
|
||||
(music! snd :stop))
|
||||
|
||||
(defn make-music [r]
|
||||
(doto (music r) (music! :set-looping true)))
|
||||
|
||||
|
||||
|
||||
(defn apply-tweens [screen entities tweens]
|
||||
(reduce (fn [e f]
|
||||
(f e (:total-time screen)))
|
||||
entities
|
||||
(vals tweens)))
|
||||
|
||||
(defn intersects? [e [x y]]
|
||||
(and (:object e)
|
||||
(< (:x e) x (+ (:x e) (or (:width e) (.getWidth (:object e)))))
|
||||
(< (:y e) y (+ (:y e) (or (:height e) (.getHeight (:object e)))))))
|
||||
|
||||
(defn get-current-music [entities]
|
||||
(let [time (get-in entities [:state :time])
|
||||
musics (:musics entities)
|
||||
override-music (musics (get-in entities [:music-override :value]))
|
||||
current-music (musics (get-in entities [:room :music]))
|
||||
current-time-music (musics (get-in entities [:room :music time]))]
|
||||
(or override-music current-music current-time-music)))
|
||||
|
||||
|
||||
(defn setup-viewport [screen width height]
|
||||
(let [cam (orthographic)
|
||||
viewport (FitViewport. width height cam)
|
||||
stage (Stage. viewport)]
|
||||
(update! screen :renderer stage :viewport viewport :camera cam)
|
||||
(.apply viewport)
|
||||
[cam viewport stage]))
|
||||
|
||||
(defn unproject
|
||||
([screen]
|
||||
(unproject screen [(:input-x screen) (:input-y screen)]) )
|
||||
([screen [x y]]
|
||||
(let [pj (.unproject ^FitViewport (:viewport screen) (vector-2 x y))
|
||||
x (.x pj)
|
||||
y (.y pj)]
|
||||
[x y])))
|
||||
|
||||
(defn project
|
||||
([screen [x y]]
|
||||
(let [pj (.project ^FitViewport (:viewport screen) (vector-2 x y))
|
||||
x (.x pj)
|
||||
y (.y pj)]
|
||||
[x y])))
|
||||
|
||||
(defn contains-point? [x1 y1 width height x y]
|
||||
(and (< x1 x (+ x1 width))
|
||||
(< y1 y (+ y1 height))))
|
||||
|
||||
(defn update-override [screen entities]
|
||||
(let [last-pos (unproject screen (get-in entities [:cursor :last-pos]))]
|
||||
(if (get-in entities [:state :active?])
|
||||
(if-let [mouse-override (find-override entities last-pos)]
|
||||
(assoc-in entities [:cursor :override] (or (:cursor mouse-override) (when (#{:main :active-main} (get-in entities [:cursor :last])) :active-main)))
|
||||
(assoc-in entities [:cursor :override] nil))
|
||||
entities)))
|
||||
@@ -1 +0,0 @@
|
||||
bryce@brycepro.local.77007
|
||||
@@ -130,4 +130,6 @@
|
||||
:walkie-talkies {:name "Communication devices" :value :walkie-talkies :cursor :walkie-talkies}
|
||||
:walkie-talkie {:name "Communication device" :value :walkie-talkie :cursor :walkie-talkie}
|
||||
:alarm-clock {:name "Time-keeping device" :value :alarm-clock :cursor :alarm-clock}
|
||||
:magic-slingshot {:name "The Slinger's Shot" :value :magic-slingshot :cursor :magic-slingshot}})
|
||||
:magic-slingshot {:name "The Slinger's Shot" :value :magic-slingshot :cursor :magic-slingshot}
|
||||
:shovel {:name "Shovel" :value :shovel :cursor :shovel}
|
||||
:broom {:name "Broom" :value :broom :cursor :broom}})
|
||||
|
||||
@@ -222,7 +222,8 @@
|
||||
(actions/walk-to entities :ego [267 70] :face :right)
|
||||
(actions/play-animation entities :ego :sigh)
|
||||
(actions/play-animation entities :ego :reach)
|
||||
(actions/remove-entity entities :broom))
|
||||
(actions/remove-entity entities :broom)
|
||||
(actions/give entities :broom))
|
||||
|
||||
(read-broom-plaque entities))))
|
||||
:shovel (assoc (texture "dream/shovel.png") :x 33 :y 122
|
||||
@@ -236,7 +237,8 @@
|
||||
(actions/walk-to entities :ego [61 72] :face :left)
|
||||
(actions/play-animation entities :ego :sigh)
|
||||
(actions/play-animation entities :ego :reach)
|
||||
(actions/remove-entity entities :shovel))
|
||||
(actions/remove-entity entities :shovel)
|
||||
(actions/give entities :shovel))
|
||||
|
||||
(read-shovel-plaque entities))))
|
||||
:sign (assoc (texture "dream/sign.png") :x 229 :y 33 :baseline 207)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
(let [{:keys [x y]} (input->screen screen {:x (:input-x screen) :y (:input-y screen)})]
|
||||
(println (:input-x screen) (:input-y screen) "->" x y)))
|
||||
|
||||
(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :watch :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main])
|
||||
(def +all-cursors+ [:main :wool :mushrooms :carrot :right :down :left :up :flask :flask-with-contents :trophy :ladder :stick :cat-toy :balloon :frog-legs :teddy :portrait :recipe :glass-eye :motivational-tapes :used-earplugs :grass :slobber :flask-with-strength :medal :kiss :sword :hourglass :mandrake :ball-n-chain :key :rope :crowbar :note-1 :ash :sack-lunch :flies :spear :monocle :feather :spell-component :money :watch :broken-clock :slingshot :camera :walkie-talkies :alarm-clock :walkie-talkie :flask-water :flask-water-stuff :flask-water-stuff-2 :note-2 :magic-slingshot :active-main :shovel :broom])
|
||||
|
||||
(def settings (atom {:music-volume 50.0
|
||||
:sound-volume 75.0}))
|
||||
|
||||
Reference in New Issue
Block a user