Bomberman movement cleanup, notes on pacman movement
This commit is contained in:
parent
238dcee158
commit
47230144bb
|
@ -35,31 +35,32 @@
|
||||||
; * if there is one solid and one empty tile in front of Bomberman, push Bomberman
|
; * if there is one solid and one empty tile in front of Bomberman, push Bomberman
|
||||||
; back onto the tile boundary, and push Bomberman towards the empty tile in the
|
; back onto the tile boundary, and push Bomberman towards the empty tile in the
|
||||||
; other axis
|
; other axis
|
||||||
; repeat for both x and y axis
|
; Movement only happens along one axis; diagonal movement is not allowed.
|
||||||
; TODO: do we add the two vectors? is it acceptable that diagonal movement is faster?
|
(fn horizontal [c copp] [c copp])
|
||||||
(fn horizontal [x y] (fn [dx dy] [(+ x dx) (+ y dy)]))
|
(fn vertical [c copp] [copp c])
|
||||||
(fn vertical [x y] (fn [dy dx] [(+ x dx) (+ y dy)]))
|
(fn bomberman.axis-movement [make-xy c copp dc rules]
|
||||||
(fn bomberman.axis-movement [off c copp dc rules]
|
(let [(edge-prev edge-next) (edge c dc dim.halftile)
|
||||||
(let [d (fn [cnew] (- cnew c))
|
|
||||||
(edge-prev edge-next) (edge c dc dim.halftile)
|
|
||||||
crosses (edge-crosses edge-prev edge-next dim.tilesize)
|
crosses (edge-crosses edge-prev edge-next dim.tilesize)
|
||||||
neg-collides (bomberman.collides? (off (d edge-next) (- dim.halftile)) rules)
|
neg-edge (- copp dim.halftile)
|
||||||
pos-collides (bomberman.collides? (off (d edge-next) (- dim.halftile 0.01)) rules)
|
neg-collides (bomberman.collides? (make-xy edge-next neg-edge) rules)
|
||||||
dc-edge (d (bomberman.tile-edge edge-next dc))
|
pos-edge (+ copp dim.halftile -0.01)
|
||||||
dcopp (math.abs dc)]
|
pos-collides (bomberman.collides? (make-xy edge-next pos-edge) rules)
|
||||||
(if (not crosses) [dc 0]
|
dc-edge (- (bomberman.tile-edge edge-next dc) c)
|
||||||
(and (not neg-collides) (not pos-collides)) [dc 0]
|
dcopp (math.abs dc)
|
||||||
(and neg-collides pos-collides) [dc-edge 0]
|
[cn coppn]
|
||||||
neg-collides [dc-edge (math.min dcopp (- (bomberman.tile-edge (+ copp dim.tilesize (- dim.halftile 0.01)) 1) copp))]
|
(if (not crosses) [dc 0]
|
||||||
pos-collides [dc-edge (math.max (- dcopp) (- (bomberman.tile-edge (- copp dim.tilesize dim.halftile) -1) copp))])))
|
(and (not neg-collides) (not pos-collides)) [dc 0]
|
||||||
|
(and neg-collides pos-collides) [dc-edge 0]
|
||||||
|
neg-collides [dc-edge (math.min dcopp (- (bomberman.tile-edge (+ pos-edge dim.tilesize) 1) copp))]
|
||||||
|
pos-collides [dc-edge (math.max (- dcopp) (- (bomberman.tile-edge (- neg-edge dim.tilesize) -1) copp))])]
|
||||||
|
(make-xy cn coppn)))
|
||||||
|
|
||||||
(fn bomberman.update [entity dt rules]
|
(fn bomberman.update [entity dt rules]
|
||||||
(set entity.vel (direct bomberman.keymap (* dim.tilesize 3)))
|
(set entity.vel (direct bomberman.keymap (* dim.tilesize 3)))
|
||||||
(let [[x y] entity.pos
|
(let [[x y] entity.pos
|
||||||
[dx dy] (vec* entity.vel dt)
|
[dx dy] (vec* entity.vel dt)
|
||||||
[dx1 dy1] (bomberman.axis-movement (horizontal x y) x y dx rules)
|
[dx dy] (if (not= dx 0) (bomberman.axis-movement horizontal x y dx rules)
|
||||||
[dy2 dx2] (bomberman.axis-movement (vertical x y) y x dy rules)
|
(bomberman.axis-movement vertical y x dy rules))]
|
||||||
[dx dy] (if (not= dx 0) [dx1 dy1] [dx2 dy2])]
|
|
||||||
(set entity.pos [(+ x dx) (+ y dy)]))
|
(set entity.pos [(+ x dx) (+ y dy)]))
|
||||||
(when (love.keyboard.isDown bomberman.keymap.bomb)
|
(when (love.keyboard.isDown bomberman.keymap.bomb)
|
||||||
(rules.place-bomb (map.world-to-tile entity.pos))))
|
(rules.place-bomb (map.world-to-tile entity.pos))))
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
(local Entity (require :game.entity))
|
(local util (require :lib.util))
|
||||||
(local rules (require :game.rules))
|
(local dim (require :game.dim))
|
||||||
|
|
||||||
(local Pacman (Entity:extend))
|
(local map (require :game.tilemap))
|
||||||
(set Pacman.keymap {:up :up :down :down :left :left :right :right})
|
|
||||||
(set Pacman.color [1 1 0])
|
|
||||||
|
|
||||||
Pacman
|
(local pacman (util.hot-table ...))
|
||||||
|
|
||||||
|
; 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
|
||||||
|
pacman.hot
|
||||||
|
|
Loading…
Reference in a new issue