I am trying to make my first game in PyGame. The objective is to click on a jar (Titled "jar.png") to gain more sand. There is also text to constantly tell you how much sand you have.
I have a problem though, I need a script that makes sure when you click on "jar.png" it increases the variable sand by 1. Also, if I do find a solution to this problem, I'm not sure if the text will display the variable correctly.
My current code looks like this:
import sys, pygame
from pygame.locals import *
pygame.init()
size = width, height = 800,500
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Sand Maker (Created by - Not Really Working Lamp Productions:)")
CORNBLUE = (100,149,237)
WHITE = (255,255,255)
sand = 0
liams = 0
screen.fill (CORNBLUE)
jar = pygame.image.load("jar.png")
screen.blit(jar,(90,50))
liambutton = pygame.image.load("liam button.png")
screen.blit(liambutton,(450,50))
liamdesc = pygame.image.load("liam desc.png")
screen.blit(liamdesc,(350,50))
myfont = pygame.font.SysFont("monospace", 16)
scoretext = myfont.render("Number of sand = "+str(sand), 1, (255,255,255))
screen.blit(scoretext, (5, 10))
liamscoretext = myfont.render("Number of Liams = "+str(liams), 1, (255,255,255))
screen.blit(liamscoretext, (350, 10))
import time
while 1:
for event in pygame.event.get():
pygame.display.flip()
if event.type == pygame.QUIT:sys.exit()
while 1:
time.sleep(5)
sand = sand + 1 * liams
So, could you please provide me with an edited piece of this code that contains the function I desire. Thank you.