[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Working with maps
Timothy Baldock (tb@xxxxxxxxxxxxx) wrote:
> http://www.pygame.org/project-pyTile-871-.html
>
> This is the game engine I was working on, the code in question is in
> the tools.py file, e.g. collide_locate() function of the Tool
> object, which uses the MouseSprite object as the "invisible" sprite.
> You pass in a sprite group to test against and the cursor position.
>
> def collide_locate(self, mousepos, collideagainst):
> """Locates the sprite(s) that the mouse position intersects with"""
> # Draw mouseSprite at cursor position
> if self.mouseSprite:
> self.mouseSprite.sprite.update(mousepos)
> else:
> self.mouseSprite = pygame.sprite.GroupSingle(
> MouseSprite(mousepos))
> # Find sprites that the mouseSprite intersects with
> collision_list1 = pygame.sprite.spritecollide(
> self.mouseSprite.sprite, collideagainst, False)
> if collision_list1:
> collision_list = pygame.sprite.spritecollide(
> self.mouseSprite.sprite, collision_list1, False, pygame.sprite.collide_mask)
> if collision_list:
> collision_list.reverse()
> for t in collision_list:
> if t.exclude == False:
> return t
> return None
> else:
> # No collision means nothing to select
> return None
> else:
> return None
Very useful!
Thank you!
--
Regards,
Kenny Meyer