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

2018/3/5

Getting Rid of actors

1
2
Heet_Patel Heet_Patel

2018/3/5

#
I have created a scenario in greenfoot but it is not fully not complete, so I need help with one last thing.
Heet_Patel Heet_Patel

2018/3/5

#
I created one gameover screen where when the rocket crashes with trump or the border the gameover screen pops up. But when I do this the little men still left out continue to move. So i need the little men to stop moving or just disappear. Please tell me the code. This is the code for the gameover:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class GameOver here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GameOver extends Actor
{
    /**
     * Act - do whatever the GameOver wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setImage(new GreenfootImage("Game Over", 48, Color.PINK, Color.YELLOW));
    }    
}
This is the code which makes the gameover screen pop up:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Zyxian here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Zyxian extends Actor
{
    /**
     * Act - do whatever the Zyxian wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(4);
     if (Greenfoot.isKeyDown("Left"))
     {
         turn(-3);
     }
     if (Greenfoot.isKeyDown("Right"))
     {
         turn(3);
     }
     
     Actor Villian;
     Villian = getOneObjectAtOffset(0,0,Villian.class);
     if(Villian!=null)
     {
         TheHouse thehouse = (TheHouse)getWorld();
         thehouse.removeObject(Villian);
         Greenfoot.playSound("Scream.wav");
         Counter counter = thehouse.getCounter();
         counter.bumpCount(5);
     }    

     Actor Border = getOneIntersectingObject(Border.class);
     if (Border != null)
     {
         World TheHouse = getWorld();
         GameOver gameover = new GameOver();
         Greenfoot.playSound("Bomb.wav");
         TheHouse.addObject(gameover, TheHouse.getWidth()/2, TheHouse.getHeight()/2);
         TheHouse.removeObject(this);
}
}
}
This is the code for donald trump:
import greenfoot.*;
 
public class Donald_Trump extends Actor
{
    public Donald_Trump()
    {
        GreenfootImage image = getImage();
        image.scale(image.getWidth() - 150, image.getHeight() - 120);
        setImage(image);
    }
 
    public void act()
    {
        move(2);
       if (Greenfoot.getRandomNumber(100) < 10)
       {
           turn(Greenfoot.getRandomNumber(90) - 45);
       }   
       if (getX() <= 5 || getX() >= getWorld().getWidth() - 5)
       {
           turn(180);
       }
       if (getY() <= 5 || getY() >= getWorld().getHeight() - 5)
       {
           turn(180);
       }
       Actor Zyxian = getOneIntersectingObject(Zyxian.class);
     if (Zyxian != null)
     {
         World TheHouse = getWorld();
         GameOver gameover = new GameOver();
         Greenfoot.playSound("Laugh.wav");
         Greenfoot.playSound("Bomb.wav");
         TheHouse.addObject(gameover, TheHouse.getWidth()/2, TheHouse.getHeight()/2);
         TheHouse.removeObject(Zyxian);
}
    }
}
So i need the little men to stop moving when the game over screen pops up.
danpost danpost

2018/3/5

#
Just use:
Greenfoot.stop();
Heet_Patel Heet_Patel

2018/3/5

#
When I write this code the gameover screen doesn't appear. Before the code was written the gameover would pop up, but after writing the code the gameover would pop up has a little green foot. like legit a little greenfoot. Its looks like the logo of Greenfoot
danpost danpost

2018/3/5

#
Heet_Patel wrote...
When I write this code the gameover screen doesn't appear. Before the code was written the gameover would pop up, but after writing the code the gameover would pop up has a little green foot. like legit a little greenfoot. Its looks like the logo of Greenfoot
Show how you used it. Show the code (always).
Heet_Patel Heet_Patel

2018/3/5

#
fine
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Zyxian here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Zyxian extends Actor
{
    /**
     * Act - do whatever the Zyxian wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(4);
     if (Greenfoot.isKeyDown("Left"))
     {
         turn(-3);
     }
     if (Greenfoot.isKeyDown("Right"))
     {
         turn(3);
     }
      
     Actor Villian;
     Villian = getOneObjectAtOffset(0,0,Villian.class);
     if(Villian!=null)
     {
         TheHouse thehouse = (TheHouse)getWorld();
         thehouse.removeObject(Villian);
         Greenfoot.playSound("Scream.wav");
         Counter counter = thehouse.getCounter();
         counter.bumpCount(5);
     }    
 
     Actor Border = getOneIntersectingObject(Border.class);
     if (Border != null)
     {
         World TheHouse = getWorld();
         GameOver gameover = new GameOver();
         Greenfoot.playSound("Bomb.wav");
         TheHouse.addObject(gameover, TheHouse.getWidth()/2, TheHouse.getHeight()/2);
         TheHouse.removeObject(this);
         Greenfoot.stop();
}
}
}
Heet_Patel Heet_Patel

2018/3/5

#
Thats how i used it
danpost danpost

2018/3/5

#
You placed it properly. I cannot believe that the placing of the line had anything to do with the changing of the 'GameOver' image. How do you set the image of a GameOver object -- default class image (make sure it is there) or code (show code)?
Heet_Patel Heet_Patel

2018/3/5

#
Now it won't stop moving the character. Its still the same code.
danpost danpost

2018/3/5

#
Heet_Patel wrote...
Now it won't stop moving the character. Its still the same code.
You must have moved, edited or changed the line.
Heet_Patel Heet_Patel

2018/3/5

#
I put a update with the code. Even the greenfoot doesn't show up now
Heet_Patel Heet_Patel

2018/3/5

#
please tell me if you need to source code
danpost danpost

2018/3/5

#
Heet_Patel wrote...
please tell me if you need to source code
I guess so. Will get to it shortly (time for food).
Heet_Patel Heet_Patel

2018/3/5

#
please reply by 12 noon tommorow.
Heet_Patel Heet_Patel

2018/3/5

#
I have done it
There are more replies on the next page.
1
2