I am developing an idle clicker game for a school project. There's a button that you can click on to upgrade your clicking power, but the rectangle assigned to it is in the wrong place. The button's rectangle is not on the button itself. Here is some of the code.
import pygame
pygame.init()
pygame.font.init()
screen = pygame.display.set_mode((800, 600))
clickimage = pygame.image.load('block.png')
button = pygame.image.load('button.png')
boxclip = clickimage.get_rect()
buttonclip = button.get_rect()
myfont = pygame.font.SysFont('Comic Sans MS', 50)
coins = 0
cost = 15
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if pygame.mouse.get_pressed()[0] and boxclip.collidepoint(pygame.mouse.get_pos()):
coins = coins+1
if pygame.mouse.get_pressed()[0] and buttonclip.collidepoint(pygame.mouse.get_pos()):
coins = coins-cost
screen.fill((255, 255, 255))
screen.blit(clickimage, (50, 50))
screen.blit(button, (500, 50))
coindisplay = myfont.render(f'Coins: {coins}', False, (0, 0, 0))
costdisplay = myfont.render(f'Cost: {cost}', False, (0, 0, 0))
screen.blit(coindisplay, (50, 310))
screen.blit(costdisplay, (500, 200))
pygame.display.update()
I assigned the button's rectangle to the button but it's for some reason overlapping the clickimage. Why is this happening?