This site requires JavaScript, please enable it in your browser!
Greenfoot back
Al7amed
Al7amed wrote ...

2014/4/14

stop shooting when move

Al7amed Al7amed

2014/4/14

#
In my game I want to stop shoot if you press right or left with space. disable space something like that .. my game is in my account you can try it
danpost danpost

2014/4/14

#
if (!Greenfoot.isKeyDown("left") &&
    !Greenfoot.isKeyDown("right") &&
    Greenfoot.isKeyDown("space"))
Al7amed Al7amed

2014/4/14

#
where should i put this .. i think it's not complete I want to do something like this if (Greenfoot.isKeyDown("left") && Greenfoot.isKeyDown("right")) { Greenfoot.isKeyDown("space") = false; } but this is wrong
danpost danpost

2014/4/14

#
It is a complete conditional statement and it will regulate the firing of shots the way you want. It is much easier to say when to do something than when not to do something. One more condition will probably need added to it. The condition of the shot delay timer (is it zero); but, that was not part of the main subject matter. If you really want to do it like you tried above, then:
boolean noCanFire = Greenfoot.isKeyDown("left") || Greenfoot.isKeyDown("right");
if (!noCanFire && Greenfoot.isKeyDown("space")) // fire shot
however, this is awkward with the double-negative.
You need to login to post a reply.