I recently wrote a command line program for random dice rolls for the various types of D&D dice, and I want to turn it into a basic GUI next.
I've got the below image worked out using Pygame-Menu library, and I also have functions which return a random dice roll for each button.
But how do I get the result of the dice rolls displayed on a surface on the screen?
I tried reading the library documentation but I didn't see anything on this topic that I understood.
I also tried to blit a text rect surface onto the screen but it didn't seem to work either.
Is anyone familiar with this particular Pygame library who can assist?
import random
import pygame
import pygame_menu
screen_width = 320
screen_height = 520
done = False
White = (255,255,255)
Grey = (179,179,179)
Black = (17,17,17)
Green = (30,215,96)
pygame.init()
pygame.display.set_caption('Dungeon Dice')
FPS = 60
screen = pygame.display.set_mode((screen_width, screen_height))
width = screen.get_width()
height = screen.get_height()
rollsound = pygame.mixer.Sound("roll.mp3")
mouse = pygame.mouse.get_pos()
font = pygame.font.SysFont('Calibri', 48)
screen.fill(Black)
def rolld20():
d20output = random.randint(1,20)
pygame.mixer.Sound.play(rollsound)
return(d20output)
def rolld12():
d12output = random.randint(1,12)
pygame.mixer.Sound.play(rollsound)
return(d12output)
def rolld10():
d10output = random.randint(1,10)
pygame.mixer.Sound.play(rollsound)
return(d10output)
def rolld8():
d8output = random.randint(1,8)
pygame.mixer.Sound.play(rollsound)
return(d8output)
def rolld6():
d6output = random.randint(1,6)
pygame.mixer.Sound.play(rollsound)
return(d6output)
def rolld4():
d4output = random.randint(1,4)
pygame.mixer.Sound.play(rollsound)
return(d4output)
def rolld100():
d100output = random.randint(1,100)
pygame.mixer.Sound.play(rollsound)
return(d100output)
menu = pygame_menu.Menu('Dungeon Dice', screen_width, screen_height, theme=pygame_menu.themes.THEME_DEFAULT)
menu.add.button('D4', rolld4)
menu.add.button('D6', rolld6)
menu.add.button('D8', rolld8)
menu.add.button('D10', rolld10)
menu.add.button('D12', rolld12)
menu.add.button('D20', rolld20)
menu.add.button('D100', rolld100)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(screen)