Apr-17-2020, 01:58 AM
(This post was last modified: Apr-17-2020, 02:11 AM by CrazyMakes.)
# i am trying to follow pep 8 here # importing stuff import pygame import time # initializing pygame pygame.init() # defining variables autog = 0 coins = 0 display_width = 800 display_height = 600 white = (255, 255, 255) black = (0, 0, 0) grey = (128, 128, 128) light_grey = (224, 224, 224) # creating display and caption gameDisplay = pygame.display.set_mode((display_width, display_height)) pygame.display.set_caption("clicky clicks") # defining functions def DrawText(text, Textcolor, Rectcolor, x, y, fsize): font = pygame.font.Font('freesansbold.ttf', fsize) text = font.render(text, True, Textcolor, Rectcolor) textRect = text.get_rect() textRect.center = (x, y) gameDisplay.blit(text, textRect) def rectangle(display, color, x, y, w, h): pygame.draw.rect(display, color, (x, y, w, h)) def main_loop(): global autog tc = 0 mong = 1 cost = 50 cost2 = 50 global coins game_running = True while game_running: for event in pygame.event.get(): if event.type == pygame.QUIT: game_running = False if event.type == pygame.MOUSEBUTTONDOWN: tc += 1 print(tc) mopos = pygame.mouse.get_pos() if mopos >= (350, 0): if mopos <= (450, 0): print("button clicked 1") coins += mong if mopos <= (800, 0): if mopos >= (600, 0): print("button clicked 2") if coins >= cost: coins = coins - cost cost = cost * 2 mong += 3 if mopos >= (50, 0): if mopos <= (245, 0): print("button clicked 3") if coins >= cost2: coins = coins - cost2 cost2 = cost2 * 2 autog += 1 while True: time.sleep(0.5) coins = coins + autog # drawing stuff gameDisplay.fill(white) DrawText("Clicky Clicks", black, white, 400, 100, 50) DrawText("you have " + str(coins) + " coins", black, white, 100, 50, 20) DrawText("upgrade 50*2", black, light_grey, 700, 300, 20) DrawText("buy auto miner 50*2", black, light_grey, 150, 370, 20) rectangle(gameDisplay, light_grey, 50, 400, 200, 300) rectangle(gameDisplay, black, 350, 250, 100, 100) rectangle(gameDisplay, light_grey, 600, 317, 200, 300) pygame.display.update() # ending the program main_loop() pygame.quit() quit()So I have 2 problems 1 is that when I made my buttons they had a problem that when I clicked above or below the buttons they still activated. my second problem was with this code while True:
time.sleep(0.5)
coins = coins + autog this code is in button 3 and it crashes the program when I click the button
I just realized i posted this in the wrong thread is there a way to change which thread this is on
~~ UwU