@waica/behaviors 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/interactable.js +7 -17
- package/dist/melee-attack.js +9 -18
- package/package.json +2 -2
package/dist/interactable.js
CHANGED
|
@@ -56,26 +56,16 @@ export function fireInteract(target, initiator) {
|
|
|
56
56
|
* radius hides it again. Nearest one wins when several are in range.
|
|
57
57
|
*/
|
|
58
58
|
export function interactUpdate({ entity, game }) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const interactable = other.get(Interactable);
|
|
66
|
-
if (!interactable)
|
|
67
|
-
continue;
|
|
68
|
-
const distance = Math.hypot(other.position.x - entity.position.x, other.position.y - entity.position.y);
|
|
69
|
-
if (distance <= interactable.radius && distance < nearestDistance) {
|
|
70
|
-
nearest = interactable;
|
|
71
|
-
nearestEntity = other;
|
|
72
|
-
nearestDistance = distance;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!nearest || !nearestEntity) {
|
|
59
|
+
const nearestEntity = game.query.nearest(entity.position.x, entity.position.y, {
|
|
60
|
+
with: [Interactable],
|
|
61
|
+
exclude: entity,
|
|
62
|
+
where: (candidate, { distance }) => distance <= candidate.get(Interactable).radius,
|
|
63
|
+
});
|
|
64
|
+
if (!nearestEntity) {
|
|
76
65
|
game.ui.hide(INTERACTABLE_UI_PIECE);
|
|
77
66
|
return;
|
|
78
67
|
}
|
|
68
|
+
const nearest = nearestEntity.get(Interactable);
|
|
79
69
|
if (game.input.justPressed('interact') && !game.input.consumed('interact')) {
|
|
80
70
|
// The press is spent: an input:interact edge needs a NEW press.
|
|
81
71
|
game.input.consume('interact');
|
package/dist/melee-attack.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, Hitbox,
|
|
1
|
+
import { Component, Hitbox, } from '@waica/engine';
|
|
2
2
|
import { logicalDirection } from './facing.js';
|
|
3
3
|
import { Health } from './health.js';
|
|
4
4
|
/**
|
|
@@ -43,25 +43,16 @@ export class MeleeAttack extends Component {
|
|
|
43
43
|
this.game.audio.play(this.swingSound, { at: this.entity });
|
|
44
44
|
const area = this.strikeArea(direction.x, direction.y);
|
|
45
45
|
const struck = [];
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const targets = this.game.query.area(area, {
|
|
47
|
+
with: [Health],
|
|
48
|
+
exclude: this.entity,
|
|
49
|
+
});
|
|
50
|
+
for (const other of targets) {
|
|
51
|
+
// Query results are eager live references: an earlier target can destroy
|
|
52
|
+
// a later one while this strike is still consuming its snapshot.
|
|
53
|
+
if (!other.alive)
|
|
50
54
|
continue;
|
|
51
|
-
const hitbox = other.get(Hitbox);
|
|
52
55
|
const health = other.get(Health);
|
|
53
|
-
if (!hitbox || !health)
|
|
54
|
-
continue;
|
|
55
|
-
const body = {
|
|
56
|
-
x: other.position.x + hitbox.offsetX,
|
|
57
|
-
y: other.position.y + hitbox.offsetY,
|
|
58
|
-
width: hitbox.width,
|
|
59
|
-
height: hitbox.height,
|
|
60
|
-
shape: hitbox.shape,
|
|
61
|
-
points: hitbox.points,
|
|
62
|
-
};
|
|
63
|
-
if (!collisionOverlap(area, body))
|
|
64
|
-
continue;
|
|
65
56
|
const before = health.current;
|
|
66
57
|
health.damage(this.damage, this.entity);
|
|
67
58
|
if (health.current < before)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waica/behaviors",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Waica built-in behaviors — the curated game-feel library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@waica/engine": "^0.14.
|
|
22
|
+
"@waica/engine": "^0.14.1"
|
|
23
23
|
}
|
|
24
24
|
}
|