I am new to python programming and am trying to create a game for class. Every time I run the program, before the user gets to put input in the surface screen goes non responsive. What am I doing wrong?
#import modules needed import pygame, sys, time, random from pygame.locals import *
def main():
#Assigns Colors
ORANGE = (255, 127, 80) #Background
BLACK = (0, 0, 0 ) #Mountains
WHITE = (255,255,255) #Snow & Trees
BROWN = (61, 16, 16) #moose & Mountains
GREEN = (0, 153, 0) #Trees
L_BROWN=(181, 101, 29) #Tree Trunks
YELLOW =(255, 255, 204) #Sky
BLUE = (67, 111, 181) #Lake
LIME = (57, 255, 20)
#initiate modules
pygame.init()
done=False
#assign screen values and display captions
screen = pygame.display.set_mode((1000,600))
pygame.display.set_caption("Welcome To Michelle Era's Final Project - Moose Scene")
#start clock
clock=pygame.time.Clock()
fps = (60)
#Assign Variables
drink = " "
name = " "
welcome = " "
water= " "
quit = " "
i = 0
Moose_img = pygame.image.load('moose.png')
Beer_img = pygame.image.load('beer.png')
mikey_img=pygame.image.load('Mikey.jpg')
Water_img = pygame.image.load('water.png')
font = pygame.font.SysFont('Calibri',25,False,False)
text=font.render("My text", True, YELLOW)
player_num = 0
moose_num = random.randrange(1,26)
while not done:
pygame.event.pump()
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill(ORANGE) #fills background orange
#Draw Scene
def draw_mountains(screen, x,y):
pygame.draw.rect(screen, BLACK,(1,200,1000,100)) # Base of mountain
x_offset=0
while x_offset<1000:
pygame.draw.polygon(screen, WHITE, [[100+x_offset,100], [0+x_offset ,225], [200+x_offset, 225]], 0) # snow caps on mountain
pygame.draw.polygon(screen, BROWN, [[100+x_offset,120], [0+x_offset ,225], [200+x_offset, 230]], 0)
x_offset=x_offset+120#tells how many pixels to move over until you reached 1000
def draw_trees(screen, x,y):
x_offset=0
while x_offset<1000:
pygame.draw.ellipse(screen, GREEN, [27+x_offset,158,40,50], 0) #draws leaves starting at x27 to x 1000 every 50 pixels
x_offset=x_offset +50 #tells how many pixels to move over until you reached 1000
pygame.draw.line(screen,L_BROWN,[x_offset,200],[x_offset +10,250],8) #draws trunk starting at x0 to x 1000 every 50 pixels
pygame.draw.line(screen,WHITE,[x_offset,207],[x_offset +10,250],1) #draws snow starting at x0 to x 1000 every 50 pixels
x_offset=x_offset +50
def draw_lake(screen, x,y):
pygame.draw.rect(screen,BLUE, [0,300,1000,200],0)# draws the lake
pygame.draw.rect(screen,L_BROWN,[0,500,1000,100],0) #draws grass
def gameover():
screen.fill(BLACK) #fills play surface
pygame.display.flip() #updates the display
gameOverFont=pygame.font.Font('freesansbold.ttf',17)
gameOversurf = gameOverFont.render("A Big thank you to my brother Michael Era who originally painted the mural that was the inspiration for this project",True, YELLOW)
gameOverRect = gameOversurf.get_rect()
gameOverRect.midtop = (500,40)
screen.blit(gameOversurf, gameOverRect)
screen.blit(mikey_img, (200,100))
pygame.display.flip()
time.sleep(30)
draw_mountains(screen, 0,0)
draw_trees(screen,0,0)
draw_lake(screen,300,400)
screen.blit(Moose_img, (600,400))
welcome = font.render("WELCOME TO MOOSEVILLE", True, YELLOW)
screen.blit(welcome, [300,50])
pygame.display.update()
#
#GET user input
name=(input('What is your Moose named ? '))
name=font.render("I like The Name " + str(name), True, YELLOW)
draw_mountains(screen, 0,0)
draw_trees(screen,0,0)
draw_lake(screen,300,400)
screen.blit(Moose_img, (600,400))
screen.blit(name, (550, 355))
pygame.display.update()
num_game=font.render("I am thinking of a number between 1 and 25, can you guess it? ", True, LIME)
screen.blit(num_game,(25,325))
player_num=(input(" What is your guess 1 to 10: "))
player_num = font.render('You Choose The Number: ' +str(player_num), True, LIME)
screen.blit(player_num,(25,350))
pygame.display.update()
moose_num = random.randrange(1,11)
moose_num=font.render('My number choice was : ' + str(moose_num), True, LIME)
screen.blit(moose_num,(25,376))
pygame.display.update()
if player_num == moose_num:
won=font.render('You Won!!!', True, YELLOW)
screen.blit(won,(25,400))
pygame.display.update()
else:
lose=font.render('You Lose!' , True, YELLOW)
screen.blit(lose,(25,400))
pygame.display.update()
quit = input('Do you want to try again? y or n ')
if quit == "n":
gameover()
else:
done=False
pygame.quit()
main()