I've created a slots-type game based on a numpy grid but the code below is just a shortened example that demonstrates the problem
The issue I'm running into is with the "cost" feature that I'm trying to add, I have designed two buttons that are supposed to have the function of changing the current cost but I have a few problems that I can't solve;
The amount of winning lines is calculated after the cost button can be clicked making it so increasing cost also increases winnings for the last roll that we already know the result of.
The cost button isn't working properly and clicking either the left or right button just makes a "2" appear on top of the standard "1". It's supposed to increase and decrease the "1" instead.
import sys
import pygame as pg
pg.init()
width = 800
height = 800
lineWidth = 15
winLineWidth = 15
windowName = "Slots"
windowNameInt = 0
cost = 1
costtxt = "Cost: 1"
game_over = False
bgColor = (200, 200, 0)
lineColor = (0, 0, 180)
fontClr = (255,99,71)
triangleColor = (255, 0, 0)
winLineColor = (220, 220, 220)
tri1L = (750, 730)
tri2L = (750, 790)
tri3L = (720, 760)
tri1R = (760, 730)
tri2R = (760, 790)
tri3R = (790, 760)
screen = pg.display.set_mode((width, height))
pg.display.set_caption(windowName)
screen.fill(bgColor)
def drawPointSyst(cost) :
#(rightest point)(top point)(bottom point)
pg.draw.polygon(screen, (triangleColor), ((tri3R), (tri1R), (tri2R)))
#(leftest point)(top point)(bottom point)
pg.draw.polygon(screen, (triangleColor), ((tri3L), (tri1L), (tri2L)))
costtxt = "Cost: {}".format(cost)
myFont = pg.font.SysFont(None, 50)
textSurface = myFont.render(costtxt, True, (fontClr))
#(x,y)
screen.blit(textSurface, (560, 750))
def posCheckLeft(pos) :
x, y = pos
return 720 < x < 750 and 730 < y < 790
def posCheckRight(pos) :
x, y = pos
return 760 < x < 790 and 730 < y < 790
def game(cost) :
for event in pg.event.get() :
if event.type == pg.QUIT :
sys.exit()
if event.type == pg.MOUSEBUTTONDOWN:
pos = pg.mouse.get_pos()
print(pos)
if posCheckLeft(pos) :
print("left")
cost += 1
drawPointSyst(cost)
elif posCheckRight(pos) :
print("right")
cost += 1
drawPointSyst(cost)
pg.display.update()
drawPointSyst(cost)
while True: game(cost)