Using ImpactJS: How to set a publicly available variable
Posted
by
Dave Voyles
on Game Development
See other posts from Game Development
or by Dave Voyles
Published on 2013-03-05T22:28:32Z
Indexed on
2013/11/03
16:13 UTC
Read the original article
Hit count: 227
JavaScript
I'm trying to get an entity (a bullet, a grenade, and an explosive) from my player player. Specifically, I want the shootingRate of my bullet (how frequently it can be fired).
How can I do this without having to call getEntityByType each time I fire this projectile? There has got to be a cleaner way from what I'm doing right now....
// Shooting
var isShooting = ig.input.state('shoot');
if (isShooting && this.lastShootTimer.delta() > 0) {
switch (this.activeWeapon)
{
case("EntityBullet"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y - 10);
var equipedWeap = ig.game.getEntitiesByType(EntityBullet);
this.lastShootTimer.set(equippedWeap.shootingRate);
console.log(equipedWeap.shootingRate);
break;
case("EntityGrenade"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5);
var equipedWeap = ig.game.getEntitiesByType(EntityGrenade);
this.lastShootTimer.set(equipedWeap.shootingRate);
console.log(EquipedWeap.shootingRate);
break;
case("EntityExplosiveBomb"):
ig.game.spawnEntity(this.activeWeapon, this.pos.x, this.pos.y +5 );
var equipedWeap = ig.game.getEntitiesByType(EntityExplosiveBomb)[0];
this.lastShootTimer.set(equipedWeap.shootingRate);
console.log(equipedWeap.shootingRate);
break;
}
}
© Game Development or respective owner