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

2020/3/21

Pong Score not working

Sakura.Waifu Sakura.Waifu

2020/3/21

#
Hello, I have a problem with my Pong game I wanted to make. Everything works ecept the score. I wanted that my ball, if he is at the position where a point is being scored, would move back to the center and my score would get up. I do not know how to make that in Greenfoot. Can somebody help me?
danpost danpost

2020/3/21

#
Depends on where and how you maintain the score. Cannot help without seeing your codes.
RcCookie RcCookie

2020/3/23

#
Well basically you could use a setup like this:
//in ball class
public void act(){
    //your code for movement and other stuff here
    if(scoring){ //replace with your scoring condition 
        Greenfoot.setWorld(new MyWorld(((MyWorld)getWorld()).getScore()+addedScore));
    }
}

//in MyWorld class
private int score;
public MyWorld(){ //standard constructor
    //whatever you do here
    score = 0;
}
public MyWorld(int pScore){
    //same code you had in the other one
    score = pScore;
}
public int getScore(){
    return score;
}
This code basically resets the game but saves the point scored by telling it the new world. But like danpost said you better show us some of the code if you want more detailed information
You need to login to post a reply.