salve a tutti
sto provando a creare un giochino
il mio omino dovrebbe sparare se premo il tasto Alt un colpo (richiamato dalla libreria "Bullet")
e nel frattempo scalare un colpo dalle munizioni in dotazione ("shots")
il problema è che se premo Alt per poco più di un attimo continua a scalarmi gli "shots" senza sparare altri colpi.
io vorrei che venisse sparatoun colpo alla volta, cioè fino a quando il colpo è On Screen io non posso sparare nessun altro colpo e ovviamente non deve diminuire il numero delle munizioni
riporto di seguito i codici usati
il primo è la funzione che viene richiamata dal personaggio(hero), qst AS si trova sul frame
Codice PHP:
function fireBullet() {
if (_root.bulletOnScreen==false ) {
// crea un colpo
attachMovie("Bullet", "bulletMC", 1000);
_root.shots=_root.shots-1;
_root.bulletOnScreen = true;
// posizione di partenza colpo
bulletMC._x = hero._x+(15*hero.rot);
bulletMC._y = hero._y;
// direzione colpo
heroAngle = 2*Math.PI*(hero._rotation);
bulletMC.dx = Math.cos(heroAngle)*hero.rot;
bulletMC.dy = Math.sin(heroAngle)*hero.rot;
bulletMC.moveBullet = moveBulletFunction;
setInterval(bulletMC, "moveBullet",50, bulletMC);
}else{_root.bulletOnScreen = false}}
function moveBulletFunction() {
// movimento colpo
bulletSpeed = 10.0;
dist=Math.abs(hero._x-this._x);
this._x += bulletSpeed*this.dx;
this._y += bulletSpeed*this.dy;
// rimozione colpo
dist=Math.abs(hero._x-this._x);
if (dist >100) this.removeMovieClip();
if (this._x < 0) this.removeMovieClip();
if (this._y > 280) this.removeMovieClip();
if (this._y < 0) this.removeMovieClip();
if (this.hitTest(_root.map["hot"+i])) this.removeMovieClip();
_root.bulletOnScreen = false;
}
qst invece il codice riportato in "hero" per richiamare la funzione
Codice PHP:
if(Key.isDown(Key.ALT)) {
if(_root.shots>=1)
_root.fireBullet();
}