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 coreysnyder

Here is an entity that I have:

EntitySnowball = EntityWeapon.extend({
        animSheet: new ig.AnimationSheet( 'media/web/ammo/snowball.png', 18, 18),
		weaponID: 0,
        size: {x: 18, y: 18},
        bounciness: 0.6,
        friction: {x:500, y: 0},
        damage: 1,
        init: function (x, y, settings)
        {
            this.velocity = settings.velocity || {x: 0, y: 0};
            this.parent(x, y, settings);
            this.addAnim( 'idle', 1, [0]);
            this.pos = {x: x, y: y};
        }
    });

Now I have a set of menus that sit over the game. One of these menus is a store. I want to be able to upgrade the damage of the snowball if it is purchased from inside the store. From then on, any time that entity is spawned it has the updated damage. Has anyone accomplished this before? If so, how?

Thanks,
Corey

1 decade ago by Joncom

You would need to know whether or not the user has payed for the upgrade. Likely you will have a server with a database containing this information.

Then it would simply take an AJAX call to a script which let's your game know whether or not to use the upgrade.

1 decade ago by coreysnyder

I guess I wasn't clear in my question. I'm less worried about the whole server portion of it, and more interested in how to actuall update the entity. It has a property called:
this.damage = 1;
I need to make it be:
this.damage = 2 after the click the buy button.

I can't do "EntitySnowball.damage = 3" from outside of the game framework. Nor can I do something like the code below because at the time of the store being open, the game is not running an there is no current instance of snowball.
var snowball = ig.game.getEntitiesByType( EntitySnowball )[0];

My current and only idea is to use some global variable which I reference in the init method of the snowball where I say:
  .....
init: function (x, y, settings)
        {
            ...blah code here...

            this.damage = globalWeaponVar.snowball.damage; // Referencing global that was set outside of the game loop. 

        }

Then on button click for buy do something like:
    globalWeaponVar.snowball.damage += 1;

Ideally there where I'm setting the global I'd rather do something like this:
    ig.game.entities.SnowBall.damage += 1;

That way I'm not adding clutter to the global namespace.
Page 1 of 1
« first « previous next › last »