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

2013/10/15

Change world after an objected has been removed

Syntac Syntac

2013/10/15

#
Hey guys, got a new problem, what else.. This time I want that after I´ve clicked the Object, a movie appears (it isn´t actually a movie, it´s more like many pictures in a loop), then after the movie appears it should wait, lets say, 5 sec and then change the world. All works fine, except changing the world.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Bombe here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Bombe extends Actor
{
    public int iTime = 0;
    public int iZeit = 0;
    public int itimeTillDetonation =  0;
    GreenfootSound soundb = new GreenfootSound("C&C Generals music (GLA Battle Theme 1).wav");    
    GreenfootSound soundc = new GreenfootSound("GameOver.wav");
    /**
     * Act - do whatever the Bombe wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        explosion();        
        itimeTillDetonation++;        
        iTime++;      
        iZeit++;
    } 
         
    public void explosion()  
    {  
        soundb.play(); //Spiele Hintergrundmusik
        if(iTime > 1200) // Soll die Hintergrund nach ca. einer Minute stoppen
            {
               soundb.stop();
            }  
        movie movie = new movie();   
        GameOver GameOver = new GameOver();
        if(Greenfoot.mouseClicked(this))  //Wenn die Bombe angeglickt wird dann...
            {  
                getWorld().removeObject(this);     // ...soll sie entfernt werden     
                soundb.stop(); //...soll die Musik entfernen
            }  
                else   //ansonsten...
                    if(itimeTillDetonation > 200)  //... soll nach ca. 4 Sek. ...
                    {  
                        soundb.stop();              //... die Hintergrundmusik gestoppt werden,         
                        soundc.play();              //... ein neuer Sound abgespielt werden,
                        getWorld().addObject(movie, 670, 440);    //... ein Video hinzugefügt werden                    
                        getWorld().removeObject(this);            //... und die Bombe soll entfernt werden  
                        if(iZeit > 210)
                        {
                            Greenfoot.setWorld(GameOver);
                        }   
                   }  
    }  
}
You need to login to post a reply.