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

2012/10/19

PONGER

DOGGY DOGGY

2012/10/19

#
hello, im making a little pong-game, only i'm stuck right now. Im trying to place the bat on the right and left of the screen (this will help the players to protect their goals). but how do i write this code. I want the bat only to move up and down at just one place. can anyone help me with this?
limefortheworld limefortheworld

2012/10/19

#
Indeed? What progresses have you made? Have you created the bat and the ball classes? If you have done so, visit the world class that you've created. There should be a constructor with the world class name on it alongside the parenthesis (e.g. aynrandsucksworld()), and write below the super(width,height,cellsize) code
addObject(paddleclass, some x value, some y value);
Substituting x and y value for whatever you want. An x value of say 20 should suffice for the left paddle, while an x palle of width-20, where the width is whatever you put on in the super(width,...) method should suffice for the right paddle. And substitute paddleclass with whatever you named the bat class.
danpost danpost

2012/10/19

#
I would not mind seeing what you have so far for the Bat class.
DOGGY DOGGY

2012/10/20

#
Thankyou for the reply my Bat class is empty currently but my ball class had something written in it already. The code im using for the ball to stay inside the field. This is what my World class looks like so far: --------------------------------------------------------------------------------------------------------- public class Stadion extends World { private int grensLinks; private int grensRechts; private int grensBoven; private int grensBeneden; /** * Constructor for objects of class Stadion. * */ public Stadion() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(877, 541, 1); grensLinks = 97; grensRechts = getWidth() - 97; grensBoven = 70; grensBeneden = getHeight () - 70; } public boolean wereldEinde(Actor object) { if((object.getX() - (object.getImage().getWidth() / 2)) <= grensLinks || (object.getX() + (object.getImage().getWidth() / 2)) >= grensRechts) { return true; } if((object.getY() - (object.getImage().getHeight() / 2)) <= grensBoven || (object.getY() + (object.getImage().getHeight() / 2)) >= grensBeneden) { return true; } return false; } } ---------------------------------------------------------------------------------------------------------- And my Bat class is empty as i already mentioned.
Upupzealot Upupzealot

2012/10/20

#
It's a bit hard to read. Are you coding in English?
SPower SPower

2012/10/20

#
No, he's coding in dutch :)
SPower SPower

2012/10/20

#
Well, to add a Bat, do this in the constructor for Stadion:
Bat bat = new Bat();
addObject(bat, 30, getHeight() /2);
this will add it to the left of the screen, at 30 cells as x value and whatever the height of your world is, divided by 2, as y value. (if you need I can also help you in Dutch :) )
Upupzealot Upupzealot

2012/10/20

#
How did you tell? U speak dutch also?
SPower SPower

2012/10/20

#
Yes, I live in the Netherlands and Dutch is my birth language :)
Upupzealot Upupzealot

2012/10/20

#
English is difficult enough for me :-(
DOGGY DOGGY

2012/10/23

#
@SPower de 1e batje is gelukt aan de linkerkant, maar nu wil ik er ook een aan de rechterkant hebben. alleen lukt dat niet als ik eronder hetzelfde plak. Hij geeft dan aan: bat is already defined in Stadion() weet je misschien hoe ik dit kan oplossen?
SPower SPower

2012/10/23

#
For all the english people, I'm explaining what went wrong :) Eerst ff uitleggen: Je kan een object met een bepaalde naam maar 1 keer maken, je moet de volgende dus een andere naam geven. Als voorbeeld:
// je eerste:
Bat bat = new Bat();
addObject(bat, 30, getHeight() /2);
// je tweede:
Bat bat2 = new Bat();
addObject(bat2, getWidth() -31, getHeight() /2);
op deze manier wordt het batje genaamd bat2 aan de rechterkant toegevoegd, 30 pixels van de rand (je denkt zeker, waarom zeg je dan '-31'??!! nou, dat komt omdat de coordinaten vanaf 0 beginnen te tellen, dus helemaal aan de rechterkant is de breedte -1 :) ) ik hoop dat je dit begrijpt.
You need to login to post a reply.