Python Forum
[PyGame] arkanoid / breakout clone
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] arkanoid / breakout clone
#1
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

Attached Files

.txt   ball.txt (Size: 1.41 KB / Downloads: 191)
.txt   brick.txt (Size: 717 bytes / Downloads: 214)
.txt   main.txt (Size: 2.98 KB / Downloads: 200)
.txt   paddle.txt (Size: 506 bytes / Downloads: 187)
Reply
#2
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.
Reply
#3
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...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  breakout clone flash77 32 8,517 Mar-07-2022, 08:12 PM
Last Post: deanhystad
  breakout clone pygame flash77 2 1,778 Feb-06-2022, 06:36 PM
Last Post: flash77

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020