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

2020/2/28

How do you add 1 point every time an actor touches instead of it rapidly adding points while it's already touching?

Adrian2004 Adrian2004

2020/2/28

#
public int score = 0; public void act() { int counter = 0; counter += 1; int speed = 3; if (Greenfoot.isKeyDown("Up")) { setLocation(getX(), getY() - speed); } if (Greenfoot.isKeyDown("Down")) { setLocation(getX(), getY() + speed); } if (Greenfoot.isKeyDown("Left")) { setLocation(getX() - speed, getY()); } if (Greenfoot.isKeyDown("Right")) { setLocation(getX() + speed, getY()); } if (isTouching(Point.class)) { score = score + 1; System.out.println(score); } } } This is my actor class for my actor that requires contact with a point to add 1 to the score. But I want it to only add 1 point instead of it rapidly increasing the score. Anyone know how to fix?
footpickle footpickle

2020/2/28

#
you could remove what is giving the points?
footpickle footpickle

2020/2/28

#
otherwise I don't know.
danpost danpost

2020/2/28

#
Add a field to contain a Point object and set it to any touching Point object. Also, set it to null if not touching any Point object. Only score if field does not contain the Point object it currently touches.
You need to login to post a reply.