d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Python - Using Turtle Resources > Import Turtle
Add Reply New Topic New Poll
Member
Posts: 263
Joined: Mar 13 2018
Gold: 0.00
Nov 19 2018 01:00am
Hi.

Was hoping there was anyone here that is familiar with using turtle in python.

Need help getting multiple balls to bounce off the edge of screen and having them collide with each other.


I have my starting code that I was able to do by myself.

PM me if this is something you can help with. Thanks :)
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Nov 20 2018 11:29am
To get a circle turtle to collide with another, just do a check of: (t1, t2 are turtles)
Code
if t1.distance(t2) < collision_distance:
repel them or do whatever you need here


This post was edited by Klexmoo on Nov 20 2018 11:33am
Member
Posts: 263
Joined: Mar 13 2018
Gold: 0.00
Nov 20 2018 02:37pm
Quote (Klexmoo @ Nov 20 2018 09:29am)
To get a circle turtle to collide with another, just do a check of: (t1, t2 are turtles)
Code
if t1.distance(t2) < collision_distance:
repel them or do whatever you need here


How about setting up the width/length to make sure the ball stays inside the screen

This post was edited by RaiseIt on Nov 20 2018 02:37pm
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Nov 20 2018 03:18pm
Quote (RaiseIt @ 20 Nov 2018 22:37)
How about setting up the width/length to make sure the ball stays inside the screen


Use
Code
window_width()
and
Code
window_height()
methods on the Screen to obtain the width and height of your screen. Then you can just check if the turtle stays inside by:

Code
-width < x < width and -height < y < height


Where x and y are the turtle's current or new position after making a move. If it's the latter, you reset the turtle's position since it would be invalid.

This post was edited by Klexmoo on Nov 20 2018 03:18pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll