Files
tickstales/desktop/src-common/advent/screens/cards.clj

52 lines
2.3 KiB
Clojure

(ns advent.screens.cards
(:require [play-clj.core :refer :all]
[play-clj.ui :refer :all]
[play-clj.utils :refer :all]
[play-clj.g2d :refer :all]
[clojure.pprint]
[advent.pathfind]
[clojure.core.async :refer [put! <! <!! >! >!! chan go thread take! alts!!]]
)
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.scenes.scene2d.utils Align]
[com.badlogic.gdx Screen]))
(def min-x (+ 16 (* 320 0.1)))
(defscreen card-screen
:on-show
(fn [screen entities]
(update! screen :renderer (stage) :camera (orthographic))
{:all-cards {:heal-big (texture "cards/heal-big.png")
:heal-med (texture "cards/heal-med.png")
:heal-small (texture "cards/heal-small.png")
:recharge-big (texture "cards/recharge-big.png")
:recharge-med (texture "cards/recharge-med.png")
:recharge-small (texture "cards/recharge-small.png")}
:health-bar (texture "cards/health-bar.png")
:mana-bar (texture "cards/mana-bar.png")
:bar (texture "cards/bar.png")
:player {:hp 65
:mana 50
:hand [:heal-big :heal-small :recharge-big :recharge-big :recharge-big]}})
:on-render
(fn [screen [entities]]
(let [player-hand (for [[c index] (map vector (get-in entities [:player :hand]) (range))]
(assoc (get-in entities [:all-cards c]) :x (+ min-x (* index 50)) :y 32))
player-health (assoc (get-in entities [:health-bar])
:x min-x
:y 16
:width (* (/ (get-in entities [:player :hp]) 100.0) 50))
player-mana (assoc (get-in entities [:mana-bar])
:x min-x
:y 5
:width (get-in entities [:player :mana]))]
(render! screen player-hand)
(render! screen [player-health (assoc (get-in entities [:bar] ) :x min-x :y 16)])
(render! screen [player-mana (assoc (get-in entities [:bar] ) :x min-x :y 5)]))
entities)
:on-resize (fn [screen entities]
(size! screen 320 240)))