Apr-12-2019, 01:50 AM
I am making a game which is so far good, but after the player fills in all the info, it doesn't display the buttons. The shell is in typable mode (Can't type commands). I don't know how to fix it can someone please tell me what I'm doing wrong. Thx
The Button Func on line 58 and executed on lines 96 and 97 inside Game_Func
The Button Func on line 58 and executed on lines 96 and 97 inside Game_Func
import pygame
import random
import time
pygame.init()
#GameData
signInList = {'Sheepposu' : 'rachl032078', 'gg' : 'rachl1979'}
#Variables
#Colors
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
darker_red = (200,0,0)
green = (0,255,0)
blue = (0,0,255)
CustomColor1 = (48,150,140)
CustomColor2 = (36,112.5,105)
Unique_Color = (190,140,210)
ColorList = [black, red, green, blue]
Confirm = True
#Game Config
display_width = 1000
display_height = 800
pd = pygame.display
gD = pygame.display.set_mode((display_width,display_height))
fps = 100
pd.set_caption('Game')
clock = pygame.time.Clock()
gD.fill(blue)
clock.tick(fps)
pygame.display.update()
#functions
def SignIn():
global signInList
username = input('(Type "new" for new player) Username: ')
if username == 'new':
newUsername = input('Type your Username: ')
newPassword = input('Type your Password: ')
signInList = {'Sheepposu' : 'rachl032078',
newUsername : newPassword}
Game_Func(username)
else:
if username in signInList:
password = input('Please type your password: ')
if password == signInList[username]:
Game_Func(username)
else:
print('Invalid Username')
SignIn()
def Button(Butx, Buty, Butx2, Buty2, Butcolor, ShadowColor, text, textsize, textcolor, textFont, command=None, command2=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
smallText = pygame.font.SysFont(textFont, textsize)
textSurf, textRect = text_objects(text, smallText)
textRect.center = ((Butx + (Butx2/2)), Buty + (Buty2/2))
pygame.draw.rect(gD, Butcolor, (Butx, Buty, Butx2, Buty2))
gD.blit(textSurf, textRect)
if Butx + Butx2 > mouse[0] > Butx and Buty + Buty2 > mouse[1] > Buty:
pygame.draw.rect(gD, ShadowColor, (Butx, Buty, Butx2, Buty2))
gD.blit(textSurf, textRect)
if click[0] == 1:
if command != None:
command()
if command2 != None:
command2()
else:
pygame.draw.rect(gD, Butcolor, (Butx, Buty, Butx2, Buty2))
gD.blit(textSurf, textRect)
pygame.display.update()
def message_display(text, size, centerX, centerY):
font = pygame.font.SysFont('arial', size)
textSurf, TextRect = text_objects(text, font)
TextRect.center = ((centerX),(centerY))
gD.blit(textSurf, TextRect)
pygame.display.update()
def text_objects(text, font):
textSurface = font.render(text, True, Unique_Color)
return textSurface, textSurface.get_rect()
def Game_Func(username):
global Confirm
while Confirm:
gD.fill(blue)
message_display('You\'re %s, correct?' %username, round(display_width/17), round(display_width/2), display_height * .25)
Button(round(display_width * .3), round(display_height * .7), round(display_width * .4), round(display_height * .2), CustomColor1, CustomColor2, 'Confirm!', round(display_width/20), blue, 'arial', Game_Func2)
Button(round(display_width * .75), round(display_height * .8), round(display_width * .2), round(display_height * .1), red, darker_red, "No!", round(display_width/50), blue, 'arial', SignIn)
clock.tick(15)
def Game_Func2():
global Confirm
Confirm = False
End_Game()
def End_Game():
print(signInList)
message_display('Please fill in info on the console', round(display_width/20), round(display_width/2), round(display_height/2))
SignIn()
