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

2020/4/26

How do I make a highscore?

1
2
3
danpost danpost

2020/4/28

#
You will probably have to insert some System.out.println statements to track what is being executed.
HairyChickens HairyChickens

2020/4/28

#
danpost wrote...
You will probably have to insert some System.out.println statements to track what is being executed.
Whats that?
danpost danpost

2020/4/28

#
Like:
public void plutoTouched1()
{
    System.out.println("pluto touched");
    if (player_1.player1score > player_2.player2score)
    {
        System.out.println("win verified");
        addObject(new Player_1_Wins(),getWidth()/2, getHeight()/2);
        Greenfoot.playSound("Victory.mp3");
        if (player_1.player1score > high_1)
        {
            System.out.println("high score achieved");
            high_1 = player_1.player1score;
            showStatus();
        }
        Greenfoot.stop();
    }
}
The first output may cause your scenario to pause. Just click on 'Run' if that happens. Report full terminal output.
HairyChickens HairyChickens

2020/4/28

#
A terminal window pops up shows pluto touched win verified high score achieved
danpost danpost

2020/4/28

#
HairyChickens wrote...
A terminal window pops up shows pluto touched win verified high score achieved
Okay, remove print lines. Out of curiosity, try removing the Greenfoot.stop line.
HairyChickens HairyChickens

2020/4/29

#
Same thing happens
danpost danpost

2020/4/29

#
HairyChickens wrote...
Same thing happens
Please show your entire GameWorld class.
HairyChickens HairyChickens

2020/4/30

#
public class GameWorld extends World
{
    private Player_1 player_1; 
    private Player_2 player_2;
    private static int high_1, high_2;

    /**
     * Constructor for objects of class GameWorld.
     * 
     */
    public GameWorld()
    {    
        // Create a new world with 1650x900 cells with a cell size of 1x1 pixels.
        super(1650, 900, 1);
        prepare();
    }

    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        Pluto pluto = new Pluto();
        addObject(pluto,69,72);
        Earth earth2 = new Earth();
        addObject(earth2,1562,826);
        player_1 = new Player_1();
        player_1.turn(-90);
        addObject(player_1,1510,820);
        player_2 = new Player_2();
        player_2.turn(-90);
        addObject(player_2,1621,820);
        Asteroid asteroid = new Asteroid();
        addObject(asteroid,344,223);
        Asteroid asteroid2 = new Asteroid();
        addObject(asteroid2,746,91);
        Asteroid asteroid3 = new Asteroid();
        addObject(asteroid3,646,305);
        Asteroid asteroid4 = new Asteroid();
        addObject(asteroid4,269,582);
        Asteroid asteroid5 = new Asteroid();
        addObject(asteroid5,216,394);
        Asteroid asteroid6 = new Asteroid();
        addObject(asteroid6,621,521);
        Asteroid asteroid7 = new Asteroid();
        addObject(asteroid7,392,787);
        Asteroid asteroid8 = new Asteroid();
        addObject(asteroid8,925,725);
        Asteroid asteroid9 = new Asteroid();
        addObject(asteroid9,1009,496);
        Asteroid asteroid10 = new Asteroid();
        addObject(asteroid10,906,317);
        Asteroid asteroid11 = new Asteroid();
        addObject(asteroid11,1209,69);
        Asteroid asteroid12 = new Asteroid();
        addObject(asteroid12,1566,254);
        Asteroid asteroid13 = new Asteroid();
        addObject(asteroid13,620,783);
        Asteroid asteroid14 = new Asteroid();
        addObject(asteroid14,1253,285);
        removeObject(asteroid5);
        asteroid.setLocation(231,292);
        WaterBlob waterblob = new WaterBlob();
        addObject(waterblob,811,675);
        WaterBlob waterblob2 = new WaterBlob();
        addObject(waterblob2,770,387);
        WaterBlob waterblob3 = new WaterBlob();
        addObject(waterblob3,376,417);
        WaterBlob waterblob4 = new WaterBlob();
        addObject(waterblob4,135,754);
        WaterBlob waterblob5 = new WaterBlob();
        addObject(waterblob5,384,89);
        WaterBlob waterblob6 = new WaterBlob();
        addObject(waterblob6,966,91);
        Timer timer = new Timer();
        addObject(timer,73,66);
        WaterBlob waterblob7 = new WaterBlob();
        addObject(waterblob7,1378,393);
        WaterBlob waterblob8 = new WaterBlob();
        addObject(waterblob8,1327,610);
        Scorepanel scorepanel = new Scorepanel();
        addObject(scorepanel,240,887);
        scorepanel.setLocation(240,882);
        Barrier barrier = new Barrier();
        addObject(barrier,1649,887);
        BackgroundMusic backgroundmusic = new BackgroundMusic();
        addObject(backgroundmusic,69,86);
        Alien alien = new Alien();
        addObject(alien,55,55);
        alien.setLocation(70,66);
    }

    public void plutoTouched1()
    {
        if (player_1.player1score > player_2.player2score)
        {
            addObject(new Player_1_Wins(),getWidth()/2, getHeight()/2);
            Greenfoot.playSound("Victory.mp3");
            if (player_1.player1score > high_1)
            {
                high_1 = player_1.player1score;
                showStatus();
            }
            Greenfoot.stop();
        }
    }

    public void showStatus()
    {
        showText("Highscore : "+high_1, 100,100);
        showText("Highscore : "+high_2, 100,100);
    }


    public void plutoTouched2()
    {
        if (player_2.player2score > player_1.player1score)
        {
            addObject(new Player_2_Wins(), getWidth()/2,getHeight()/2);
            Greenfoot.playSound("Victory.mp3");
            if (player_2.player2score > high_2)
            {
                high_2 = player_2.player2score;
                showStatus();
            }
            Greenfoot.stop();
        }
    }

}
danpost danpost

