2021-04-04 17:26:47 +00:00
|
|
|
(local util (require :lib.util))
|
|
|
|
(local dim (require :game.dim))
|
2021-04-11 03:39:42 +00:00
|
|
|
(local {: defmethod} (util.require :lib.multimethod))
|
|
|
|
(local {: direct : draw : update} (util.require :game.entity))
|
2021-04-04 17:26:47 +00:00
|
|
|
(local map (require :game.tilemap))
|
2021-02-07 21:56:19 +00:00
|
|
|
|
2021-04-04 17:26:47 +00:00
|
|
|
(local pacman (util.hot-table ...))
|
2021-02-07 21:56:19 +00:00
|
|
|
|
2021-04-11 03:39:42 +00:00
|
|
|
(set pacman.keymap {:up :up :down :down :left :left :right :right})
|
|
|
|
(defmethod draw :pacman (fn [{:pos [x y]}]
|
|
|
|
(love.graphics.setColor 1 1 0)
|
|
|
|
(love.graphics.circle :fill x y dim.halftile)))
|
|
|
|
|
2021-04-04 17:26:47 +00:00
|
|
|
; Pacman movement and collision rules
|
|
|
|
; * Pacman moves in the direction he was told until stopped by a wall
|
|
|
|
; * If the player tells Pacman to change direction but there is a wall there,
|
|
|
|
; Pacman's direction does not change
|
|
|
|
; * Turning a corner is funky:
|
|
|
|
; https://www.gamasutra.com/view/feature/132330/the_pacman_dossier.php?page=4
|
|
|
|
; "Whenever Pac-Man makes a pre-turn or post-turn, his orientation changes, and he starts to
|
|
|
|
; move one pixel in his new direction for every pixel traveled in his old direction, effectively
|
|
|
|
; doubling his speed as he moves at a 45 degree angle. Once he reaches the centerline of the new
|
|
|
|
; direction's path, he starts moving purely in that direction and his speed returns to normal."
|
|
|
|
; The simplest way to implement this appears to be to treat turns as having a "fudge factor" -
|
|
|
|
; Pacman enters a state where he changes direction _and_ is being pulled towards the center of
|
|
|
|
; the track. (The "post-turn" correction means we can't simply treat this as the corners having
|
|
|
|
; their edges filed off!)
|
|
|
|
; I think Bomberman actually does this too
|
2021-04-11 03:39:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
(fn pacman.new [pos]
|
|
|
|
{: pos :vel [0 0] :entity :pacman})
|
|
|
|
|
2021-04-04 17:26:47 +00:00
|
|
|
pacman.hot
|