1

Basically, I have a game in which a character drops a balloon. The character is allowed to overlap the balloon when they drop it, but as soon as they move out of the balloon's rect, they shouldn't be able to overlap it (it becomes like a barrier).

    for balloon in balloons:
        if self.rect.colliderect(balloon.rect):
            if d == 'right': 
                self.rect.right = balloon.rect.left
            if d == 'left': 
                self.rect.left = balloon.rect.right
            if d == 'forwards': 
                self.rect.bottom = balloon.rect.top
            if d == 'backwards': 
                self.rect.top = balloon.rect.bottom

If I have something like this, the character jumps out of the rect of the balloon. I was thinking I need to use some sort of boolean to check whether the overlap is allowed initially, but I'm not sure how to implement that. Any ideas?

Thanks!

sy89
  • 195
  • 2
  • 14
  • here's an idea, get the position of the balloon and check if the position of the balloon and the barrier is the same – Abhishta Gatya Nov 25 '17 at 04:36
  • maybe `ballon` should have `balloon.barrier = True/False` so you could use it to control if you can overlap balloon. – furas Nov 25 '17 at 10:47
  • you have three situations: 1. before you visit ballon first time - you can go inside and overlap. 2. you are inside balloon - you can still overlap. 3 you leave ballon - you can't overlap. You would need two variables to control it - ie. 1. visited=False, leave=False, 2.visited=True, leave=False, 3. visited=True, leave=True. – furas Nov 25 '17 at 11:04

0 Answers0