My character currently can shoot, but I want him to shoot when he gets then gun. Can someone help create a code the will not allow my character to shoot until he touches the gun.
private boolean gunTuched = false;
public void act() {
if (getOneIntersectingObject(Gun.class) != null)) {
gunTuched = true;
}
if (gunTuched /*and probably more conditions you can add here*/) {
shoot();
}
}//you don't need the boolean anymore;
public void act() {
if (getOneIntersectingObject(Gun.class) != null) {
//the other conditions for shooting;
shoot();
}
}// if you currently have in your character act method shoot(); // then qualify it with if (getOneIntersectingObject(Gun.class) != null) shoot();
private boolean gunTuched = false;
public void act() {
if (getOneIntersectingObject(Gun.class) != null)) {
gunTuched = true;
}
if (gunTuched /*and probably more conditions you can add here*/) {
shoot();
}
}//you don't need the boolean anymore;
public void act() {
if (getOneIntersectingObject(Gun.class) != null) {
//the other conditions for shooting;
shoot();
}
}public boolean gunTouched()
{
Actor gun = getOneIntersectingObject(Gun.class);
if(a!=null)
{
getWorld().removeObject(gun);
return true;
}
else
return false;
}boolean shootAllowed = false;
public void gunTouched()
{
Actor gun = getOneIntersectingObject(Gun.class); if(a!=null)
{
getWorld().removeObject(gun);
shootAllowed = true;
}
else
shootAllowed = false;
}
public void act()
{
gunTouched();
if(shootAllowed && Greenfoot.isKeyDown("space"))
//or how you want make the player to shoot
{
shoot();
shootAllowed=false;
}
}