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

2019/1/16

Pong

1
2
Josh123 Josh123

2019/1/16

#
I need help adding a score board to a simple pong game can anyone help?
danpost danpost

2019/1/16

#
Josh123 wrote...
I need help adding a score board to a simple pong game can anyone help?
Are you needing a running game score (or scores) or an end game high score board?
Josh123 Josh123

2019/1/16

#
danpost wrote...
Josh123 wrote...
I need help adding a score board to a simple pong game can anyone help?
Are you needing a running game score (or scores) or an end game high score board?
I need running game scores. Would I need a separate class?
danpost danpost

2019/1/16

#
Josh123 wrote...
I need running game scores. Would I need a separate class?
Not one for each score. See my Value Display Tutorial scenario.
Josh123 Josh123

2019/1/16

#
<iframe src="https://www.greenfoot.org/scenarios/22998?embed=true"></iframe>
Josh123 Josh123

2019/1/16

#
I cant figure it out i want the scoreboard on the right and in the middle but it wont work
Josh123 Josh123

2019/1/16

#
danpost wrote...
Josh123 wrote...
I need running game scores. Would I need a separate class?
Not one for each score. See my Value Display Tutorial scenario.
can u help
danpost danpost

2019/1/16

#
Just use the following in your World subclass act method:
1
showText(""+scoreA+"\n"+scoreB, getWidth()-80, getHeight()/2);
(change the name of the int fields scoreA and scoreB as needed).
Josh123 Josh123

2019/1/16

#
danpost wrote...
Just use the following in your World subclass act method:
1
showText(""+scoreA+"\n"+scoreB, getWidth()-80, getHeight()/2);
(change the name of the int fields scoreA and scoreB as needed).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
{
 
    /**
     * 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);
         
        addObject(new Paddle(1), 350, 30);
        addObject(new Paddle(2), 350, 470);
        addObject(new Ball(), 350, 250);
         
    }
}
Josh123 Josh123

2019/1/16

#
you got me confused.
danpost danpost

2019/1/17

#
Josh123 wrote...
you got me confused.
Where are your scores?
Josh123 Josh123

2019/1/17

#
danpost wrote...
Josh123 wrote...
you got me confused.
Where are your scores?
Idk im just really confused rn that is my pong world code
danpost danpost

2019/1/17

#
Josh123 wrote...
Idk im just really confused rn that is my pong world code
You need score values to display. Insert the following at line 11 above:
1
public int scoreA, scoreB;
Then insert the following between lines 25 and 26:
1
2
3
4
public void act()
{
    shotText(""+scoreA+"\n"+scoreB, getWidth()-80, getHeight()/2);
}
Now all you will need to do is increment the appropriate score field when needed.
Josh123 Josh123

2019/1/17

#
danpost wrote...
Josh123 wrote...
Idk im just really confused rn that is my pong world code
You need score values to display. Insert the following at line 11 above:
1
public int scoreA, scoreB;
Then insert the following between lines 25 and 26:
1
2
3
4
public void act()
{
    shotText(""+scoreA+"\n"+scoreB, getWidth()-80, getHeight()/2);
}
Now all you will need to do is increment the appropriate score field when needed.
Im confused this is litrally my first game just got the book online lol
danpost danpost

2019/1/17

#
Josh123 wrote...
Im confused this is litrally my first game just got the book online lol
Did you do what I suggested? It says exactly what to do. There should be no question about that (other than those pertaining to specific lines and your understanding of what they do).
There are more replies on the next page.
1
2