Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to right realize Sonic "Landing"?

I almost created the first game in Python, so I correct shortcomings. I added part of code in function def update(self) to improve Sonic Landing. the program shows error. What’s wrong?

class Player(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        #[...]

    def update(self):
        hits_4 = pygame.sprite.collide_rect(player, platform4)
            if self.vel.y > 0:        
                if hits_4:
                    if self.pos.y < hits_4[0].rect.bottom:               
                        self.pos.y = hits_4[0].rect.top +1
                        self.vel.y = 0
    def jump(self):
        hits4 = pygame.sprite.collide_rect(self, platform4)
        if hits4:
            self.vel.y = -15 // 2

*Platform4 isn’t iterable sprite.
Error: File "C:\Users\дом\My project\Survival_with_Sonic.py", line 149, in update if self.pos.y < hits_4[0].rect.bottom: TypeError: 'bool' object is not subscriptable

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

pygame.sprite.collide_rect returns True or False:

if pygame.sprite.collide_rect(player, platform4):
    if 0 < self.pos.y < platform4.rect.bottom:               
        self.pos.y = platform4.rect.top +1
        self.vel.y = 0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading