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

2018/12/12

game over image not displaying

hmhmhn hmhmhn

2018/12/12

#
I want my gameover world to display when 8 points is reached by one player. right now I have the code for the delay in which the gameover screen should display but do not understand why when I run my game the delay happens after 8 points is reached but the image does not display. this is my code for my world class (PongWorld) that I want to put the gameover code into
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class PongWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PongWorld  extends World
{
    private Paddle paddle;
    public Paddle paddle1;
    public Paddle paddle2;
    public Counter score1;
    public Counter score2;
    public Gameover Gameover;

    /**
     * Constructor for objects of class PongWorld.
     * 
     */
    public PongWorld()
    {    
        // Create a new world with 20x20 cells with a cell size of 10x10 pixels.
        super(700, 500, 1);

        score1=new Counter();
        score2= new Counter();
        addObject (score1, 50, 35);
        addObject(score2,50,465);

        paddle1 = new Paddle();
        addObject ( paddle1, getWidth() / 2, getHeight() - 40);
        paddle2 = new Paddle("a","s");
        addObject ( paddle2, getWidth() / 2, getHeight() - 450);

        addObject(new Ball(), 350, 250);

        GreenfootImage bg = new GreenfootImage("pink.jpg");
        bg.scale(getWidth(), getHeight());
        setBackground(bg);
    }

    public void scoreTop()
    {
        score1.add(1);

    }

    public void scoreBottom()
    {
        score2.add(1);

    }

    public void act()
    {if (score1.getValue()==8) 
        {
        Greenfoot.setWorld(new Gameover());
        Greenfoot.delay (120);  
        }
        if (score2.getValue()==8) 
     {
         Greenfoot.setWorld(new Gameover());
         Greenfoot.delay (120);  
       }
    }
}
danpost danpost

2018/12/12

#
hmhmhn wrote...
I want my gameover world to display when 8 points is reached by one player. right now I have the code for the delay in which the gameover screen should display but do not understand why when I run my game the delay happens after 8 points is reached but the image does not display. this is my code for my world class (PongWorld) that I want to put the gameover code into << Code Omited >>
Please show your GamOver class code as well. Also, please explain exactly when you want to approximate 2 second delay to occur (as with what should be visible before, during and after).
hmhmhn hmhmhn

2018/12/12

#
my Gameover class does not have any code as im just using it as an image. before the delay the game will just reach 8 points, t ill start the delay, during the delay of 2 seconds I want my gameover image to be shown on the screen and once the delat of two seconds is over the game will restart
hmhmhn hmhmhn

2018/12/12

#
that will*
danpost danpost

2018/12/12

#
hmhmhn wrote...
my Gameover class does not have any code as im just using it as an image. before the delay the game will just reach 8 points, that will start the delay, during the delay of 2 seconds I want my gameover image to be shown on the screen and once the delat of two seconds is over the game will restart
You will need some code in your GameOver world. At least something to set a new PongWorld object active. The delay should probably be in that class also:
public void act()
{
    Greenfoot.delay(120);
    Greenfoot.setWorld(new PongWorld());
}
You need to login to post a reply.