Commit 461b21a
authored
feat: non-tile solids (#903)
Implement collisions for non-tile solids and a way to define them for
elements in a map's YAML. This makes the `CollisionWorld` account for
entities with the `Solid` component.
I started out trying to implement a door for #43 but quickly realized I
couldn't make a closed door solid. This is its own PR because I want to
make sure I'm going in the right direction here and discuss the
implementation.
https://github.com/fishfolk/jumpy/assets/25290530/3851d2b3-8f58-41c0-8462-9b641334d63a
## Changes
### Defining solids
Elements can be defined in each layer of a map's YAML file. Solids can
now be defined on an element with a `solid` object.
Example element in a map layer:
```yaml
- pos: [630.0, 365.0]
element: core:/elements/environment/demo_solid_box/demo_solid_box.element.yaml
```
Now, with a solid:
```yaml
- pos: [630.0, 365.0]
element: core:/elements/environment/demo_solid_box/demo_solid_box.element.yaml
solid:
enabled: true
pos: [630.0, 365.0]
size: [16.0, 16.0]
```
The solid has its own position and size since a collider may need to be
separate from the sprite. For example, the door sprite will need to be
very wide for when it's open but the collider for a closed door will be
very thin.
This was done by adding the new struct `ElementSolidMeta` to
`ElementSpawn`. I wanted it to be a `Maybe<ElementSolidMeta>` but got an
error from bones. My next best option was letting it be
default-initialized for all elements but provide an `enabled` boolean
that must be `true` for the solid to be created. Not ideal but it works.
Another downside is that the size of the solid collider has to be
defined *in the map*, whereas the size of the `KinematicBody` is often
defined in the element's `.yaml` data file and the size of the sprite is
defined in the element's `.atlast.yaml`. Maybe this can eventually be
moved into an element's asset configs.
### Collision detection
Solids get a `Collider` component like kinematic bodies, which are also
synced to the rapier colliders. This allows game code to easily control
the collider. e.g. the door will want to disable the collider when it's
open, which can be done by setting `Collider.disabled` to `true`.
I'm not convinced my changes to
`CollisionWorld::move_{horizontal,vertical}` are correct, but this seems
to mostly work.
Since the `CollisionWorld::tile_collision{,_filtered}` methods now
detect *any* collision they should be renamed to
`CollisionWorld::collision{,_filtered}`. If this is looking good so far
I will make that change.
### Game behavior
I added a few demo boxes to dev level 1 for testing. It works great from
the testing I did except for a couple minor bugs. If you slide into the
box to the left of where you spawn you stop short of the box. But if you
walk up to the box you collide with it as expected. Sliding into the one
in the far bottom right of the map behaves like you would expect. This
is all shown in the video.
Additionally, critters cause a lot of collision warnings:
> 2024-01-16T22:02:52.902798Z WARN jumpy::core::physics: Collision test
error resulting in physics body stuck in wall at Rect { min: Vec2(712.0,
96.1), max: Vec2(722.0, 106.1) }
Snails walk straight through solids, causing these warnings. Crabs may
attempt and fail to surface under a solid after burrowing, also causing
these warnings. I'm not sure what to do about this yet.1 parent 3e99ea2 commit 461b21a
4 files changed
Lines changed: 112 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
48 | 57 | | |
49 | 58 | | |
50 | 59 | | |
| |||
85 | 94 | | |
86 | 95 | | |
87 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
88 | 101 | | |
89 | 102 | | |
90 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 175 | | |
179 | 176 | | |
180 | | - | |
| 177 | + | |
181 | 178 | | |
182 | 179 | | |
183 | 180 | | |
| |||
196 | 193 | | |
197 | 194 | | |
198 | 195 | | |
199 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
203 | | - | |
| 206 | + | |
204 | 207 | | |
205 | 208 | | |
206 | 209 | | |
| |||
398 | 401 | | |
399 | 402 | | |
400 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
401 | 434 | | |
402 | 435 | | |
403 | 436 | | |
| |||
430 | 463 | | |
431 | 464 | | |
432 | 465 | | |
433 | | - | |
| 466 | + | |
434 | 467 | | |
435 | | - | |
436 | | - | |
437 | | - | |
| 468 | + | |
438 | 469 | | |
439 | 470 | | |
440 | 471 | | |
| |||
459 | 490 | | |
460 | 491 | | |
461 | 492 | | |
462 | | - | |
| 493 | + | |
463 | 494 | | |
464 | 495 | | |
465 | 496 | | |
| |||
594 | 625 | | |
595 | 626 | | |
596 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
597 | 633 | | |
598 | 634 | | |
599 | 635 | | |
| |||
615 | 651 | | |
616 | 652 | | |
617 | 653 | | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
618 | 658 | | |
619 | 659 | | |
620 | 660 | | |
| |||
725 | 765 | | |
726 | 766 | | |
727 | 767 | | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
728 | 773 | | |
729 | 774 | | |
730 | 775 | | |
| |||
747 | 792 | | |
748 | 793 | | |
749 | 794 | | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
750 | 799 | | |
751 | 800 | | |
752 | 801 | | |
| |||
810 | 859 | | |
811 | 860 | | |
812 | 861 | | |
813 | | - | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
814 | 877 | | |
815 | 878 | | |
816 | 879 | | |
| |||
865 | 928 | | |
866 | 929 | | |
867 | 930 | | |
868 | | - | |
| 931 | + | |
| 932 | + | |
869 | 933 | | |
870 | 934 | | |
871 | 935 | | |
872 | | - | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
873 | 942 | | |
874 | 943 | | |
875 | 944 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
41 | 56 | | |
42 | 57 | | |
43 | 58 | | |
| |||
0 commit comments