import pygame import sys import json import time from classes import * from viecher import * fps = 60 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() quit() def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): objects = [] objects.append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) while running: screen.fill('#000000') events = pygame.event.get() for event in events: if event.type == pygame.QUIT: quitGame() # 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.update(pygame.key.get_pressed()) obj.draw(screen) # flip() the display to put your work on screen pygame.display.flip() clock.tick(fps) # limits FPS to 60 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, 160, 64, 'medieval', 48, "Play", play)) #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Options", uwu)) objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False quitGame() # RENDER YOUR GAME HERE with open(f'art/images/{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, clock, running, background, isblack, WIDTH, HEIGHT) # 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() #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", play)) #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, "Exit game", quitGame)) menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) """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: for obj in objects: obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) # 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()