# The hero pushes a box, pushing another box...

## Recommended Posts

Hi!

I have a problem, and I do not know how to start ...

CONTEXT
- phaser

FACTS

heroes
- a boy, big heroes, with "power" of 100
- a girl, small heroes, with "power" of 50

objects
- big box, weight of 100
- small box, weight of 50
- others types of objects, weight variables

- walls (immovable)

RULES

- heroes can push 1 or more objects, but as long as the weight of the objects is less than its force
- example: the boy (power=100) can push 1 object (100), 2 objects (50+50), or any combination of objects, sum(weight) <= 100;

- all = can't push nothing when at least one pushed object is touching a wall (right or left)...

- objects can fall, stopped by walls or others objects (including heroes)

- objects can be stacked but an object can only be on a heavier object
- ex: a small box (w=50) can be on an other small, or on a big one
- ex: a big box (w=100) will crush a smaller one (w=50)
- ex: 2 small boxes will crush the girl (power=50) but not the boy (power=100)

QUESTION

How do I get to settle the physics (collisions) and body parameters of objects/heroes to achieve the rules?

In a collision function, I have try this, it's work for "ONE hero moving ONE box", but I can't find how I can be if their are 2 or more objects...

if (hero.body.touching.right || hero.body.touching.left) {
if (hero.data.power >= box.data.weight) {
box.body.moves = true;
} else {
box.body.moves = false;
}
} else {
box.body.moves = false;
}

If someone has a clue ...

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.