def button(text, x, y, width, height, inactive_color, active_color,action = None):
cur = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
#click1 = pygame.MOUSEBUTTONDOWN()
if x + width > cur[0] > x and y+height > cur[1] > y:
pygame.draw.rect(gameDisplay, active_color, (x,y,width,height))
if click[0] == 1 and action !=None:
if action == "start": #actions define what each thing does. modify the actions for it to do different things.
game_intro()
pygame.display.update()
if action == "play":
scene1()
pygame.display.update()
if action == "next":
scene1_p2()
pygame.display.update()
if action == "next1":
scene1_p3()
pygame.display.update()
if action == "next2":
scene2()
pygame.display.update()
if action == "next3":
scene2_p2()
pygame.display.update()
else:
x + width > cur[0] > x and y+height > cur[1] > y
pygame.draw.rect(gameDisplay, inactive_color, (x,y,width,height))
text_to_button(text,black,x,y,width,height)
def game_title():
title = True
while title:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
gameDisplay.blit(opimg, [0, 0])
message_to_screen("TBN", red, -100, size='large')
pygame.draw.rect(gameDisplay, blue, (380, 500, 230, 50))
text_to_button("Press to Start", red, 450, 500, 100, 50)
mouse = pygame.mouse.get_pos()
#print(mouse)
if 380+230 > mouse[0] > 380 and 500+50 > mouse[1] > 500:
button("Press to Start",380, 500, 230, 50,blue,light_blue,"start")
'''
if event.type == pygame.KEYDOWN:
if event.key == pygame.MOUSEBUTTONDOWN:
title = False
game_intro()
'''
pygame.display.update()
def game_intro():
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
message_to_screen("Welcome to TBN", red, -100, size='large')
message_to_screen('This is a story based RPG',
black,
10)
message_to_screen('By Stephen Wang',
black,
50)
message_to_screen('Assets used not owned by me but by their respective owners.',
black,
100)
button("Play", 420, 550, 150, 50, blue, light_blue,action="play")
pygame.display.update()
def scene1():
scene1= True
mouse_click=False
while scene1 == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(black)
button("I can't hear anything...", 0,700 , 1000, 100, blue,blue,action="next")
pygame.display.update()
def scene1_p2():
scene1= True
while scene1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(black)
button("Where am I?", 0,700 , 1000, 100, blue, blue,action="next1")
pygame.display.update()
def scene1_p3():
scene1= True
while scene1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(black)
button("Slowly, I opened my eyes.", 0,700 , 1000, 100, blue, blue,action="next2")
pygame.display.update()
def scene2():
scene2 = True
while scene2:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
gameDisplay.blit(forest, [0, 0])
button("Nearby, I could hear the sounds of battle.", 0, 700, 1000, 100, blue, blue, action="next3")
pygame.display.update()
def scene2_p2():
scene2 = True
while scene2:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
gameDisplay.blit(forest, [0, 0])
button("Nearby, I could hear the sounds of battle.", 0, 700, 1000, 100, blue, blue, action="next3")
pygame.display.update()
game_title()
game_intro()
So that is the code that I have. I am currently making a choose your own adventure type game for school. Since I'm still new to Pygame, I don't know how to do the textboxes so I create a new screen for each update. I use the button as a textbox, and when it is pressed, it proceeds to the next screen. However, when I tried to add more screens in, the buttons just straight up won't function at all. Please help!