Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import sys
- import button
- import pygame_gui
- pygame.init()
- #setting up the window
- WIDTH, HEIGHT = 1900, 1050
- FPS = 120
- WIN = pygame.display.set_mode((WIDTH, HEIGHT))
- pygame.display.set_caption('GameStudy')
- #images
- BG = pygame.transform.scale(pygame.image.load("gamestudy.png"), (WIDTH, HEIGHT))
- login_img = pygame.image.load("loginbtn.PNG").convert_alpha()
- signup_img = pygame.image.load("signupbtn.PNG").convert_alpha()
- #buttons
- login_button = button.Button(790, 630, login_img, 0.4)
- signup_button = button.Button(790, 800, signup_img, 0.4)
- MANAGER = pygame_gui.UIManager((WIDTH, HEIGHT))
- clock = pygame.time.Clock()
- class Game():
- def __init__(self):
- self.WIN = WIN
- self.clock = pygame.time.Clock()
- self.gameStateManager = GameStateManager('Openscene')
- self.openingscene = Openscene(self.WIN, self.gameStateManager) #tells the program which scene to run
- self.loginscene = Login(self.WIN, self.gameStateManager)
- #create a dictionary of states so the program knows which state we have created to run
- self.states = {'Openscene': self.openingscene, 'loginscene': self.loginscene}
- def run(self):
- UI_REFRESH_RATE = self.clock.tick(FPS)/1000
- run = True
- while run:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- if login_button.draw(self.WIN): #when button is pressed, action becomes true and is returned, this will run, and it changes the game state
- self.gameStateManager.set_state('loginscene')
- MANAGER.process_events(event)
- MANAGER.update(UI_REFRESH_RATE)
- MANAGER.draw_ui(self.WIN)
- self.states[self.gameStateManager.get_state()].run() #gets the state from the gamestatemanager class, then checks the
- dictionary created and runs it
- pygame.display.update()
- self.clock.tick(FPS)
- class Openscene(): #login/sign up scene, where the game starts
- def __init__(self, display, gameStateManager):
- self.display = display
- self.gameStateManager = gameStateManager
- def run(self):
- self.display.blit(BG,(0,0))
- login_button.draw(self.display)
- signup_button.draw(self.display)
- class Login(): #login/sign up scene, where the game starts
- def __init__(self, display, gameStateManager):
- self.display = display
- self.gameStateManager = gameStateManager
- def run(self):
- text_input = pygame_gui.elements.UITextEntryLine(relative_rect=pygame.Rect((350, 275), (900, 50)),
- manager=MANAGER,
- object_id='#main_text_entry')
- self.display.fill('white')
- class GameStateManager:
- def __init__(self, currentstate):
- self.currentstate = currentstate
- def get_state(self): #getting the state which we are currently running
- return self.currentstate
- def set_state(self, state): #when we set the state, setting it to whatever value we put in
- self.currentstate = state
- if __name__ == '__main__':
- game = Game()
- game.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement