I am making a soccer game with four players and need to get the ball to move when they touch it. How do I do that? And if I wanted a goalie to move back and forth in front of the goal, how would I do that?
Thanks
Ball ball = (Ball) getOneIntersectingObject(Ball.class)
if (ball != null)
{
ball.setRotation(getRotation());
ball.setSpeed(speed*2); //speed is the current moving speed of the player
}private double speed = 0;
public void act()
{
if (speed > 0)
{
move(speed);
speed *= 0.98; //ball slows down on its own
if (speed < 0.1) speed = 0;
}
}
public void setSpeed(double newSpeed)
{
speed = newSpeed;
}private int direction = 1;
public void act()
{
setLocation(getX(), getY()+direction*2)
if (getY < 100 || getY > 200) direction *= -1;
}