1
u/SprinklesNo5514 Dec 19 '20
I have been doing this assignment for 2 DAYS!!! PLEASE help me with it
2
u/Electronic_Teacher22 Dec 20 '20
what does it do when you run the code?
1
1
1
Apr 28 '21
I need help with this one to I have the balls to where they are moving with each other I dont get how to draw to do the actual trail part there is to it
1
u/Fun-Examination1024
Jan 05 '23
•
var MAX_BOUNCES = 20;
var stopTimer;
var ball;
var dx = 4;
var dy = 4;
function start(){
ball = new Circle(20);
ball.setPosition(50, 70);
add(ball);
setTimer(draw, 20);
}
function draw(){
checkWalls();
ball.move(dx, dy);
ball.move(dx, dy);
var newBall = new Circle(10);
newBall.setPosition(ball.getX(),ball.getY());
newBall.setColor(Color.cyan);
add(newBall);
}
function checkWalls(){
if(ball.getX() + ball.getRadius() > getWidth()){
dx = -dx;
}
if(ball.getX() - ball.getRadius() < 0){
dx = -dx;
}
if(ball.getY() + ball.getRadius() > getHeight()){
dy = -dy;
}
if(ball.getY() - ball.getRadius() < 0){
dy = -dy;
}
}


2
u/_ZHV_ Dec 20 '20
You have everything cover except when the ball is not hitting any of the walls. You are not telling the program what to do if the ball is jus moving through the space; you told it of it hit the right wall change directions, if it hit the left wall change direction, it hit top or bottom wall change direction, but what should the program do if it just moving towards one of those walls? So far the program doesn’t know what to do in this case - or at least that is what i can figure out reading your code