88 lines
3.6 KiB
Clojure
88 lines
3.6 KiB
Clojure
(ns advent.core
|
|
(:require [play-clj.core :refer :all]
|
|
[play-clj.ui :refer :all]
|
|
[play-clj.utils :refer :all]
|
|
[play-clj.g2d :refer :all]
|
|
[clojure.pprint])
|
|
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter]))
|
|
|
|
(def scale 4)
|
|
(def +screen-width+ 320)
|
|
(def +screen-height+ 240)
|
|
|
|
(defn cursor [filename index]
|
|
(let [base-cursor (pixmap filename)
|
|
target-width (* 16 scale)
|
|
target-height (* 16 scale)
|
|
resized (Pixmap. target-width target-height (.getFormat base-cursor))]
|
|
(Pixmap/setFilter Pixmap$Filter/NearestNeighbour)
|
|
(pixmap! resized :draw-pixmap base-cursor (* index 16) 0 16 16
|
|
0 0 target-width target-height)
|
|
resized ))
|
|
|
|
(defn right-click [screen entities]
|
|
(if (= (button-code :right) (:button screen))
|
|
(for [entity entities]
|
|
(if (= (:id entity) "cursor")
|
|
(let [entity (assoc entity :cursor-index (case (:cursor-index entity)
|
|
0 1
|
|
1 0))]
|
|
(input! :set-cursor-image (cursor "cursor.png" (:cursor-index entity)) 0 0 )
|
|
entity)
|
|
entity))))
|
|
|
|
(defscreen main-screen
|
|
:on-show
|
|
(fn [screen entities]
|
|
(update! screen :renderer (stage) :camera (orthographic))
|
|
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
|
_ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0)
|
|
background (texture "bg5.png")]
|
|
[{:id "cursor" :cursor-index 0}
|
|
(assoc background :origin-y 0 :origin-x 0 :ego? false :x 0 :y 0 :scale-x 1 :scale-y 1)
|
|
{:right (animation 0.075 (for [i (range 8)]
|
|
(texture (aget player-sheet 0 i))))
|
|
:left (animation 0.075 (for [i (range 8)]
|
|
(texture (aget player-sheet 1 i))))
|
|
:anim (animation 0.075 (for [i (range 8)]
|
|
(texture (aget player-sheet 0 i))))
|
|
:x 0 :y 75 :origin-x 0 :origin-y 0 :x-velocity 1
|
|
:ego? true}]))
|
|
|
|
:on-render
|
|
(fn [screen entities]
|
|
(clear!)
|
|
(render! screen (for [entity entities]
|
|
(if (:ego? entity)
|
|
(merge (animation->texture screen (:anim entity))
|
|
{:ego? (:ego? entity) :x (+ (:x entity) (:x-velocity entity)) :y 75 :origin-x 0 :origin-y 0 :anim (:anim entity) :x-velocity (:x-velocity entity) :left (:left entity) :right (:right entity)}
|
|
(when (> (:x entity) (width screen))
|
|
{:x-velocity -1 :anim (:left entity)})
|
|
(when (< (:x entity) 0)
|
|
{:x-velocity 1 :anim (:right entity)}))
|
|
|
|
entity))))
|
|
:on-resize (fn [screen entities]
|
|
(size! screen 320 240))
|
|
|
|
#_:on-mouse-moved #_(fn [screen entities]
|
|
(for [entity entities]
|
|
(if (= (:id entity) "cursor")
|
|
(let [{:keys [x y]} (input->screen screen (min +screen-width+ (max 0 (:input-x screen))) (max 0 (min +screen-height+ (:input-y screen))))]
|
|
(assoc entity :x x :y y))
|
|
entity)))
|
|
|
|
:on-touch-down (fn [screen entities]
|
|
(right-click screen entities))
|
|
|
|
#_:on-scrolled
|
|
#_(fn [screen entities]
|
|
(set! (. (:camera screen) zoom) (min 1.5 (max (+ (.zoom (:camera screen)) (* 0.01 (:amount screen))) 1)))
|
|
nil))
|
|
|
|
(defgame advent
|
|
:on-create
|
|
(fn [this]
|
|
(set-screen! this main-screen)
|
|
#_(input! :set-cursor-catched true)))
|