Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. # Defining display dimentions
  6. displayWidth = 800
  7. displayHeight = 600
  8.  
  9. # Defining colours that will be used using RGB format
  10. amazonite = (0, 204, 195)
  11. black = (0, 0, 0)
  12. blue = (0, 200, 255)
  13. red = (255, 0, 0)
  14. white = (255, 255, 255)
  15.  
  16. # Initialising the display and clock
  17. simDisplay = pygame.display.set_mode([displayWidth, displayHeight])
  18. pygame.display.set_caption("Main Menu")
  19. clock = pygame.time.Clock()
  20.  
  21. simQuit = False
  22.  
  23. currentDisplay = "Main Menu"
  24.  
  25. # Constantly looping and refreshing the screen until command to quit
  26. while not simQuit:
  27.  
  28.     click = pygame.mouse.get_pressed()
  29.  
  30.     # Assigning mouse location
  31.     mouse = pygame.mouse.get_pos()
  32.     mouse_x = mouse[0]
  33.     mouse_y = mouse[1]
  34.  
  35.     if currentDisplay == "Main Menu":
  36.  
  37.         # Checks every event to see if it is a command to quit
  38.         for event in pygame.event.get():
  39.             if click[0] == 1 and (displayWidth * 0.10) <= mouse_x <= (displayWidth * 0.45) and (displayHeight * 0.10) <= mouse_y <= (displayHeight * 0.45):
  40.                 import Collision
  41.                 currentDisplay = "Collision"
  42.             elif click[0] == 1 and (displayWidth * 0.55) <= mouse_x <= (displayWidth * 0.90) and (displayHeight * 0.10) <= mouse_y <= (displayHeight * 0.45):
  43.                 import Photoelectric_Effect
  44.                 currentDisplay = "Photoelectric Effect"
  45.             elif click[0] == 1 and (displayWidth * 0.10) <= mouse_x <= (displayWidth * 0.45) and (displayHeight * 0.55) <= mouse_y <= (displayHeight * 0.90):
  46.                 import Buoyancy
  47.                 currentDisplay = "Buoyancy"
  48.             elif click[0] == 1 and (displayWidth * 0.55) <= mouse_x <= (displayWidth * 0.90) and (displayHeight * 0.55) <= mouse_y <= (displayHeight * 0.90):
  49.                 simQuit = True
  50.  
  51.         # Drawing objects onto screen to create GUI
  52.         simDisplay.fill(white)
  53.         pygame.draw.rect(simDisplay, amazonite, ((displayWidth * 0.10), (displayHeight * 0.10), (displayWidth * 0.35), (displayHeight * 0.35)))
  54.         pygame.draw.rect(simDisplay, amazonite, ((displayWidth * 0.55), (displayHeight * 0.10), (displayWidth * 0.35), (displayHeight * 0.35)))
  55.         pygame.draw.rect(simDisplay, amazonite, ((displayWidth * 0.10), (displayHeight * 0.55), (displayWidth * 0.35), (displayHeight * 0.35)))
  56.         pygame.draw.rect(simDisplay, red, ((displayWidth * 0.55), (displayHeight * 0.55), (displayWidth * 0.35), (displayHeight * 0.35)))
  57.  
  58.         # Defining text font to be used with labels
  59.         defaultText = pygame.font.Font(None, 40)
  60.  
  61.         # Defining main menu labels
  62.         collisionLabel = defaultText.render("COLLISIONS", 1, black)
  63.         photoelectricLabel = defaultText.render("PHOTOELECTRIC", 1, black)
  64.         effectLabel = defaultText.render("EFFECT", 1, black)
  65.         buoyancyLabel = defaultText.render("BUOYANCY", 1, black)
  66.         quitLabel = defaultText.render("QUIT", 1, black)
  67.  
  68.         # Drawing labels onto screen
  69.         simDisplay.blit(collisionLabel, (displayWidth * 0.16, displayHeight * 0.25))
  70.         simDisplay.blit(photoelectricLabel, (displayWidth * 0.575, displayHeight * 0.20))
  71.         simDisplay.blit(effectLabel, (displayWidth * 0.65, displayHeight * 0.30))
  72.         simDisplay.blit(buoyancyLabel, (displayWidth * 0.175, displayHeight * 0.70))
  73.         simDisplay.blit(quitLabel, (displayWidth * 0.675, displayHeight * 0.70))
  74.  
  75.     '''elif currentDisplay == "Collision":
  76.        simDisplay.fill(white)
  77.  
  78.    elif currentDisplay == "Photoelectric Effect":
  79.        simDisplay.fill(white)
  80.  
  81.    elif currentDisplay == "Buoyancy":
  82.        simDisplay.fill(white)'''
  83.  
  84.     # Screen updates at 60 Hz
  85.     pygame.display.update()
  86.     clock.tick(60)
  87.  
  88. pygame.quit()
  89. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement