public void act() 
    {
        Lvl2BkgDesert myWorld = (Lvl2BkgDesert)getWorld();
        count++;
        //Detects when the dart hits the rock. When it does, the action follows.    
        List<Actor> mylist = (List<Actor>) getObjectsInRange(30,Darts.class);
        //Actor Darts=getOneIntersectingObject(Darts.class);
        if ( ! mylist.isEmpty())
        {
            Actor Darts = getOneIntersectingObject(Darts.class);
            if(Darts!=null)
            {
                getWorld().removeObject(Darts);
                if(colorchanged)
                {
                    Greenfoot.playSound("OrangeCacti.wav");
                    shotstaken++;
                    myWorld.DecrememntDarts(1);
                }
                else
                {
                    myWorld.DecrememntDarts(3);
                    Greenfoot.playSound("greencactus.wav");                
                }    
            }
            
            //Detects when explodes
            if(shotstaken > 3)
            {
                getWorld().addObject(new Explosion(), getX(), getY());
                shotstaken = 0;
                Greenfoot.playSound("explosion.wav");
                myWorld.IncrementDarts(5);
            }
        }
        
        //change the color of the cacti
        if(!colorchanged)
        {
            if(count % randtime == 0)
            {
                GreenfootImage img1 = new GreenfootImage("cactus_sprite.png");
                img1.scale(scalefactor, scalefactor);
                setImage(img1);
                colorchanged = true;
            }
        }
        else if(colorchanged)
        {
            if(count % 100 == 0)
            {
                GreenfootImage img = new GreenfootImage("cactus_sprite1.png");
                img.scale(scalefactor, scalefactor);
                setImage(img);  
                colorchanged = false;
                randtime = (Greenfoot.getRandomNumber(7) + 2)*100;        
            }
        }
    }