Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- # Defining display dimentions
- displayWidth = 800
- displayHeight = 600
- # Defining colours that will be used using RGB format
- amazonite = (0, 204, 195)
- black = (0, 0, 0)
- blue = (0, 200, 255)
- red = (255, 0, 0)
- white = (255, 255, 255)
- # Initialising the display and clock
- simDisplay = pygame.display.set_mode([displayWidth, displayHeight])
- pygame.display.set_caption("Main Menu")
- clock = pygame.time.Clock()
- simQuit = False
- currentDisplay = "Main Menu"
- # Constantly looping and refreshing the screen until command to quit
- while not simQuit:
- click = pygame.mouse.get_pressed()
- # Assigning mouse location
- mouse = pygame.mouse.get_pos()
- mouse_x = mouse[0]
- mouse_y = mouse[1]
- if currentDisplay == "Main Menu":
- # Checks every event to see if it is a command to quit
- for event in pygame.event.get():
- if click[0] == 1 and (displayWidth * 0.10) <= mouse_x <= (displayWidth * 0.45) and (displayHeight * 0.10) <= mouse_y <= (displayHeight * 0.45):
- import Collision
- currentDisplay = "Collision"
- elif click[0] == 1 and (displayWidth * 0.55) <= mouse_x <= (displayWidth * 0.90) and (displayHeight * 0.10) <= mouse_y <= (displayHeight * 0.45):
- import Photoelectric_Effect
- currentDisplay = "Photoelectric Effect"
- elif click[0] == 1 and (displayWidth * 0.10) <= mouse_x <= (displayWidth * 0.45) and (displayHeight * 0.55) <= mouse_y <= (displayHeight * 0.90):
- import Buoyancy
- currentDisplay = "Buoyancy"
- elif click[0] == 1 and (displayWidth * 0.55) <= mouse_x <= (displayWidth * 0.90) and (displayHeight * 0.55) <= mouse_y <= (displayHeight * 0.90):
- simQuit = True
- # Drawing objects onto screen to create GUI
- simDisplay.fill(white)
- pygame.draw.rect(simDisplay, amazonite, ((displayWidth * 0.10), (displayHeight * 0.10), (displayWidth * 0.35), (displayHeight * 0.35)))
- pygame.draw.rect(simDisplay, amazonite, ((displayWidth * 0.55), (displayHeight * 0.10), (displayWidth * 0.35), (displayHeight * 0.35)))
- pygame.draw.rect(simDisplay, amazonite, ((displayWidth * 0.10), (displayHeight * 0.55), (displayWidth * 0.35), (displayHeight * 0.35)))
- pygame.draw.rect(simDisplay, red, ((displayWidth * 0.55), (displayHeight * 0.55), (displayWidth * 0.35), (displayHeight * 0.35)))
- # Defining text font to be used with labels
- defaultText = pygame.font.Font(None, 40)
- # Defining main menu labels
- collisionLabel = defaultText.render("COLLISIONS", 1, black)
- photoelectricLabel = defaultText.render("PHOTOELECTRIC", 1, black)
- effectLabel = defaultText.render("EFFECT", 1, black)
- buoyancyLabel = defaultText.render("BUOYANCY", 1, black)
- quitLabel = defaultText.render("QUIT", 1, black)
- # Drawing labels onto screen
- simDisplay.blit(collisionLabel, (displayWidth * 0.16, displayHeight * 0.25))
- simDisplay.blit(photoelectricLabel, (displayWidth * 0.575, displayHeight * 0.20))
- simDisplay.blit(effectLabel, (displayWidth * 0.65, displayHeight * 0.30))
- simDisplay.blit(buoyancyLabel, (displayWidth * 0.175, displayHeight * 0.70))
- simDisplay.blit(quitLabel, (displayWidth * 0.675, displayHeight * 0.70))
- '''elif currentDisplay == "Collision":
- simDisplay.fill(white)
- elif currentDisplay == "Photoelectric Effect":
- simDisplay.fill(white)
- elif currentDisplay == "Buoyancy":
- simDisplay.fill(white)'''
- # Screen updates at 60 Hz
- pygame.display.update()
- clock.tick(60)
- pygame.quit()
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement