chewbranca.com

Check-in [a607a0e86f]
Login

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

Overview
Comment:Add Fennel port of http://www.osmstudios.com/tutorials/love2d-platformer-tutorial-part-1-the-basics
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | lisp-game-jam-2020
Files: files | file ages | folders
SHA3-256: a607a0e86f55783fd99ae3f28abac8de7ace5d261e882a33ab7fa765a6dca062
User & Date: chewbranca 2020-04-11 22:26:18
Context
2020-04-11
22:32
Don't use local in functions check-in: e11c5f9a0c user: chewbranca tags: lisp-game-jam-2020
22:26
Add Fennel port of http://www.osmstudios.com/tutorials/love2d-platformer-tutorial-part-1-the-basics check-in: a607a0e86f user: chewbranca tags: lisp-game-jam-2020
22:25
Add log function check-in: 854a3dce1a user: chewbranca tags: lisp-game-jam-2020
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added src/fahombo/assets/osmstudios_character_block.png.

cannot compute difference between binary files

Changes to src/fahombo/mode-intro.fnl.

1
2
3




4
5
6
7
8
9
10
11
12
13
14
15
(var counter 0)
(var time 0)





{:draw (fn draw [message]
         (love.graphics.print (: "This window should close in %0.2f seconds"
                                 :format (- 3 time)) 32 16))
 :update (fn update [dt set-mode]
             (if (< counter 65535)
                 (set counter (+ counter 1))
                 (set counter 0))
             (set time (+ time dt))
             (when (> time 3)
               (love.event.quit)))
 :keypressed (fn keypressed [key set-mode]
                 (love.event.quit))}


>
>
>
>








|
|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(var counter 0)
(var time 0)

(local dev-mode? true)
;;(local play-game :play)
(local play-game :play-osms-part1)

{:draw (fn draw [message]
         (love.graphics.print (: "This window should close in %0.2f seconds"
                                 :format (- 3 time)) 32 16))
 :update (fn update [dt set-mode]
             (if (< counter 65535)
                 (set counter (+ counter 1))
                 (set counter 0))
             (set time (+ time dt))
             (when (or (> time 3) dev-mode?)
               (set-mode play-game)))
 :keypressed (fn keypressed [key set-mode]
                 (love.event.quit))}

Added src/fahombo/play-osms-part1.fnl.












































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
75
76
77
78
79
80
81
82
83
84
85
86
;; This is a Fennel implementation of http://www.osmstudios.com/tutorials/love2d-platformer-tutorial-part-1-the-basics

(local bump (require "lib.bump"))
(local player-img (love.graphics.newImage "assets/osmstudios_character_block.png"))

(local player {
  :x 16
  :y 16
  ;; The first set of values are for our rudimentary physics system
  :xVelocity 0 ;; current velocity on x, y axes
  :yVelocity 0
  :acc 100 ;; the acceleration of our player
  :maxSpeed 600 ;; the top speed
  :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
  :img player-img}) ;; store the sprite we'll be drawing

(local world (bump.newWorld 16))
(local ground-0 {})
(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]
  (local goal-x (+ player.x player.xVelocity))
  (local goal-y (+ player.y player.yVelocity))

  (let [(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))))

  ;; 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 [player world]
  (love.graphics.draw player.img 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 player world)
 :update update
 :keypressed keypressed}