I am trying to make a program in Python using the Pygame Library. I want to give the pygame window information from the python command line while the window is active. Everything seems to be working but it is not drawing the Shapes to the screen and Crashes the pygame window when i try to draw to it. I can't seem to find the problem or cause for this and i've run into this problem before. The code is provided below and is messy as i'm learning. Is it possible to circumvent this or do i have to completely recreate the code.
Multithreading is an option but i am not sure how to implement it to fit my code.
import pygame
import sys
Black = 0,0,0
White = 255,255,255
Blue = 0,0,255
Red = 255,0,0
Green = 0,255,0
Commands = ["Pygame Start", "Pygame End", "Help", "Exit", "Clear Screen", "DrawMode", "Display Update"]
Types = ["Player", "Enemy"]
PlayerRect = [0,0,0,0]
DrawPlayer = False
pygame.init()
def Console():
print "Commands: ", "\n", Commands[0],"\n", Commands[1],"\n", Commands[2], "\n", Commands[3], "\n", Commands[4], "\n", Commands[5], "\n", Commands[6]
Input = raw_input("// ")
if Input == Commands[0]:
Window(True)
if Input == Commands[1]:
Window(False)
if Input == Commands[2]:
Help()
if Input == Commands[3]:
sys.exit()
if Input == Commands[4]:
pygame.draw.rect(screen,Blue,NewPlayerRect)
if Input == Commands[5]:
DrawMode()
if Input == Commands[6]:
DisplayUpdate()
def Window(Active):
if(Active == True):
global screen
screen = pygame.display.set_mode((640,480))
elif(Active == False):
pygame.display.quit()
def Help():
print "What Command Do You Need Explained?\n"
KindOfHelp = raw_input("// ")
if KindOfHelp == Commands[0]:
print("\nTurns on the Pygame Module, which opens a pygame window")
if KindOfHelp == Commands[1]:
print("\nTurns off the Pygame Module, which closes a pygame window")
if KindOfHelp == Commands[2]:
print("\nOpens the Help Screen")
def CLS():
print "\n" * 100
def DisplayUpdate():
pygame.display.update()
def DrawMode():
print "Things you are able to Create are a: ","\n", Types[0], "\n", Types[1]
Type = raw_input("What Do you Want to Create? ")
if Type == Types[0]:
PlayerPosX = int(raw_input("Where Should The Player Spawn On The X Axis? "))
PlayerPosY = int(raw_input("Where Should The Player Spawn On The Y Axis? "))
PlayerSizeX = int(raw_input("What Should The Player X Size Be?"))
PlayerSizeY = int(raw_input("What Should The Player Y Size Be?"))
PlayerRect[0] = PlayerPosX
PlayerRect[1] = PlayerPosY
PlayerRect[2] = PlayerSizeX
PlayerRect[3] = PlayerSizeY
DrawPlayer = True
while True:
X = PlayerRect[0]
Y = PlayerRect[1]
XSize = PlayerRect[2]
YSize = PlayerRect[3]
NewPlayerRect = (X,Y,XSize,YSize)
print(X,Y,XSize,YSize)
Console()