Group-based sprite collision tools and sprite collision detection predicates.
Group-based sprite collision tools and sprite collision detection predicates.
(collide-group a group-b collider)
Check a sprite from one group for collisions with all sprites from another group, updating both as necessary.
Reducing over group-b lets us build up a new version of group-b, updating the value of a as we go.
We filter out any b that returns nil
after colliding to allow
collide functions to kill sprites.
Check a sprite from one group for collisions with all sprites from another group, updating both as necessary. Reducing over group-b lets us build up a new version of group-b, updating the value of a as we go. We filter out any b that returns `nil` after colliding to allow collide functions to kill sprites.
(collide-groups sprite-groups {:keys [group-a-key group-b-key] :as collider})
Check a group of sprites for collisions with another group of sprites, updating all sprites as necessary.
We're iterating using a reducing function over the first group, this
means that each time we check an a
against group-b
we get the
new value for a, and the new values for each sprite in group-b
.
We filter out any a that returns nil
after colliding to allow
collide functions to kill sprites.
We build our results map using the threading macro to handle the
case where group-a-key
and group-b-key
are the same.
Check a group of sprites for collisions with another group of sprites, updating all sprites as necessary. We're iterating using a reducing function over the first group, this means that each time we check an `a` against `group-b` we get the new value for a, and the new values for each sprite in `group-b`. We filter out any a that returns `nil` after colliding to allow collide functions to kill sprites. We build our results map using the threading macro to handle the case where `group-a-key` and `group-b-key` are the same.
(collide-sprites a
b
{:keys [group-a-key group-b-key collision-detection-fn
collide-fn-a collide-fn-b non-collide-fn-a
non-collide-fn-b]})
Check two sprites for collision and update them with the appropriate
collide-fn-<a|b>
provided by the collider. These functions should
return an optionally modified version of their first argument, the
second is passed in only as a reference.
In the case that we're checking a group of sprites for collisions in the same group we need to check the uuid on the sprites to ensure they're not colliding with themselves.
Check two sprites for collision and update them with the appropriate `collide-fn-<a|b>` provided by the collider. These functions should return an optionally modified version of their first argument, the second is passed in only as a reference. In the case that we're checking a group of sprites for collisions in the same group we need to check the uuid on the sprites to ensure they're not colliding with themselves.
(collider group-a-key
group-b-key
collide-fn-a
collide-fn-b
&
{:keys [collision-detection-fn non-collide-fn-a non-collide-fn-b]
:or {collision-detection-fn w-h-rects-collide?
non-collide-fn-a identity-collide-fn
non-collide-fn-b identity-collide-fn}})
Define a check for collision between to groups of sprites with functions to be invoked on the sprites when collision is detected.
Define a check for collision between to groups of sprites with functions to be invoked on the sprites when collision is detected.
(equal-pos? {pos-a :pos} {pos-b :pos})
Predicate to check if two sprites have the same position.
Predicate to check if two sprites have the same position.
(identity-collide-fn a b)
Collide functions should return an optionally modified a
sprite.
Collide functions should return an optionally modified `a` sprite.
(poly-contains-pos? a b)
Predicate to check if the position of sprite b
is inside the
bounding polygon of sprite a
centered on its position.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check if the position of sprite `b` is inside the bounding polygon of sprite `a` centered on its position. Accounts for the respective `:offsets` configuration of each sprite.
(polys-collide? {bounds-fn-a :bounds-fn pos-a :pos :as a}
{bounds-fn-b :bounds-fn pos-b :pos :as b})
Predicate to check an intersection of the bounding polygons of
sprites a
and b
centered on their positions.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check an intersection of the bounding polygons of sprites `a` and `b` centered on their positions. Accounts for the respective `:offsets` configuration of each sprite.
(pos-in-poly? {pos-a :pos :as a} {bounds-fn :bounds-fn pos-b :pos :as b})
Predicate to check if the position of sprite a
is inside the
bounding polygon of sprite b
centered on its position.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check if the position of sprite `a` is inside the bounding polygon of sprite `b` centered on its position. Accounts for the respective `:offsets` configuration of each sprite.
(pos-in-rect? {pos-a :pos :as a} {[bx by] :pos bw :w bh :h :as b})
Predicate to check if the position of sprite a
is inside the w
by
h
rect of sprite b
centered on its position.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check if the position of sprite `a` is inside the `w` by `h` rect of sprite `b` centered on its position. Accounts for the respective `:offsets` configuration of each sprite.
(pos-in-rotating-poly?
{pos-a :pos :as a}
{bounds-fn :bounds-fn pos-b :pos rotation :rotation :as b})
Predicate to check if the position of sprite a
is inside the
bounding polygon of sprite b
centered on its position, taking into
account its rotation.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check if the position of sprite `a` is inside the bounding polygon of sprite `b` centered on its position, taking into account its rotation. Accounts for the respective `:offsets` configuration of each sprite.
(rect-contains-pos? a b)
Predicate to check if the position of sprite b
is inside the w
by
h
rect of sprite a
centered on its position.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check if the position of sprite `b` is inside the `w` by `h` rect of sprite `a` centered on its position. Accounts for the respective `:offsets` configuration of each sprite.
(rotating-poly-contains-pos? a b)
Predicate to check if the position of sprite b
is inside the
bounding polygon of sprite a
centered on its position, taking into
account its rotation.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check if the position of sprite `b` is inside the bounding polygon of sprite `a` centered on its position, taking into account its rotation. Accounts for the respective `:offsets` configuration of each sprite.
(rotating-polys-collide?
{bounds-fn-a :bounds-fn pos-a :pos rotation-a :rotation wa :w ha :h :as a}
{bounds-fn-b :bounds-fn pos-b :pos rotation-b :rotation wb :w hb :h :as b})
Predicate to check for an intersection of the bounding polys of
sprites a
and b
centered on their positions, taking into account
the rotation of both sprites.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check for an intersection of the bounding polys of sprites `a` and `b` centered on their positions, taking into account the rotation of both sprites. Accounts for the respective `:offsets` configuration of each sprite.
(update-state {:keys [current-scene] :as state})
Update the sprites in the current scene based on the scene colliders.
Update the sprites in the current scene based on the scene colliders.
(w-h-rects-collide? {[ax ay] :pos aw :w ah :h :as a}
{[bx by] :pos bw :w bh :h :as b})
Predicate to check for overlap of the w
by h
rects of two sprites
centered on their positions.
Accounts for the respective :offsets
configuration of each sprite.
Predicate to check for overlap of the `w` by `h` rects of two sprites centered on their positions. Accounts for the respective `:offsets` configuration of each sprite.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close