forked from InfoProjekt/game
		
	
		
			
				
	
	
		
			126 lines
		
	
	
	
		
			4.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			126 lines
		
	
	
	
		
			4.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import pygame
 | |
| import sys
 | |
| import json
 | |
| import time
 | |
| from classes import *
 | |
| 
 | |
| def setUp(config):
 | |
|     pygame.init()
 | |
|     if config["fullscreen"]:
 | |
|         screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN)
 | |
|     else:
 | |
|         screen = pygame.display.set_mode(config["res"])
 | |
|     clock = pygame.time.Clock()
 | |
|     
 | |
|     return screen, clock, True, True, "start.png", []
 | |
| 
 | |
| def readConfig():
 | |
|     with open('config.json', 'r') as c:
 | |
|         json_data = c.read()
 | |
|     return json.loads(json_data)
 | |
| 
 | |
| def quitGame():
 | |
|     #save progress somehow, if needed
 | |
|     pygame.quit()
 | |
|     sys.exit()
 | |
| 
 | |
| def uwu():
 | |
|     print('uwu')
 | |
| 
 | |
| def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
 | |
|     objects = []
 | |
|     # List that is displayed while selecting the window resolution level 
 | |
|     resolution = [("1920x1080", "1920x1080"), 
 | |
|                   ("1920x1200", "1920x1200"), 
 | |
|                   ("1280x720", "1280x720"), 
 | |
|                   ("2560x1440", "2560x1440"), 
 | |
|                   ("3840x2160", "3840x2160")]
 | |
|     
 | |
|     # This function displays the currently selected options 
 | |
| 
 | |
|     def printSettings(): 
 | |
|         print("\n\n") 
 | |
|         # getting the data using "get_input_data" method of the Menu class 
 | |
|         settingsData = settings.get_input_data() 
 | |
| 
 | |
|         for key in settingsData.keys(): 
 | |
|             print(f"{key}\t:\t{settingsData[key]}") 
 | |
|     
 | |
|     while running:
 | |
|         for event in pygame.event.get():
 | |
|             if event.type == pygame.QUIT:
 | |
|                 running = False 
 | |
|         # RENDER YOUR GAME HERE
 | |
|         with open(background, 'r') as i:
 | |
|             bg = pygame.image.load(i)
 | |
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
 | |
|         # fill the screen with an image to clear the screen
 | |
|         screen.blit(bg, (0, 0))
 | |
|         for obj in objects:
 | |
|             obj.process(screen)
 | |
| 
 | |
|         # flip() the display to put your work on screen
 | |
|         pygame.display.flip()
 | |
| 
 | |
|         clock.tick(60)  # limits FPS to 60
 | |
| 
 | |
| def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
 | |
|     objects = []
 | |
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame))
 | |
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu))
 | |
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", uwu))
 | |
|     while running:
 | |
|         for event in pygame.event.get():
 | |
|             if event.type == pygame.QUIT:
 | |
|                 running = False 
 | |
|         # RENDER YOUR GAME HERE
 | |
|         with open(background, 'r') as i:
 | |
|             bg = pygame.image.load(i)
 | |
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
 | |
|         # fill the screen with an image to clear the screen
 | |
|         screen.blit(bg, (0, 0))
 | |
|         for obj in objects:
 | |
|             obj.process(screen)
 | |
| 
 | |
|         # flip() the display to put your work on screen
 | |
|         pygame.display.flip()
 | |
| 
 | |
|         clock.tick(60)  # limits FPS to 60
 | |
| 
 | |
| def main():
 | |
|     config = readConfig()
 | |
|     screen, clock, running, isblack, background, objects = setUp(config["screen"])
 | |
|     WIDTH, HEIGHT = screen.get_size()
 | |
|     list1 = DropDown(50, 50, 128, 48, 'simple', 32, ['#881188', '#220044'], ['#991122', '#33ff11'], 'Test', ['Test 2', 'Test 17', '982'])
 | |
|     
 | |
|     while running:
 | |
|         for event in pygame.event.get():
 | |
|             if event.type == pygame.QUIT:
 | |
|                 running = False 
 | |
|         #menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
 | |
|         if not isblack:
 | |
|             with open(background, 'r') as i:
 | |
|                 bg = pygame.image.load(i)
 | |
|                 bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
 | |
|             # fill the screen with a color to wipe away anything from last frame
 | |
|             screen.blit(bg, (0, 0))
 | |
| 
 | |
|         # RENDER YOUR GAME HERE
 | |
| 
 | |
|         else:
 | |
|             selected_option = list1.update(pygame.event.get())
 | |
|             if selected_option >= 0:
 | |
|                 list1.main = list1.options[selected_option]
 | |
|             screen.fill('#000000')
 | |
|             list1.draw(screen)
 | |
|             for obj in objects:
 | |
|                 obj.process(screen)
 | |
|         # flip() the display to put your work on screen
 | |
|         pygame.display.flip()
 | |
| 
 | |
|         clock.tick(60)  # limits FPS to 60
 | |
| 
 | |
|     pygame.quit()
 | |
| 
 | |
| if __name__ == '__main__':
 | |
|     main()
 | 
