Keyboard shot
fgb01

Good afternoon people,
I'm trying to make a shooting system using the keyboard but it's not working properly ... do not fire one at a time
Could you please help me?
Thank you very much.
Here's my code:

var controlKeys =
{
    left: "left",
    right: "right",
    space: "space"
};

if(wade.isKeyDown(controlKeys.left)&&!wade.isKeyDown(controlKeys.right))
{
   this.setVelocity(-100,0);
}else if(wade.isKeyDown(controlKeys.right)&&!wade.isKeyDown(controlKeys.left))
{
    this.setVelocity(100,0);
} else{
    this.setVelocity(0,0);
}

if(wade.isKeyUp(controlKeys.space)){
    var tiro = wade.getSceneObject("Tiro").clone();
    tiro.setPosition(this.getPosition().x, this.getPosition().y-50);
    wade.addSceneObject(tiro);
    tiro.moveTo(0, this.getPosition().y,-300);
}

 

 

All 2 Comments
fgb01

So much staff that I insisted that I ...
Thank you

krumza
if(wade.isKeyDown("space")){//isKeyDown!!!
    //reload = time_in_seconds*1000/16 
    //i set it to 20 below

    if(this.reload>=20){
        var pos = this.getPosition();//cache coordinates 
        var tiro = wade.getSceneObject("Tiro").clone();
        tiro.setPosition(pos.x, pos.y-50);
        wade.addSceneObject(tiro);
        tiro.moveTo(pos.x, pos.y-500,300);//speed!!!
        this.reload=0;
    } else {
        (isNaN(this.reload))? this.reload=20 : this.reload++;
    }
}

 

Post a reply
Add Attachment
Submit Reply
Login to Reply