collinhover / impactplusplus

Impact++ is a collection of additions to ImpactJS with full featured physics, dynamic lighting, UI, abilities, and more.
http://collinhover.github.com/impactplusplus
MIT License
276 stars 59 forks source link

Ability spawningEntity seemingly not working #154

Closed codecomp closed 10 years ago

codecomp commented 10 years ago

I've started tinkering with making a somple game with ++ instead of just plain old ImpactJS. I decided following the tutorials would be a good way to see how to get started before jumping into making things msyelf. However I've bit a bit of a road block on the second one.

I have the following in my player entity:

initProperties: function() {
        this.parent();
        this.shoot = new ig.LaserGun(this);
        this.abilities.addDescendants([
           this.shoot
        ]);
    },
    handleInput: function() {
        this.parent();
        if (ig.input.pressed('shoot')) {
            ig.log('Fire!');
            this.shoot.activate({
                x: this.flip.x ? this.pos.x : this.pos.x + this.size.x,
                y: this.pos.y + this.size.y * 0.5
            });
        }
    }

And when I try to shoot I do get the log saying Fire. But there is no entity spawned.

Here is my laser entity

ig.module(
    'game.entities.laser'
)

.requires(
    'plusplus.abstractities.projectile'
)

.defines(function () {
    ig.EntityLaser = ig.global.EntityLaser = ig.Projectile.extend({
        collides: ig.EntityExtended.COLLIDES.LITE,
        size: {x: 4, y: 4},
        offset: {x: 2, y: 2},
        animSheet: new ig.AnimationSheet( 'media/laser.png', 8, 8),
        animInit: "idleX",
        animSettings: {
            moveX: { sequence: [0], frameTime: 1 },
            deathX: { sequence: [1,2,3,4,5], frameTime: 0.05 }
        },
        damage: 2, // lasers hurt
        lifeDuration: 2, // lasers eventually fade (like a particle)
        gravityFactor: 0, // lasers ignore gravity
        friction: {x:0, y:0}, // lasers have no friction
        bounciness: 0, // lasers don't bounce
        collisionKills: true, // lasers stop if they hit a wall
    });
});

And my laser-gun ability

ig.module(
    'game.abilities.laser-gun'
)

.requires(
    'plusplus.abilities.ability-shoot',
    'game.entities.laser'
)

.defines(function () {
    ig.LaserGun = ig.AbilityShoot.extend({
        spawningEntity: ig.EntityLaser,
        offsetVelX: 200
    });
});

I also noticed that the following line in the tutorial has a typo in it starting a string eith " and ending with '

animSheet: new ig.AnimationSheet( "media/projectile.png', 8, 8),
Pattentrick commented 10 years ago

Hey @Ralliare,

glad to hear that you are trying ++ out. Have you downloaded the latest dev branch? In older ++ versions the shoot ability checks if the entity that uses the shoot ability is "inside the level".

Unfortunately this check will fail every time if you don't have a level that is completely surrounded by collision tiles. So if there is a "hole" in your collision map, or you just have a few collision tiles, the shoot ability will do nothing.

Because of that @collinhover removed this check in the current dev branch and added some more minor fixes to the shoot-ability. Please switch to the dev branch and report if that fixes your problem.

Thanks for reporting the typo. There are more in some of the tutorials. I will fix the typo and rewrite some of them as soon as I have some time for that ;-)