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

2013/11/10

BulletHitsZombie = ZombieDead ???

Prish950 Prish950

2013/11/10

#
I need help with a Zombie Survival Game. I want to write that if the currentX and Y of the bullet the same is like of the Zombies the Zombie have to be removed and the bullet too. would be nice if i get some help :)
payner2013 payner2013

2013/11/10

#
put this in your zombie Actor. this code removes the Zombie and the bullet if it comes into contact will the zombie... was this what you was looking for?
 Actor Bullet;
    Bullet = getOneObjectAtOffset(0, 0, Bullet.class);
    if (Bullet != null)
    {
        World world;
        world = getWorld();
        world.removeObject(this);
        world.removeObject(Bullet);
Prish950 Prish950

2013/11/10

#
I wrote it like that: Kugel = Bullet
public void sterben() 
    {
     Kugel kugel;  
     kugel = getOneObjectAtOffset(0, 0, Kugel.class); 
     if (Kugel != null)  
      {  
       World world;  
       world = getWorld();  
       world.removeObject(this);  
       world.removeObject(Kugel); 
 
      }
    }
but its saying incompatible types and this line is meant:
Bullet = getOneObjectAtOffset(0, 0, Bullet.class);
what is the problem what can i do ?? anyway thanks for help hope you replay again
danpost danpost

2013/11/10

#
In line 3, you are naming your Kugel object 'kugel', yet you are using the class name throughout the rest of the method, instead of the field name.
Prish950 Prish950

2013/11/10

#
i didn't get it what i have to write different ?? in line 3 the class name or should i name it different in line 3?? or in line 4 Kugel in lowercase ?? can you show a specific example ?? Thanks :)
danpost danpost

2013/11/10

#
It should be lowercase in line 5 and line 10.
Prish950 Prish950

2013/11/10

#
public void sterben() 
    {
     Kugel kugel;  
     kugel = getOneObjectAtOffset(0, 0, Kugel.class); 
     if (kugel != null)  
      {  
       World world;  
       world = getWorld();  
       world.removeObject(this);  
       world.removeObject(kugel); 
 
      }
    }
It finally have the same error. is there any other failure around that code or is it possible that i made somewhere else the mistake
danpost danpost

2013/11/10

#
Change line 3 to this:
Actor kugel;
Prish950 Prish950

2013/11/11

#
Thanks but finally it don't make an error but the zombies didn't remove :( so what should i do?? that is the zombie code:
public class Zombie extends Actor
{
    
    public static int currentZombieX;
    public static int currentZombieY;
    
    
     public static int leben = 100;

    
    /**
     * Act - do whatever the Zombie wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       AutoAiming();
        
       currentZombieX = getX();
       currentZombieY = getY();
    }
    
    public void AutoAiming() 
    {
        turnTowards(Roboter.currentX, Roboter.currentY);
        move(1);
    }
    
    public void sterben() 
    {
     Actor kugel;  
     kugel = getOneObjectAtOffset( 0, 0, Kugel.class); 
     if (kugel != null)  
      {  
       World world;  
       world = getWorld();  
       world.removeObject(this);  
       world.removeObject(kugel); 
 
      }
    }
}
And this is the Bullet Code:
public class Kugel extends Actor
{
    
    private boolean getAngle = true;
    
    /**
     * Act - do whatever the Kugel wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        angleSelect();
        move(10);
        
    }    
    
    public void angleSelect() 
    {
        if (getAngle == true)
        {
            setRotation(Roboter.currentRot);
            getAngle = false;
        }    
    }
    
  
}
Prish950 Prish950

2013/11/11

#
OHHHHH FUCK FACEPALM!!!! :D I DIDNT WRITE IT IN ACT :)))) HAHAHAHAHA THANKS SO MUCH IT WORKS :)))))
You need to login to post a reply.