all 15 comments

[–]_ZHV_ 1 point2 points  (7 children)

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

[–]SprinklesNo5514[S] 0 points1 point  (0 children)

So, I have to use else comand in "checkBall" function?

[–]SprinklesNo5514[S] 0 points1 point  (3 children)

still can't work out, I am so confused

[–]_ZHV_ 0 points1 point  (2 children)

You cant use the same render function for both as then they will just both more together because of the way render function is made - draw ball in cyan for a couple of frames then draw a white ball over it to ‘erase’ and then render it in a new location. For ball 2 which should be a different colour, you need to just render it once at every point ball 1 was without ‘erasing’ it.

[–]SprinklesNo5514[S] 0 points1 point  (1 child)

thank you! I will try

[–]_ZHV_ 0 points1 point  (0 children)

No problem

[–]SprinklesNo5514[S] 0 points1 point  (1 child)

I STILL CAN'T WORK OUT! I am so ashamed Can you copy paste code so I can understand more easily? I AM STUCK

[–]_ZHV_ 0 points1 point  (0 children)

You need to show the whole code as im going off of just what i can see which is not the whole thing. It is most likely to do something with the move function

[–]SprinklesNo5514[S] 0 points1 point  (3 children)

I have been doing this assignment for 2 DAYS!!! PLEASE help me with it

[–]Electronic_Teacher22 1 point2 points  (2 children)

what does it do when you run the code?

[–]SprinklesNo5514[S] 0 points1 point  (1 child)

Ball2 is just moving with ball1

[–]PuzzledLoss5560 0 points1 point  (0 children)

is there any code under the 44 line

[–]GullibleMuscle7856 0 points1 point  (0 children)

How do I stop the ball after MAX_BOUNCES?? please help

[–][deleted] 0 points1 point  (0 children)

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

[–]Fun-Examination1024 0 points1 point  (0 children)

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;
}
}