mouse working.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
BIN
desktop/resources/bg4.png
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
BIN
desktop/resources/bg4.png.pxi
Normal file
BIN
desktop/resources/bg4.pxi
Normal file
BIN
desktop/resources/bg5.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
desktop/resources/cursor.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
desktop/resources/cursorr.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
desktop/resources/lttp.pxpalette
Normal file
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.3 KiB |
@@ -1,22 +1,52 @@
|
|||||||
(ns advent.core
|
(ns advent.core
|
||||||
(:require [play-clj.core :refer :all]
|
(:require [play-clj.core :refer :all]
|
||||||
[play-clj.ui :refer :all]
|
[play-clj.ui :refer :all]
|
||||||
[play-clj.g2d :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
|
(defscreen main-screen
|
||||||
:on-show
|
:on-show
|
||||||
(fn [screen entities]
|
(fn [screen entities]
|
||||||
(update! screen :renderer (stage) :camera (orthographic))
|
(update! screen :renderer (stage) :camera (orthographic))
|
||||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||||
background (texture "bg3.png")]
|
_ (input! :set-cursor-image (cursor "cursor.png" 0) 0 0)
|
||||||
[(assoc background :scale-y 1.0 :scale-x 1.0 :origin-y 0 :origin-x 0 :ego? false :x -60 :y -34)
|
background (texture "bg5.png")]
|
||||||
{:right (animation 0.1 (for [i (range 8)]
|
[{: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))))
|
(texture (aget player-sheet 0 i))))
|
||||||
:left (animation 0.1 (for [i (range 8)]
|
:left (animation 0.075 (for [i (range 8)]
|
||||||
(texture (aget player-sheet 1 i))))
|
(texture (aget player-sheet 1 i))))
|
||||||
:anim (animation 0.1 (for [i (range 8)]
|
:anim (animation 0.075 (for [i (range 8)]
|
||||||
(texture (aget player-sheet 0 i))))
|
(texture (aget player-sheet 0 i))))
|
||||||
:x 0 :y 25 :origin-x 0 :origin-y 0 :x-velocity 1
|
:x 0 :y 75 :origin-x 0 :origin-y 0 :x-velocity 1
|
||||||
:ego? true}]))
|
:ego? true}]))
|
||||||
|
|
||||||
:on-render
|
:on-render
|
||||||
@@ -25,23 +55,33 @@
|
|||||||
(render! screen (for [entity entities]
|
(render! screen (for [entity entities]
|
||||||
(if (:ego? entity)
|
(if (:ego? entity)
|
||||||
(merge (animation->texture screen (:anim entity))
|
(merge (animation->texture screen (:anim entity))
|
||||||
{:ego? (:ego? entity) :x (+ (:x entity) (:x-velocity entity)) :y 0 :origin-x 0 :origin-y 0 :anim (:anim entity) :x-velocity (:x-velocity entity) :left (:left entity) :right (:right 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))
|
(when (> (:x entity) (width screen))
|
||||||
{:x-velocity -1 :anim (:left entity)})
|
{:x-velocity -1 :anim (:left entity)})
|
||||||
(when (< (:x entity) 0)
|
(when (< (:x entity) 0)
|
||||||
{:x-velocity 1 :anim (:right entity)}))
|
{:x-velocity 1 :anim (:right entity)}))
|
||||||
|
|
||||||
entity))))
|
entity))))
|
||||||
:on-resize
|
:on-resize (fn [screen entities]
|
||||||
(fn [screen entities]
|
(size! screen 320 240))
|
||||||
(height! screen 135))
|
|
||||||
|
|
||||||
:on-scrolled
|
#_:on-mouse-moved #_(fn [screen entities]
|
||||||
(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)))
|
(set! (. (:camera screen) zoom) (min 1.5 (max (+ (.zoom (:camera screen)) (* 0.01 (:amount screen))) 1)))
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(defgame advent
|
(defgame advent
|
||||||
:on-create
|
:on-create
|
||||||
(fn [this]
|
(fn [this]
|
||||||
(set-screen! this main-screen)))
|
(set-screen! this main-screen)
|
||||||
|
#_(input! :set-cursor-catched true)))
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
|
|
||||||
(defn -main
|
(defn -main
|
||||||
[]
|
[]
|
||||||
(LwjglApplication. advent "advent" 1920 1080)
|
(LwjglApplication. advent "advent" 1280 960)
|
||||||
(Keyboard/enableRepeatEvents true))
|
(Keyboard/enableRepeatEvents true))
|
||||||
|
|||||||