-1

I have been following a guide to make my game. However, when I try to run the program I get a syntax Error with the Class Circle and not sure why? I can't figure out the reason and I'm sure there are more issue afterward the Class Circle but can't fix it.

import pygame
from pygame.locals import *
from uagame import Window
import time
import random


def main():

    window = Window('Pong', 500, 400)
    window.set_auto_update(False)
    game = Game(window)
    game.play()
    window.close()


class Rect:

    def __init__(self, center, radius, color, window):
        self.center = center
        self.radius = radius
        self.color = color
        self.window = window

    def draw(self):
        pygame.draw.rect(self.window.get_surface(), self.color, Rect((100, 200), (20, 30))

class Circle: # Syntax Error: class Circle:: <string>, line 28, pos 5

    def __init__(self, center, radius, color, window):

        self.center = center
        self.radius = radius
        self.color = color
        self.window = window

    def draw(self):
        pygame.draw.circle(self.window.get_surface(), self.color, self.center,self.radius)

    def get_color(self):
        return self.color

    def move(self):

        window_size = (self.window.get_width() , self.window.get_height())
        for index in range(0,2):
            self.center[index] = (self.center[index] + 1) % window_size[index]

    def enlarge(self,increment):
        self.radius = self.radius + increment


class Game:

    def __init__(self, window):

        self.window = window
        self.bg_color = pygame.Color('black')
        self.fg_color = 'green'
        self.rect_color = 'green'
        self.pause_time = 0.02
        self.close_clicked = False
        self.continue_game = True
        self.circle = Ball([200,200], 20, pygame.Color(self.fg_color),window)
        self.rect = Rect([100,200], 50 , pygame.Color(self.fg_color),window)
        self.radius_increment = 5

    def play(self):

        while not self.close_clicked:
            self.handle_event()
            self.draw()
            if self.continue_game:
                self.update()
                self.decide_continue()
            time.sleep(self.pause_time)

    def handle_event(self):
        event = pygame.event.poll()
        if event.type == QUIT:
            self.close_clicked = True
        elif event.type == MOUSEBUTTONUP and self.continue_game:
            self.handle_mouse_up()

    def handle_mouse_up(self):

        self.circle.enlarge(self.radius_increment)


    def draw(self):

        self.window.clear()
        self.circle.draw()
        self.rect.draw()
        if not self.continue_game:
            self.window.set_bg_color(self.fg_color)
            self.window.clear()
        self.window.update()

    def update(self):

        self.circle.move()

    def decide_continue(self):
        pass

main()
1
  • 1
    Post the error message Commented Feb 24, 2018 at 9:17

1 Answer 1

2

Your error actually lies in the line above. See that your code is missing a parenthesis to close the rect() function. Always remember to count the parenthesis on long functions like this.

def draw(self):
    pygame.draw.rect(self.window.get_surface(), self.color, Rect((100, 200), (20, 30))) #<-
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.