Bad Guy Machine Gun
by Jon Jorajuria · in Torque Game Builder · 12/12/2006 (12:56 pm) · 2 replies
I am trying to schedule out five round machine gun burst from a character. On the first pass the schedule works fine, after that things go crazy and the machine gun floods the game. Can anybody tell me what I am doing wrong here?
function myBadGuyClass::fireBullet(%this)
{
if(!%this.isDead)
{
%this.isFiring = true;
%this.bulletFiring = %this.schedule(100, fireBullet);
%this.schedule(500, cancelFirebullet);
%this.enemyBadGuyBullet = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = enemyBadGuyBullet;
bulletSpeed = %this.bulletSpeed;
enemy = %this;
}
%this.enemyBadGuyBullet.fireBadGuyBullet02();
}
}
function myBadGuyClass::cancelFireBullet(%this)
{
cancel(%this.bulletFiring);
%this.isFiring = false;
%this.schedule(1000, fireBullet);
}About the author
Associate Tom Eastman (Eastbeast314)
function myBadGuyClass::fireBullet(%this) { if(!%this.isDead) { %this.isFiring = true; %this.bulletFiring = %this.schedule(100, fireBullet); [b]if( !isEventPending( %this.cancelFireSchedule ) %this.cancelFireSchedule = %this.schedule(500, cancelFirebullet);[/b] %this.enemyBadGuyBullet = new t2dStaticSprite() { scenegraph = %this.scenegraph; class = enemyBadGuyBullet; bulletSpeed = %this.bulletSpeed; enemy = %this; } %this.enemyBadGuyBullet.fireBadGuyBullet02(); } } function myBadGuyClass::cancelFireBullet(%this) { cancel(%this.bulletFiring); %this.isFiring = false; %this.schedule(1000, fireBullet); }This way, you'll only have one cancel event at a time, so they won't be all calling their own fire events. Also, since you should only have one fire schedule running at any moment, you could also ID that one (just assigning the return value (the ID) from a schedule to a variable and then using that to make sure you don't make another). That should make the code more robust.
Hope that helps fix it ;)