~benaiah/ludum-dare-nov-2018

5ca9e11ab076e63a6ec6febc0ee5bc09295eee2f — Benaiah Mischenko 2 years ago a8ab70c
add gravity system
1 files changed, 17 insertions(+), 7 deletions(-)

M game.fnl
M game.fnl => game.fnl +17 -7
@@ 44,19 44,19 @@

(fn make-world []
  (local world (ces.world.create
                {:position [:x :y] :momentum [:x :y]}))
                {:position [:x :y] :momentum [:x :y] :gravity [:amount]}))
  (ces.world.run-creations
   world
   [(make-player)
    (make-player {:position [200 200] :momentum [0 200]})
    (make-player {:position [300 300]})
    (make-player {:position [400 400]})
    (make-player {:position [500 500] :momentum [50 100]})
    (make-player {:position [600 600]})
    (make-player {:position [200 200] :gravity [500]})
    (make-player {:position [300 300] :gravity [400]})
    (make-player {:position [400 400] :gravity [300]})
    (make-player {:position [500 500] :gravity [200]})
    (make-player {:position [600 600] :gravity [100]})
    ])
  world)

(local updates-initial {:position {}})
(local updates-initial {:position {} :momentum {}})
(var updates updates-initial)

(local momentum-system


@@ 72,6 72,15 @@
                new-y (+ y dy)]
            (tset updates.position id [new-x new-y])))))

(local gravity-system
       (create-system
        :gravity
        [:momentum :gravity]
        (fn gravity [dt momentum gravity]
          (let [[id _ dy] momentum
                [_ amount] gravity]
            (tset updates.momentum id [nil (+ dy (* amount dt))])))))

(print (inspect momentum-system))

(fn exports.load []


@@ 83,6 92,7 @@

(fn exports.update [dt state]
  (local world state.world)
  (run-system world gravity-system dt)
  (run-system world momentum-system dt)
  (ces.world.run-updates world updates)
  (set updates updates-initial)