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
|
||||
(:require [play-clj.core :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
|
||||
:on-show
|
||||
(fn [screen entities]
|
||||
(update! screen :renderer (stage) :camera (orthographic))
|
||||
(let [player-sheet (texture! (texture "player.png") :split 18 36)
|
||||
background (texture "bg3.png")]
|
||||
[(assoc background :scale-y 1.0 :scale-x 1.0 :origin-y 0 :origin-x 0 :ego? false :x -60 :y -34)
|
||||
{:right (animation 0.1 (for [i (range 8)]
|
||||
_ (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.1 (for [i (range 8)]
|
||||
:left (animation 0.075 (for [i (range 8)]
|
||||
(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))))
|
||||
: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}]))
|
||||
|
||||
:on-render
|
||||
@@ -25,23 +55,33 @@
|
||||
(render! screen (for [entity entities]
|
||||
(if (:ego? 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))
|
||||
{:x-velocity -1 :anim (:left entity)})
|
||||
(when (< (:x entity) 0)
|
||||
{:x-velocity 1 :anim (:right entity)}))
|
||||
|
||||
entity))))
|
||||
:on-resize
|
||||
(fn [screen entities]
|
||||
(height! screen 135))
|
||||
:on-resize (fn [screen entities]
|
||||
(size! screen 320 240))
|
||||
|
||||
:on-scrolled
|
||||
(fn [screen entities]
|
||||
#_: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)))
|
||||
(set-screen! this main-screen)
|
||||
#_(input! :set-cursor-catched true)))
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
|
||||
(defn -main
|
||||
[]
|
||||
(LwjglApplication. advent "advent" 1920 1080)
|
||||
(LwjglApplication. advent "advent" 1280 960)
|
||||
(Keyboard/enableRepeatEvents true))
|
||||
|
||||