ipython notebook - Collision detection in Python -
I am currently working on a maze game which is being written in the iPython notbook. I do not have access to Pygm and therefore, scratch is being detected from the crush.
I have the ability to move the code to the player so far and there is already a grid, which is how big the playfield will be. Imported from Turtle * Def line (x1, y1, x2, y2): Pu () goto (x1, y1) pd () goto (x2, y2) pu () setup (600,600) ) Setworldcoordinates (-1, -1,11,11) range (0, n, 10, n) line (n, 0, n, 10) tracer (1) head = heading (for category) network: tracer (30 (HT) for N category (0,11) St (Fig.): Register_shape ("figur.gif") size ("figur.gif") head = title () Pu () setpos (9.5,9.5) def Turtle_up (): If head = 90: Seth (90) FD (1) DEF turtle_down (): If head = 270: Seth (270) FD (1) DEF turtle_left (): If head = 180: Seth (180) FD (1) def turtle_right (): If the head! On ((turtle_left, "left") onkey (turtle_left, "left") onkey (turtle_right, "right") on (Turtle_up, "up") onkey (0) FD (1) onkey (0) FD (1) square () square walls: Def cut (): Tracer (30) t1 = turtle () in the range t1.color ("green") t1.left (180) t1.fd (1) t1.right (90) t1.fd (for i) 11) (1,4): for i in t1.right range (1,3) (90) t 1. fd (12): in range (1,5) i for t1.right (90) t1 Fd (1) t1.left (90): t1.fd (10) t1 Wright (90) walls Tartle () Tracer (1) updated ()
There are currently no walls around. I just started on them and tried to make a wall around the competitive playfield, as a result the hole area was covered in green. I have made a picture of a turtle myself, but I think it should work without it and take regular turtle instead.
So my main question is: How can I know the control for my turtle so it can not go through the walls?
I set a This is probably not the most efficient solution, but it works! set of Vec2D s already This is a simple and backward side function: Compare no_collision_forward (volume, wall): movement = 1 if abs () Zodiac) == Amount Other -1 # If the amount is negative, then in the range below (abdomen): cur_pos = position (nex_pos = Vec2p (cur_pos [0], cur_pos [1] + movement) if in the walls Nex_pos: no_collision_backward defer (movement) def (amount: return #) whatever else Returns can be returned, walls): return should be a set of no_collision_forward (-meter, walls) visited_locations Vec2D s or tuples .
Comments
Post a Comment