Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
breakout clone
#1
Hi,
I'm new to python/pygame and I'm trying to program a breakout clone.
I've got an error message: self = {Paddle} Unable to get repr for <class 'paddle.Paddle'>
I occurs in line 6 of class Paddle (super(Paddle, self).__init__()).
I'm not experienced and don't understand this error...
Please be so kind and help me...
Thanks a lot...

import pygame


class Paddle(pygame.sprite.Sprite):
    def __init__(self, playfield_rect):
        super(Paddle, self).__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)
# !/usr/bin/env python3
import pygame, random, math
from ball import Ball
from brick import Brick
from paddle import Paddle
pygame.init()
WHITE = (255, 255, 255)
DARKBLUE = (0, 0, 139)
Screen_Width = 800
Screen_Height = 600
screen = pygame.display.set_mode((Screen_Width, Screen_Height))
pygame.display.set_caption("Breakout")
pygame.mixer.init()
pygame.mixer.music.load('images/Ketsa - Holding The Line.mp3')
pygame.mixer.music.set_volume(0.7)
pygame.mixer.music.play(-1)


def main():
    try:
        paddle = Paddle(screen.get_rect())
        ball = Ball()
        score = 0
        lives = 5
        brickgroup = pygame.sprite.Group()
        brick_coord_list = [
            32, 64, 32, 96, 32, 128, 32, 160
        ]
        i = 0
        while i < len(brick_coord_list):
            brick = Brick(brick_coord_list[i], brick_coord_list[i + 1])
            brickgroup.add(brick)
            i = i + 2

        paddlegroup = pygame.sprite.Group()
        paddlegroup.add(paddle)
        ballgroup = pygame.sprite.Group()
        ballgroup.add(ball)

        all_spritesgroup = pygame.sprite.Group()
        all_spritesgroup.add(paddlegroup, ballgroup, brickgroup)

        # to control how fast the screen updates
        clock = pygame.time.Clock()
        while True:
            # Limit to 60 frames per second
            clock.tick(60)
            # update object
            lives = ball.move(lives)
            if lives == 0:
                font = pygame.font.Font(None, 74)
                text = font.render("Game over", 1, WHITE)
                screen.blit(text, (250, 300))
                pygame.display.flip()
                pygame.time.wait(3000)
                # stop the game
                return
            # check for collisions
            # ball / paddle
            if ball.collpaddle(paddlegroup):
                ball.bounce()
            # ball / brick
            for brick in brickgroup:
                if ball.collbrick(brickgroup):
                    ball.bounce()
                    score = brick.takehit(score)
                if len(brickgroup) == 0:
                    font = pygame.font.Font(None, 74)
                    text = font.render("Level complete", 1, WHITE)
                    screen.blit(text, (200, 300))
                    pygame.display.flip()
                    pygame.time.wait(3000)
                    # stop the game
                    return
                screen.fill(DARKBLUE)
                font = pygame.font.Font(None, 34)
                text = font.render("Score: " + str(score), 1, WHITE)
                screen.blit(text, (20, 10))
                text = font.render("Lives: " + str(lives), 1, WHITE)
                screen.blit(text, (650, 10))

                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        return
                    elif event.type == pygame.MOUSEMOTION:
                        paddle.update2(event.pos)
                all_spritesgroup.draw(screen)
                pygame.display.flip()
    finally:
        pygame.quit()


if __name__ == "__main__":
    main()
import math
import random, pygame
Screen_Width = 800
Screen_Height = 600


class Ball(pygame.sprite.Sprite):
    def __init__(self):
        super(Ball, self).__init__()
        self.image = pygame.image.load('images/ballblue.png').convert()
        self.rect = self.image.get_rect()
        self.rect.x = 10
        self.rect.y = 300
        self.x = self.rect.x
        self.y = self.rect.y
        # random direction of the ball
        self.dx = random.randint(4, 6)
        self.dy = random.randint(4, 6)
        if self.dx != 0:
            pass
        else:
            self.dx = 4
        if self.dy != 0:
            pass
        else:
            self.dy = 4
        self.width = 15
        self.height = 15

    def move(self, lives):
        self.x = self.x + self.dx
        self.y = self.y + self.dy

        # Check border collision
        if self.x >= Screen_Width - self.width / 2:
            self.dx = -self.dx
        if self.x <= 0:
            self.dx = -self.dx
        if self.y <= 0:
            self.dy = -self.dy
        if self.y >= Screen_Height - self.height / 2:
            self.bounce()
            lives -= 1
        return lives

    def bounce(self):
        self.dx = self.dx
        self.dy = -self.dy

    def collpaddle(self, a):
        collide = pygame.sprite.spritecollide(self, a, False)
        return collide

    def collbrick(self, a):
        collide = pygame.sprite.spritecollide(self, a, False)
        return collide
