chewbranca.com

Check-in [d243b75468]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Finish part1 and fix jumping
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lisp-game-jam-2020
Files: files | file ages | folders
SHA3-256: d243b754680361c4ba3a01a5bb677462e67cb175420b66e7f6b92c2f39a1d948
User & Date: chewbranca 2020-04-11 22:49:06
Context
2020-04-13
20:06
Add initial prototype with https://ansimuz.itch.io/warped-city assets check-in: a6620266bc user: chewbranca tags: lisp-game-jam-2020
2020-04-11
22:49
Finish part1 and fix jumping check-in: d243b75468 user: chewbranca tags: lisp-game-jam-2020
22:32
Don't use local in functions check-in: e11c5f9a0c user: chewbranca tags: lisp-game-jam-2020
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/fahombo/play-osms-part1.fnl.

29
30
31
32
33
34
35








36
37
38
39
40
41










42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(local ground-1 {})

(: world :add player player.x player.y (: player.img :getWidth) (: player.img :getHeight))
;;(: world :add ground-0 20 360 640 16) ; blog version
(: world :add ground-0 120 360 640 16) ; github version
(: world :add ground-1 0 448 640 32)









(fn update [dt set-mode]
  (let [goal-x (+ player.x player.xVelocity)
        goal-y (+ player.y player.yVelocity)
        (x y) (: world :move player goal-x goal-y)]
    (set player.x (lume.clamp x 5 1000))
    (set player.y y))











  ;; 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
  (set player.yVelocity (+ player.yVelocity (* player.gravity dt)))
  (when (= player.yVelocity 0) ;; TODO: FIXME
    (set player.hasReachedMax false))

  ;; 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))))







>
>
>
>
>
>
>
>



|

|
>
>
>
>
>
>
>
>
>
>








<
<







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
(local ground-1 {})

(: world :add player player.x player.y (: player.img :getWidth) (: player.img :getHeight))
;;(: world :add ground-0 20 360 640 16) ; blog version
(: world :add ground-0 120 360 640 16) ; github version
(: world :add ground-1 0 448 640 32)

(set player.filter (fn [item other]
                     (let [(x y w h) (: world :getRect other)
                           (px py pw ph) (: world :getRect item)
                           player-bottom (+ py ph)
                           other-bottom (+ y h)]
                       (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)]
    (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
  (set player.yVelocity (+ player.yVelocity (* player.gravity dt)))



  ;; 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))))