Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by fuelless

Hello everyone!
I'm new around these parts (bought the licence last Friday) but I am already enjoying the engine very much.

I'm planning on doing a top-down rpg much like secret of mana and was wondering how are you guys solving the melee attacks in your projects.

I understand, and have done ranged attacks in the tutorials, but I was wondering which would be the best way to solve melee ones. The idea is that there will be different kinds of weapons available to the characters.

The solutions that occurred to me are:

>checking for the distance between the enemies and the player-character and the orientation. Maybe even considering the angles between them as well. The wepons would be a separate entity with animations just like the character.
>using the bounding boxes impact already has implemented, having the weapon as a different entity (only one frame) and rotating accordingly to the attack. This is the more realistic one but I'm not so sure about how to do it.

Thanks in advance!

1 decade ago by Joncom

A simple solution might be to spawn a 1x1 pixel entity at the location relative to your player where you want to attack.

If you are attacking to the left, then it might be player.pos.x - 3 and player.pos.y - 5. Just examples. Spawn the entity at that position.

The entity would have some logic in it's init function like this:

init: function(x, y, settings) {
    this.parent(x, y, settings);
    var enemies = ig.game.getEntitesByType(EntityEnemy); // Get enemies
    for(var i=0; i<enemies.length; i++) { // For all enemies...
        if(this.touches(enemies[i])) { // Check if enemy is being attacked.
            enemies[i].take_damage(100); // Deal damage to enemy.
        }
    }
    // This entity is no longer needed. Get rid of it.
    this.kill();
}
Page 1 of 1
« first « previous next › last »