2020/4/30

#
Okay, how about your entire Player_1 class.
HairyChickens HairyChickens

2020/4/30

#
Here you go
public class Player_1 extends Actor
{
    public int player1score;
    public int player1death;
    private GreenfootImage rocket1imagenoflames= new GreenfootImage("rocket3.png");
    private GreenfootImage rocket1imageflames= new GreenfootImage("rocket4.png");

    /**
     * Act - do whatever the Player_1 wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        rocketMovement();
        detectPlayer_2Collision();
        detectAsteroidCollision();
        collectWaterBlob();
        winCheck();
    }


    private void rocketMovement()
    {
        if (Greenfoot.isKeyDown("d"))
        {
            turn(5);
        }
        if (Greenfoot.isKeyDown("a"))
        {
            turn(-5);
        }
        if (Greenfoot.isKeyDown("w"))
        {
            move(5);
            setImage(rocket1imageflames);
        }
        else
        {
            setImage(rocket1imagenoflames);
        }
    }


    public void detectPlayer_2Collision()
    {
        if (isTouching(Player_2.class))
        {
            Greenfoot.playSound("explosion.mp3");
            setLocation(1510,820);
            setRotation(-90);
            player1score = (0);
            increaseDeath();
        }
    }


    public void detectAsteroidCollision()
    {
        if (isTouching(Asteroid.class))
        {
            Greenfoot.playSound("explosion.mp3");
            setLocation(1510,820);
            setRotation(-90);
            player1score = (0);
            increaseDeath();
        }
    }


    public void collectWaterBlob()
    {
        if (isTouching(WaterBlob.class))
        {
            removeTouching(WaterBlob.class);
            Greenfoot.playSound("drip.mp3");
            increaseScore();
            World world = getWorld();
            world.addObject(new WaterBlob(), Greenfoot.getRandomNumber(1690), Greenfoot.getRandomNumber(900));
        }
    }


    public void increaseScore()
    {
        player1score++;
        showStatus();
    }


    public void increaseDeath()
    {
        player1death++;
        showStatus();
    }


    public void winCheck()
    {
        if (isTouching(Pluto.class))
        {
            ((GameWorld)getWorld()).plutoTouched1();
        }
    }


    public void showStatus()
    {
        getWorld().showText("Player 1 Score : "+player1score, 93,865);
        getWorld().showText("Player 1 Death : "+player1death, 93,885);
    }

    protected void addedToWorld(World world)
    {
        showStatus();
    }
}
danpost danpost

2020/4/30

#
What are the player's location coordinates (x and y values) of the closest point to the door? (inspect player and find x and y values)
HairyChickens HairyChickens

2020/5/1

#
danpost wrote...
What are the player's location coordinates (x and y values) of the closest point to the door? (inspect player and find x and y values)
To the door?
HairyChickens HairyChickens

2020/5/2

#
danpost wrote...
What are the player's location coordinates (x and y values) of the closest point to the door? (inspect player and find x and y values)
What did you mean by to the door? Do you mean pluto?
danpost danpost

2020/5/2

#
HairyChickens wrote...
<< Quote Omitte >> To the door?
Sorry. I believe I put that to the wrong discussion.
danpost danpost

2020/5/2

#
Oh my. Lines 111 and 112 in your GameWorld class put both lines of text to the same location. Change one (or both of) them to put to different locations.
There are more replies on the next page.
1
2
3