Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How do I make a program so that when 2 circles touch the bigger circle is removed and the program resets

Henry1218

New Coder
When "circ" which follows your cursor touches the other circle i need to to remove the circle and create another circle that moves the same as the previous one
this is my code so far

var circle = new Circle(7);

var circ;
var dx = Randomizer.nextInt(-10,10);
var dy = Randomizer.nextInt(-10,10);




function start(){
mouseClickMethod(start);
circ = new Circle(20);
circ.setPosition(Randomizer.nextInt(0,400), Randomizer.nextInt(0,400));

add(circ);

setTimer(draw, 20);

mouseMoveMethod(paint);


}


function draw(){
checkWalls();
mouseClickMethod(circ.move(dx, dy));

}

function checkWalls(){
// Bounce off right wall
if(circ.getX() > getWidth()){
dx = -dx;
}

// Bounce off left wall
if(circ.getX() < 0){
dx = -dx;
}

// Bounce off bottom wall
if(circ.getY() > getHeight()){
dy = -dy;
}

// Bounce off top wall
if(circ.getY() < 0){
dy = -dy;
}
}


function ball1(){
mouseClickMethod(functionToCall);
}




function paint(e){
mouseMoveMethod(paint);
circle.setPosition(e.getX(), e.getY());
circle.setColor("red");
add(circle);
}
 
When you do repost your code, look at it first and correct errors.
At the end
Code:
 }>Cancel</button>
I also think you need to add more info because If I run your code nothing happens. Are you use "canvas" in the HTML/CSS that is not here?
 
When you do repost your code, look at it first and correct errors.
At the end
Code:
 }>Cancel</button>
I also think you need to add more info because If I run your code nothing happens. Are you use "canvas" in the HTML/CSS that is not here?
Where do you see that ? I see only JS in the user's post.
I agree that people should post complete code, not snippets. At least something that others can just pick up and run without having to massage it.
<rant>And people should learn to validate their HTML online, and look for script errors in the console.</rant>
 
Back
Top Bottom