Python Forum
[PyGame] arkanoid / breakout clone - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [PyGame] arkanoid / breakout clone (/thread-36275.html)



arkanoid / breakout clone - flash77 - Feb-03-2022

Hello,
I'm trying to code an arkanoid / breakout clone.
I have to check if the ball collides with the paddle or with one of the bricks (Later I want to use spritecollide for this).

But now I've got an error message for what I need some help.

This is the error message:

Traceback (most recent call last):
File "D:/Daten/Breakout-neu/main.py", line 89, in <module>
main()
File "D:/Daten/Breakout-neu/main.py", line 23, in main
paddlegroup.add(paddle)
File "C:\Users\\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygame\sprite.py", line 361, in add
sprite.add_internal(self)
File "C:\Users\\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygame\sprite.py", line 163, in add_internal
self.__g[group] = 0
AttributeError: 'Paddle' object has no attribute '_Sprite__g'

Please have a look on my code...
(it is attached as text files because I didn't get the code snippet working...)
And please be so kind and let me know what I'm doing wrong...

Greetings, flash77


RE: arkanoid / breakout clone - BashBedlam - Feb-04-2022

Try addingsuper ().__init__()to yourclass Paddlelike this:
import pygame


class Paddle(pygame.sprite.Sprite):
    def __init__(self, playfield_rect):
        super ().__init__()
        self.image = pygame.image.load('images/ship_fertig.png').convert()
        self.rect = self.image.get_rect()
        self.rect.centerx = self.rect.x
        self.playfield_rect = playfield_rect
        self.rect.bottom = self.playfield_rect.bottom

    def update2(self, position):
        x, _ = position
        self.rect.centerx = x
        self.rect = self.rect.clamp(self.playfield_rect)
and let us know.


RE: arkanoid / breakout clone - flash77 - Feb-04-2022

Hello BashBedlam,

thanks a lot for your very good answer!!

I added super().__init__() to my paddle, ball and brick class - and the problem is solved...

Now I'm trying to check for collisions between (ball and paddle) and (ball and bricks).

Have a good evening...