animate pacman
This commit is contained in:
parent
856d6400f5
commit
ab69260091
|
@ -2,14 +2,24 @@
|
|||
(local dim (require :game.dim))
|
||||
(local {: defmethod} (util.require :lib.multimethod))
|
||||
(local {: direct : draw : update} (util.require :game.entity))
|
||||
(local {: vec*} (util.require :game.helpers))
|
||||
(local map (require :game.tilemap))
|
||||
|
||||
(local pacman (util.hot-table ...))
|
||||
|
||||
(set pacman.keymap {:up :up :down :down :left :left :right :right})
|
||||
(defmethod draw :pacman (fn [{:pos [x y]}]
|
||||
(defmethod draw :pacman (fn [{:pos [x y] :vel [dx dy]}]
|
||||
(let [mouthsize-max (if (and (= dx 0) (= dy 0)) 0 (/ math.pi 4))
|
||||
mouthsize-ratio (math.abs (math.sin (* (love.timer.getTime) 16)))
|
||||
mouthsize (* mouthsize-max mouthsize-ratio)
|
||||
anglestart (if (< dx 0) math.pi
|
||||
(> dx 0) 0
|
||||
(> dy 0) (/ math.pi 2)
|
||||
(+ math.pi (/ math.pi 2)))
|
||||
angle1 (+ anglestart mouthsize)
|
||||
angle2 (+ anglestart math.pi math.pi (- mouthsize))]
|
||||
(love.graphics.setColor 1 1 0)
|
||||
(love.graphics.circle :fill x y dim.halftile)))
|
||||
(love.graphics.arc :fill x y dim.halftile angle1 angle2))))
|
||||
|
||||
; Pacman movement and collision rules
|
||||
; * Pacman moves in the direction he was told until stopped by a wall
|
||||
|
@ -27,6 +37,13 @@
|
|||
; their edges filed off!)
|
||||
; I think Bomberman actually does this too
|
||||
|
||||
(defmethod update :pacman (fn [entity dt rules]
|
||||
(let [[dx dy] entity.vel
|
||||
[dxkey dykey] (direct pacman.keymap (* dim.tilesize 4))
|
||||
turn-attempted (and (or (not= dxkey 0) (not= dykey 0))
|
||||
(or (not= dxkey dx) (not= dykey dy)))]
|
||||
(when turn-attempted
|
||||
(set entity.vel [dxkey dykey])))))
|
||||
|
||||
(fn pacman.new [pos]
|
||||
{: pos :vel [0 0] :entity :pacman})
|
||||
|
|
|
@ -10,11 +10,12 @@
|
|||
(local map (require :game.tilemap))
|
||||
(local tile (require :game.tiles))
|
||||
(local bomberman (require :game.entities.bomberman))
|
||||
(local pacman (require :game.entities.pacman))
|
||||
(local rules (require :game.rules))
|
||||
|
||||
(modes:register :game gamemode)
|
||||
|
||||
(set state.entities [(bomberman.new [48 48])])
|
||||
(set state.entities [(bomberman.new [48 48]) (pacman.new [112 112])])
|
||||
(set state.map (map.new-tilemap 28 31 tile.bombertile (tile.itile-named tile.bombertile :empty)))
|
||||
(set state.bombs (map.new-entitymap state.map.w state.map.h))
|
||||
(rules.generate-maze state.map)
|
||||
|
|
Loading…
Reference in a new issue