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

2013/10/31

Spawning help

Baenefin Baenefin

2013/10/31

#
Hello all, I am trying to add a new object to the world by getting the X and Y from another object. I would like to spawn a heart if my enemy dies. Alice can kill an enemy by jumping on it. So when alice kills an enemy Alice should spawn another enemy?
public void checkCollisionEnemy()  
    {  
        
        Actor enemy = getOneObjectAtOffset(0, getImage().getHeight()/2+5, Walker.class); 
        if (enemy != null) 
        {    
            Greenfoot.playSound("DeathEnemy.wav");
            //code for spawn heart +32X
            //getWorld().addObject(new Heart(),getx(enemy), getY(enemy));
            ((enemyCounter)getWorld().getObjects(enemyCounter.class).get(0)).add(-1);
        }

        Actor collided = getOneIntersectingObject(Enemy.class);  
        if (collided !=null)  
        {
            if (!onEnemy && (Greenfoot.isKeyDown("right")))
            {
                onEnemy = true;
                setImage("DamageRight.png");
            }
            if (!onEnemy && (Greenfoot.isKeyDown("left")))
            {
                onEnemy = true;
                setImage("DamageLeft.png");
            }

            if (contactTimer ==0)
            {  
                ((Score)getWorld().getObjects(Score.class).get(0)).add(-1);
                Greenfoot.playSound("Damage.wav");
                contactTimer = 125;  
            }  
            else if (onEnemy)
            {
                onEnemy=false;
            }
        }
    }
You need to login to post a reply.