import pygame, random


class Brick(pygame.sprite.Sprite):
    def __init__(self, a, b):
        super(Brick, self).__init__()
        # random number for blue and green Brick
        randomnumber = random.randint(1, 2)
        if randomnumber == 1:
            self.image = pygame.image.load('images/greenbrick.png').convert()
        else:
            self.image = pygame.image.load('images/bluebrick.png').convert()
        self.rect = self.image.get_rect()
        self.rect.x = a
        self.rect.y = b
        self.hits = 3

    def takehit(self, score):
        # the ball has collided with *this* brick
        self.hits -= 1
        if self.hits == 0:
            self.kill()
            score += 1
        return score
Reply


Messages In This Thread
breakout clone - by flash77 - Feb-09-2022, 07:27 PM
RE: breakout clone - by deanhystad - Feb-09-2022, 08:44 PM
RE: breakout clone - by flash77 - Feb-10-2022, 06:51 PM
RE: breakout clone - by deanhystad - Feb-13-2022, 04:17 AM
RE: breakout clone - by flash77 - Feb-14-2022, 08:40 PM
RE: breakout clone - by deanhystad - Feb-15-2022, 04:38 AM
RE: breakout clone - by deanhystad - Feb-18-2022, 11:04 PM
RE: breakout clone - by flash77 - Feb-19-2022, 05:55 PM
RE: breakout clone - by deanhystad - Feb-20-2022, 03:10 PM
RE: breakout clone - by flash77 - Feb-21-2022, 05:59 PM
RE: breakout clone - by flash77 - Feb-26-2022, 04:09 PM
RE: breakout clone - by deanhystad - Feb-26-2022, 04:12 PM
RE: breakout clone - by flash77 - Feb-26-2022, 04:31 PM
RE: breakout clone - by deanhystad - Feb-26-2022, 04:35 PM
RE: breakout clone - by flash77 - Feb-26-2022, 05:05 PM
RE: breakout clone - by deanhystad - Feb-26-2022, 06:20 PM
RE: breakout clone - by flash77 - Feb-26-2022, 08:53 PM
RE: breakout clone - by deanhystad - Feb-27-2022, 05:05 AM
RE: breakout clone - by flash77 - Feb-27-2022, 10:19 AM
RE: breakout clone - by deanhystad - Feb-27-2022, 02:41 PM
RE: breakout clone - by flash77 - Feb-27-2022, 06:41 PM
RE: breakout clone - by deanhystad - Feb-28-2022, 04:21 AM
RE: breakout clone - by flash77 - Mar-02-2022, 05:26 PM
RE: breakout clone - by deanhystad - Mar-02-2022, 08:44 PM
RE: breakout clone - by deanhystad - Mar-04-2022, 09:07 PM
RE: breakout clone - by flash77 - Mar-05-2022, 10:41 AM
RE: breakout clone - by deanhystad - Mar-05-2022, 02:50 PM
RE: breakout clone - by flash77 - Mar-05-2022, 07:11 PM
RE: breakout clone - by deanhystad - Mar-05-2022, 07:37 PM
RE: breakout clone - by flash77 - Mar-06-2022, 09:03 AM
RE: breakout clone - by deanhystad - Mar-06-2022, 04:53 PM
RE: breakout clone - by flash77 - Mar-07-2022, 06:13 PM
RE: breakout clone - by deanhystad - Mar-07-2022, 08:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] little space invaders / breakout game flash77 0 1,385 Jul-24-2024, 08:56 PM
Last Post: flash77
  breakout clone pygame flash77 2 2,654 Feb-06-2022, 06:36 PM
Last Post: flash77
  [PyGame] arkanoid / breakout clone flash77 2 5,119 Feb-04-2022, 05:42 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