Random game for fun

I'm trying to understand why I'm getting an error
mail@pastecode.io avatar
unknown
python
2 months ago
1.8 kB
6
Indexable
Never
'''Imports'''
import pygame as pg


'''Pygame window'''
pg.init()
W = 1000
H = 800
window = pg.display.set_mode((W, H))
pg.display.set_caption('Random clicker game for me')


'''Variables'''
score = 0
font = pg.font.Font(None, 20)


'''Main cycle'''
while True:


    '''Game window'''
    window.fill((221, 221, 221))


    '''Mouse var'''
    ms_x, ms_y = pg.mouse.get_pos()
    ms_button = pg.mouse.get_pressed()
    print(ms_x, ms_y, ms_button)


    '''Exit from game'''
    keys = pg.key.get_pressed()
    if keys[pg.K_ESCAPE]:
        pg.quit()


    '''Circle under cursor when you click'''
    class circle_under_cursor():
        def __init__(self):
            self.radius = 1
            self.r,self.b,self.g = 0,0,0
        def draw_circle(self, window):
            global ms_x, ms_y
            pg.draw.circle(window, (self.r, self.b, self.g), (ms_x, ms_y), self.radius)
            self.radius += 1


            '''Color and radius'''
            if self.r<221:
                self.r+=1
                self.b+=1
                self.g+=1
                self.radius+=1
            elif self.r>=211:
                r, b, g, self.radius = 0


    '''Quit type 2 and Score+1'''
    for event in pg.event.get():

        '''quit type 2'''
        if event.type == pg.QUIT:
            pg.quit()

        '''Score+1'''
        if event.type == pg.MOUSEBUTTONDOWN:
            if event.button == 1:
                score += 1
                circle_under_cursor.draw_circle(1,window)


    '''Score text'''
    text = font.render(str(score), True, (0, 0, 0))
    text_rect = text.get_rect(center=(W // 2, H - 20))
    window.blit(text, text_rect)


    '''Window update'''
    pg.display.update()
    pg.time.delay(16)
Leave a Comment