Detecting collision in Python turtle game

This code seems to be more wishful thinking than actual programming: def is_collided_with(self, run): return self.rect.colliderect(run.rect) runner = run(10, 10, ‘my_run’) follower = follow(20, 10) if follow.is_collided_with(run): print ‘collision!’ Turtles don’t have a .rect() method. You can’t simply add a is_collided_with() method to an existing class with this def statement. There are no run() and … Read more

How do I prevent the player from moving through the walls in a maze?

Use mask collision. Draw the maze of a transparent pygame.Surface: cell_size = 40 maze = Maze() maze_surf = pygame.Surface((maze.size[0]*cell_size, maze.size[1]*cell_size), pygame.SRCALPHA) draw_maze(maze_surf, maze, 0, 0, cell_size, (196, 196, 196), 3) Crate a pygame.Mask from the Surface with pygame.mask.from_surface: maze_mask = pygame.mask.from_surface(maze_surf) Create a mask form the player: player_rect = pygame.Rect(190, 190, 20, 20) player_surf = … Read more

Java ball object doesn’t bounce off of drawn rectangles like it’s supposed to.

I finally found a edge detection system I like… Basically, the magic happens here… // Detect if we collided with any one (collision is the rectangle, bounds is us) if (collision.intersects(bounds)) { // Determine the intersect of the collision… insect = collision.intersection(bounds); // Flags… boolean vertical = false; boolean horizontal = false; boolean isLeft = … Read more