Skip to content

Commit

Permalink
Add koalio
Browse files Browse the repository at this point in the history
  • Loading branch information
oakes committed Mar 14, 2019
1 parent 461da61 commit 8204ce2
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ pom.xml.asc
*~
.*
!.gitignore
**/main.out
2 changes: 1 addition & 1 deletion super-koalio/deps.edn
@@ -1,6 +1,6 @@
{:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.10.0"}
play-cljc {:mvn/version "0.1.0"}
play-cljc {:mvn/version "0.2.0-SNAPSHOT"}
org.lwjgl/lwjgl {:mvn/version "3.2.1"}
org.lwjgl/lwjgl-glfw {:mvn/version "3.2.1"}
org.lwjgl/lwjgl-opengl {:mvn/version "3.2.1"}
Expand Down
Binary file added super-koalio/resources/public/koalio.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions super-koalio/resources/public/level1.tmx

Large diffs are not rendered by default.

Binary file removed super-koalio/resources/public/player_walk1.png
Binary file not shown.
Binary file removed super-koalio/resources/public/player_walk2.png
Binary file not shown.
Binary file removed super-koalio/resources/public/player_walk3.png
Binary file not shown.
Binary file added super-koalio/resources/public/tileSet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 19 additions & 13 deletions super-koalio/src/super_koalio/core.cljc
Expand Up @@ -17,26 +17,32 @@
:can-jump? false
:direction :right
:player-images {}
:player-image-key :walk1}))
:player-walk-keys [:walk1 :walk2 :walk3]
:player-image-key :jump}))

(def koala-width 18)
(def koala-height 26)

(defn init [game]
;; allow transparency in images
(gl game enable (gl game BLEND))
(gl game blendFunc (gl game SRC_ALPHA) (gl game ONE_MINUS_SRC_ALPHA))
;; load images and put them in the state atom
(doseq [[k path] {:walk1 "player_walk1.png"
:walk2 "player_walk2.png"
:walk3 "player_walk3.png"}]
(doseq [[k path] {:walk1 "koalio.png"}]
(utils/get-image path
(fn [{:keys [data width height]}]
(let [;; create an image entity (a map with info necessary to display it)
entity (e/->image-entity game data width height)
;; compile the shaders so it is ready to render
entity (c/compile game entity)
;; assoc the width and height to we can reference it later
entity (assoc entity :width width :height height)]
(let [images (vec (for [i (range 5)]
(c/compile game (e/->image-entity game data width height
{:x (* i koala-width) :y 0
:width koala-width :height koala-height}))))
[stand jump walk1 walk2 walk3] images]
;; add it to the state
(swap! *state update :player-images assoc k entity))))))
(swap! *state update :player-images assoc
:stand stand
:jump jump
:walk1 walk1
:walk2 walk2
:walk3 walk3))))))

(def screen-entity
{:viewport {:x 0 :y 0 :width 0 :height 0}
Expand All @@ -58,8 +64,8 @@
assoc :width game-width :height game-height))
;; get the current player image to display
(when-let [player (get player-images player-image-key)]
(let [player-width (/ game-width 10)
player-height (* player-width (/ (:height player) (:width player)))]
(let [player-width (/ game-width 30)
player-height (* player-width (/ koala-height koala-width))]
;; render the player
(c/render game
(-> player
Expand Down
16 changes: 9 additions & 7 deletions super-koalio/src/super_koalio/move.cljc
Expand Up @@ -80,16 +80,18 @@
(defn animate
[{:keys [total-time]}
{:keys [x-velocity y-velocity direction
player-images player-image-key]
player-images player-walk-keys]
:as state}]
(let [direction (get-direction state)]
(-> state
(assoc :player-image-key
(if (and (not= x-velocity 0)
(= y-velocity 0))
(let [image-keys (->> player-images keys sort vec)
cycle-time (mod total-time (* animation-secs (count image-keys)))]
(nth image-keys (int (/ cycle-time animation-secs))))
player-image-key))
(cond
(not= y-velocity 0)
:jump
(not= x-velocity 0)
(let [cycle-time (mod total-time (* animation-secs (count player-walk-keys)))]
(nth player-walk-keys (int (/ cycle-time animation-secs))))
:else
:stand))
(assoc :direction direction))))

0 comments on commit 8204ce2

Please sign in to comment.