Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Initial state logic and wip camera sacling |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | lisp-game-jam-2020 |
Files: | files | file ages | folders |
SHA3-256: |
35d9508f682b24dec9a9ad4a45203e08 |
User & Date: | chewbranca 2020-04-18 21:45:15 |
Context
2020-04-20
| ||
01:27 | Map updates check-in: 0d823e0a3b user: chewbranca tags: lisp-game-jam-2020 | |
2020-04-18
| ||
21:45 | Initial state logic and wip camera sacling check-in: 35d9508f68 user: chewbranca tags: lisp-game-jam-2020 | |
2020-04-16
| ||
05:39 | Add Warper City atlas loader and initial animations check-in: 02b8ba3fe4 user: chewbranca tags: lisp-game-jam-2020 | |
Changes
Changes to src/fahombo/main.lua.
1 2 3 4 5 6 7 8 |
-- bootstrap the compiler fennel = require("lib.fennel") table.insert(package.loaders, fennel.make_searcher({correlate=true})) pp = function(x) print(require("lib.fennelview")(x)) end lume = require("lib.lume") log = function(...) print(string.format(...)) end require("wrap") |
> |
1 2 3 4 5 6 7 8 9 |
-- bootstrap the compiler
fennel = require("lib.fennel")
table.insert(package.loaders, fennel.make_searcher({correlate=true}))
pp = function(x) print(require("lib.fennelview")(x)) end
pps = function(x) return require("lib.fennelview")(x) end
lume = require("lib.lume")
log = function(...) print(string.format(...)) end
require("wrap")
|
Changes to src/fahombo/play.fnl.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 .. 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 .. 67 68 69 70 71 72 73 74 75 76 77 78 79 80 .. 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 ... 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
;; This is a Fennel implementation of http://www.osmstudios.com/tutorials/love2d-platformer-tutorial-part-1-the-basics (local anim8 (require "lib.anim8")) (local bump (require "lib.bump")) (local sti (require "lib.sti")) (local game-width 384) (local game-height 224) (local bg-1 (love.graphics.newImage "assets/warped_city/environment/bg-1.png")) (local bg-2 (love.graphics.newImage "assets/warped_city/environment/bg-2.png")) (local bg-3 (love.graphics.newImage "assets/warped_city/environment/bg-3.png")) (local player-img (love.graphics.newImage "assets/osmstudios_character_block.png")) (local player { ................................................................................ :friction 20 ;; slow our player down - we could toggle this situationally to create icy or slick platforms :gravity 80 ;; we will accelerate towards the bottom ;; These are values applying specifically to jumping :isJumping false ;; are we in the process of jumping? :isGrounded false ;; are we on the ground? :hasReachedMax false ;; is this as high as we can go? :jumpAcc 500 ;; how fast do we accelerate towards the top :jumpMaxSpeed 9.5 ;; our speed limit while jumping ;; Here are some incidental storage areas :am-state :walk ;; player animation :img player-img}) ;; store the sprite we'll be drawing (local atlas-data (require "assets/warped_city/atlas/atlas")) (local atlas-tile (love.graphics.newImage "assets/warped_city/atlas/atlas.png")) ;; apparently this helps for scaling (: atlas-tile :setFilter "nearest" "linear") ................................................................................ (tset atlas-imgs name quad))))) ;; create animations (each [name quads (pairs atlas-ams-imgs)] (let [am (anim8.newAnimation quads 0.1)] (tset atlas-ams name am))) (local map (sti "map.lua" ["bump"])) ;; TODO: add lint wrapper (local world (bump.newWorld 16)) (local ground-0 {}) (local ground-1 {}) ................................................................................ (if (<= player-bottom y) :slide)))) (fn update [dt set-mode] (let [goal-x (+ player.x player.xVelocity) goal-y (+ player.y player.yVelocity) (x y cols) (: world :move player goal-x goal-y player.filter) am (. atlas-ams player.am-state)] (: am :update dt) (set player.x (lume.clamp x 5 1000)) (set player.y y) (each [i col (ipairs cols)] (if (> col.touch.y goal-y) (do (set player.hasReachedMax true) (set player.isGrounded false)) (< col.normal.y 0) (do (set player.hasReachedMax false) (set player.isGrounded true))))) ;; apply friction (let [df (- 1 (math.min 1 (* dt player.friction)))] (set player.xVelocity (* player.xVelocity df)) (set player.yVelocity (* player.yVelocity df))) ;; apply gravity ................................................................................ ;; handle horizontal movement (if (and (love.keyboard.isDown "left" "a") (> player.xVelocity (- player.maxSpeed))) (set player.xVelocity (- player.xVelocity (* player.acc dt))) (and (love.keyboard.isDown "right" "d") (< player.xVelocity player.maxSpeed)) (set player.xVelocity (+ player.xVelocity (* player.acc dt)))) ;; jump up jump up and get down (if (love.keyboard.isDown "up" "w") (do (if (and (< (- player.yVelocity) player.jumpMaxSpeed) (not player.hasReachedMax)) (do ;; (log "{%s} Setting player velocity{%s} to {%s} using a={%s}" dt player.yVelocity (- player.yVelocity (* player.jumpAcc dt)) player.jumpAcc) (set player.yVelocity (- player.yVelocity (* player.jumpAcc dt)))) ;; (log "Approaching terminal velocity %s ----> %s" (math.abs player.yVelocity) player.jumpMaxSpeed) (> (math.abs player.yVelocity) player.jumpMaxSpeed) (set player.hasReachedMax true)) (set player.isGrounded false)))) (fn keypressed [key set-mode]) (fn draw [map world player] (let [w (love.graphics.getWidth) h (love.graphics.getHeight) iw (: bg-1 :getWidth) ih (: bg-1 :getHeight) sw (/ w iw) sh (/ h ih) am (. atlas-ams player.am-state)] (love.graphics.draw bg-1 0 0 0 sw sh) (love.graphics.draw bg-2 0 0 0 sw sh) (love.graphics.draw bg-3 0 0 0 sw sh)) (: map :draw) (let [p-img atlas-quads.walk-5 p-am atlas-ams.walk] ;; TODO: switch to drawing with a spritebatch ;;(love.graphics.draw atlas-tile p-img player.x player.y)) (: p-am :draw atlas-tile player.x player.y)) (let [(x0 y0 w0 h0) (: world :getRect ground-0) (x1 y1 w1 h1) (: world :getRect ground-1)] (love.graphics.rectangle "fill" x0 y0 w0 h0) (love.graphics.rectangle "fill" x1 y1 w1 h1))) {:draw (partial draw map world player) :update update :keypressed keypressed} |
> > > > > | | > > | | > | > > > > > > > | | > | | > > | > | | > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 .. 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 .. 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 .. 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 ... 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
;; This is a Fennel implementation of http://www.osmstudios.com/tutorials/love2d-platformer-tutorial-part-1-the-basics ;; TODO ;; - [ ] swap animation directions for -x movement (local anim8 (require "lib.anim8")) (local bump (require "lib.bump")) (local sti (require "lib.sti")) (local game-width 384) (local game-height 224) (local idle-speed 0.001) (local bg-1 (love.graphics.newImage "assets/warped_city/environment/bg-1.png")) (local bg-2 (love.graphics.newImage "assets/warped_city/environment/bg-2.png")) (local bg-3 (love.graphics.newImage "assets/warped_city/environment/bg-3.png")) (local player-img (love.graphics.newImage "assets/osmstudios_character_block.png")) (local player { ................................................................................ :friction 20 ;; slow our player down - we could toggle this situationally to create icy or slick platforms :gravity 80 ;; we will accelerate towards the bottom ;; These are values applying specifically to jumping :isJumping false ;; are we in the process of jumping? :isGrounded false ;; are we on the ground? :hasReachedMax false ;; is this as high as we can go? :jumpAcc 100 ;; how fast do we accelerate towards the top :jumpMaxSpeed 9.5 ;; our speed limit while jumping ;; Here are some incidental storage areas :state :idle ;; player animation :img player-img}) ;; store the sprite we'll be drawing (local atlas-data (require "assets/warped_city/atlas/atlas")) (local atlas-tile (love.graphics.newImage "assets/warped_city/atlas/atlas.png")) ;; apparently this helps for scaling (: atlas-tile :setFilter "nearest" "linear") ................................................................................ (tset atlas-imgs name quad))))) ;; create animations (each [name quads (pairs atlas-ams-imgs)] (let [am (anim8.newAnimation quads 0.1)] (tset atlas-ams name am))) (log "Created animations: %s" (pps (lume.keys atlas-ams))) (local map (sti "map.lua" ["bump"])) ;; TODO: add lint wrapper (local world (bump.newWorld 16)) (local ground-0 {}) (local ground-1 {}) ................................................................................ (if (<= player-bottom y) :slide)))) (fn update [dt set-mode] (let [goal-x (+ player.x player.xVelocity) goal-y (+ player.y player.yVelocity) (x y cols) (: world :move player goal-x goal-y player.filter) am (. atlas-ams player.state)] (: am :update dt) (set player.x (lume.clamp x 5 1000)) (set player.y y) (each [i col (ipairs cols)] (if (> col.touch.y goal-y) (do (set player.hasReachedMax true) (set player.isGrounded false) (set player.state :jump)) (< col.normal.y 0) (do (set player.hasReachedMax false) (set player.isGrounded true) (set player.state :walk)))) ;; TODO: don't just default to :walk ;; apply friction (let [df (- 1 (math.min 1 (* dt player.friction)))] (set player.xVelocity (* player.xVelocity df)) (set player.yVelocity (* player.yVelocity df))) ;; apply gravity ................................................................................ ;; handle horizontal movement (if (and (love.keyboard.isDown "left" "a") (> player.xVelocity (- player.maxSpeed))) (set player.xVelocity (- player.xVelocity (* player.acc dt))) (and (love.keyboard.isDown "right" "d") (< player.xVelocity player.maxSpeed)) (set player.xVelocity (+ player.xVelocity (* player.acc dt)))) (if (< (math.abs player.xVelocity) idle-speed) (when (not (= player.state :idle)) (set player.state :idle)) (match player.state :idle (set player.state :walk))) ;; jump up jump up and get down (if (love.keyboard.isDown "up" "w") (do (if (and (< (- player.yVelocity) player.jumpMaxSpeed) (not player.hasReachedMax)) (do ;; (log "{%s} Setting player velocity{%s} to {%s} using a={%s}" dt player.yVelocity (- player.yVelocity (* player.jumpAcc dt)) player.jumpAcc) (set player.yVelocity (- player.yVelocity (* player.jumpAcc dt)))) ;; (log "Approaching terminal velocity %s ----> %s" (math.abs player.yVelocity) player.jumpMaxSpeed) (>= (math.abs player.yVelocity) player.jumpMaxSpeed) (set player.hasReachedMax true)) (set player.isGrounded false) (set player.state :jump))))) (fn keypressed [key set-mode]) (fn draw [map world player] (let [w (love.graphics.getWidth) h (love.graphics.getHeight) iw (: bg-1 :getWidth) ih (: bg-1 :getHeight) sw (/ w iw) sh (/ h ih) tdx 1] (love.graphics.draw bg-1 0 0 0 sw sh) (love.graphics.draw bg-2 0 0 0 sw sh) (love.graphics.draw bg-3 0 0 0 sw sh) (love.graphics.push)) ;;(love.graphics.translate (/ w tdx) (/ h tdx))) (: map :draw) (let [p-img atlas-quads.walk-5 p-am atlas-ams.walk am (. atlas-ams player.state)] ;; TODO: switch to drawing with a spritebatch ;;(love.graphics.draw atlas-tile p-img player.x player.y)) (: am :draw atlas-tile player.x player.y)) (let [(x0 y0 w0 h0) (: world :getRect ground-0) (x1 y1 w1 h1) (: world :getRect ground-1)] (love.graphics.rectangle "fill" x0 y0 w0 h0) (love.graphics.rectangle "fill" x1 y1 w1 h1)) (love.graphics.pop)) {:draw (partial draw map world player) :update update :keypressed keypressed} |