36 lines
1.2 KiB
Fennel
36 lines
1.2 KiB
Fennel
(local util (require :lib.util))
|
|
(local dim (require :game.dim))
|
|
(local {: direct : move} (util.require :game.entity))
|
|
(local {: edge : vec*} (util.require :game.helpers))
|
|
(local map (require :game.tilemap))
|
|
|
|
(local bomberman {})
|
|
(set bomberman.keymap {:up :w :down :s :left :a :right :d :bomb :x})
|
|
|
|
(fn bomberman.draw [entity]
|
|
(love.graphics.setColor 0.2 0.2 0.2)
|
|
(love.graphics.circle :fill (. entity.pos 1) (. entity.pos 2) (/ dim.tilesize 2)))
|
|
|
|
(fn collides? [x y rules]
|
|
(-?> [x y]
|
|
(map.world-to-tile)
|
|
(rules.tile-at)
|
|
(. :solid)))
|
|
|
|
(fn bomberman.update [entity dt rules]
|
|
(set entity.vel (direct bomberman.keymap (* dim.tilesize 3)))
|
|
(local [x y] entity.pos)
|
|
(local [dx dy] (vec* entity.vel dt))
|
|
(let [xedge (edge x dx (/ dim.tilesize 2))
|
|
xn (if (collides? xedge y rules) x (+ x dx))
|
|
yedge (edge y dy (/ dim.tilesize 2))
|
|
yn (if (collides? x yedge rules) y (+ y dy))]
|
|
(set entity.pos [xn yn]))
|
|
(when (love.keyboard.isDown bomberman.keymap.bomb)
|
|
(rules.place-bomb (map.world-to-tile entity.pos))))
|
|
|
|
(fn bomberman.new [pos]
|
|
{: pos :vel [0 0] :draw (util.fn bomberman :draw) :update (util.fn bomberman :update)})
|
|
|
|
bomberman
|