forked from InfoProjekt/game
		
	Update main.py
This commit is contained in:
		
							parent
							
								
									d08274c2f6
								
							
						
					
					
						commit
						a35dcfb823
					
				
					 1 changed files with 414 additions and 411 deletions
				
			
		
							
								
								
									
										825
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										825
									
								
								main.py
									
										
									
									
									
								
							|  | @ -1,411 +1,414 @@ | ||||||
| import pygame | import pygame | ||||||
| import sys | import sys | ||||||
| import json | import json | ||||||
| import time | import time | ||||||
| import random | import random | ||||||
| from classes import * | from classes import * | ||||||
| from viecher import * | from viecher import * | ||||||
| fps = 60 | from pygame import mixer | ||||||
| 
 | fps = 60 | ||||||
| def setUp(config): | 
 | ||||||
|     pygame.init() | def setUp(config): | ||||||
|     if config["fullscreen"]: |     pygame.init() | ||||||
|         screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN) |     mixer.music.load('audio/music/thebritons(1.1).mp3') | ||||||
|     else: |     mixer.music.play(-1) | ||||||
|         screen = pygame.display.set_mode(config["res"]) |     if config["fullscreen"]: | ||||||
|     clock = pygame.time.Clock() |         screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN) | ||||||
|     pygame.display.set_caption('Between The Pages') |     else: | ||||||
|     with open('art/images/icon.png', 'r') as i: |         screen = pygame.display.set_mode(config["res"]) | ||||||
|         pygame.display.set_icon(pygame.image.load(i)) |     clock = pygame.time.Clock() | ||||||
|     return screen, clock, True, True, "startscreen.png", [] |     pygame.display.set_caption('Between The Pages') | ||||||
| 
 |     with open('art/images/icon.png', 'r') as i: | ||||||
| def readConfig(): |         pygame.display.set_icon(pygame.image.load(i)) | ||||||
|     with open('config.json', 'r') as c: |     return screen, clock, True, True, "startscreen.png", [] | ||||||
|         json_data = c.read() | 
 | ||||||
|     return json.loads(json_data) | def readConfig(): | ||||||
| 
 |     with open('config.json', 'r') as c: | ||||||
| def quitGame(): |         json_data = c.read() | ||||||
|     #save progress somehow, if needed |     return json.loads(json_data) | ||||||
|     pygame.quit() | 
 | ||||||
|     quit() | def quitGame(): | ||||||
| 
 |     #save progress somehow, if needed | ||||||
| def genRooms(WIDTH, HEIGHT, type:str, objects:list): |     pygame.quit() | ||||||
|     room_objects = [] |     quit() | ||||||
|     #room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)] | 
 | ||||||
|     room_objects.append(Obstacle('river', 'water', 'art/images/background/river.png', True, random.randint(32, round(WIDTH * 0.75)), 32, WIDTH=96, HEIGHT=round(HEIGHT * 0.66))) | def genRooms(WIDTH, HEIGHT, type:str, objects:list): | ||||||
|     room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)] |     room_objects = [] | ||||||
|     rooms = [ |     #room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)] | ||||||
|         Room(type, 'normal', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, j) |     room_objects.append(Obstacle('river', 'water', 'art/images/background/river.png', True, random.randint(32, round(WIDTH * 0.75)), 32, WIDTH=96, HEIGHT=round(HEIGHT * 0.66))) | ||||||
|         for j in range(random.randint(5, 10)) |     room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)] | ||||||
|     ] |     rooms = [ | ||||||
|     rooms.append(Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88)) |         Room(type, 'normal', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, j) | ||||||
|     #rooms =Room(type, 'normal', room_backgrounds[random.randint(0, 4)], [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j) |         for j in range(random.randint(5, 10)) | ||||||
|      |     ] | ||||||
|     return rooms |     rooms.append(Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88)) | ||||||
|          |     #rooms =Room(type, 'normal', room_backgrounds[random.randint(0, 4)], [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j) | ||||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): |      | ||||||
|     main = [herbert] |     return rooms | ||||||
|     mobs = [Skeleton('skeleton', random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 5))]+[Zombie('zombie', random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 25) for i in range(0,random.randint(2, 5))] |          | ||||||
|     weapons = [] | def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     others = [] |     main = [herbert] | ||||||
|     npcs = [] |     mobs = [Skeleton('skeleton', random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 5))]+[Zombie('zombie', random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 25) for i in range(0,random.randint(2, 5))] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     weapons = [] | ||||||
|     level = [] |     others = [] | ||||||
|     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) |     npcs = [] | ||||||
|     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) |     objects = [main, mobs, npcs, weapons, others] | ||||||
|     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) |     level = [] | ||||||
|     freeze = False #Gameplay is freezed in certain situations |     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) | ||||||
| 
 |     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) | ||||||
|     while running: |     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) | ||||||
|         screen.fill('#000000') |     freeze = False #Gameplay is freezed in certain situations | ||||||
|         events = pygame.event.get() | 
 | ||||||
|         for event in events: |     while running: | ||||||
|             if event.type == pygame.QUIT: |         screen.fill('#000000') | ||||||
|                 quitGame() |         events = pygame.event.get() | ||||||
|             elif event.type == pygame.KEYDOWN: |         for event in events: | ||||||
|                 if event.key == pygame.K_e: #when book is open gameplay is freezed |             if event.type == pygame.QUIT: | ||||||
|                     freeze = not freeze |                 quitGame() | ||||||
|         # RENDER YOUR GAME HERE |             elif event.type == pygame.KEYDOWN: | ||||||
|         """with open(background, 'r') as i: |                 if event.key == pygame.K_e: #when book is open gameplay is freezed | ||||||
|             bg = pygame.image.load(i) |                     freeze = not freeze | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |         # RENDER YOUR GAME HERE | ||||||
|         # fill the screen with an image to clear the screen |         """with open(background, 'r') as i: | ||||||
|         screen.blit(bg, (0, 0)) |             bg = pygame.image.load(i) | ||||||
| """  |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|         if not freeze: |         # fill the screen with an image to clear the screen | ||||||
|             objects = scene.getObjects() |         screen.blit(bg, (0, 0)) | ||||||
|             screen.blit(scene.background, (32, 32)) | """  | ||||||
|          |         if not freeze: | ||||||
|             for thing in objects[4]: |             objects = scene.getObjects() | ||||||
|                 thing.draw(screen) |             screen.blit(scene.background, (32, 32)) | ||||||
| 
 |          | ||||||
|             for weapon in objects[3]: |             for thing in objects[4]: | ||||||
|                 weapon.update(objects) |                 thing.draw(screen) | ||||||
|                 weapon.draw(screen) | 
 | ||||||
|              |             for weapon in objects[3]: | ||||||
|             for thing in objects[0]: |                 weapon.update(objects) | ||||||
|                 thing.book.hidden = not freeze |                 weapon.draw(screen) | ||||||
|                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) |              | ||||||
|                 if result == 'village': |             for thing in objects[0]: | ||||||
|                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 thing.book.hidden = not freeze | ||||||
|                 elif result == 'play': |                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) | ||||||
|                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 if result == 'village': | ||||||
|                 else: |                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                     thing.draw(screen) |                 elif result == 'play': | ||||||
|          |                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|             for mob in objects[1]: |                 else: | ||||||
|                 mob.update(objects) |                     thing.draw(screen) | ||||||
|                 mob.draw(screen) |          | ||||||
|              |             for mob in objects[1]: | ||||||
|             for npc in objects[2]: |                 mob.update(objects) | ||||||
|                 npc.update(pygame.key.get_pressed(), objects) |                 mob.draw(screen) | ||||||
|                 npc.draw(screen) |              | ||||||
|              |             for npc in objects[2]: | ||||||
|             objects[0][0].book.addspell('windslash') |                 npc.update(pygame.key.get_pressed(), objects) | ||||||
|             scene.update(False, objects) |                 npc.draw(screen) | ||||||
|             scene.draw(screen) |              | ||||||
| 
 |             objects[0][0].book.addspell('windslash') | ||||||
|         else: |             scene.update(False, objects) | ||||||
|             objects[0][0].book.hidden = not freeze |             scene.draw(screen) | ||||||
|             objects[0][0].book.draw(screen) | 
 | ||||||
|             objects[0][0].book.update() |         else: | ||||||
|         # flip() the display to put your work on screen |             objects[0][0].book.hidden = not freeze | ||||||
|         pygame.display.flip() |             objects[0][0].book.draw(screen) | ||||||
| 
 |             objects[0][0].book.update() | ||||||
|         clock.tick(fps)  # limits FPS to 60 |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
| def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | 
 | ||||||
|     main = [herbert] |         clock.tick(fps)  # limits FPS to 60 | ||||||
|     mobs = [] | 
 | ||||||
|     weapons = [] | def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500), |     main = [herbert] | ||||||
|               Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] |     mobs = [] | ||||||
|     npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] |     weapons = [] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500), | ||||||
|     room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, 0) |               Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] | ||||||
|     freeze = True #Gameplay is freezed in certain situations |     npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] | ||||||
|     main[0].health.health = 20 |     objects = [main, mobs, npcs, weapons, others] | ||||||
| 
 |     room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, 0) | ||||||
|     while running: |     freeze = True #Gameplay is freezed in certain situations | ||||||
|         screen.fill('#000000') |     main[0].health.health = 20 | ||||||
|         events = pygame.event.get() | 
 | ||||||
|         for event in events: |     while running: | ||||||
|             if event.type == pygame.QUIT: |         screen.fill('#000000') | ||||||
|                 quitGame() |         events = pygame.event.get() | ||||||
|             elif event.type == pygame.KEYDOWN: |         for event in events: | ||||||
|                 if event.key == pygame.K_e: #when book is open gameplay is freezed |             if event.type == pygame.QUIT: | ||||||
|                     freeze = not freeze |                 quitGame() | ||||||
|         # RENDER YOUR GAME HERE |             elif event.type == pygame.KEYDOWN: | ||||||
|         """with open(background, 'r') as i: |                 if event.key == pygame.K_e: #when book is open gameplay is freezed | ||||||
|             bg = pygame.image.load(i) |                     freeze = not freeze | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |         # RENDER YOUR GAME HERE | ||||||
|         # fill the screen with an image to clear the screen |         """with open(background, 'r') as i: | ||||||
|         screen.blit(bg, (0, 0)) |             bg = pygame.image.load(i) | ||||||
| """  |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|         if not freeze: |         # fill the screen with an image to clear the screen | ||||||
|             objects = room.getObjects() |         screen.blit(bg, (0, 0)) | ||||||
|             screen.blit(room.background, (32, 32)) | """  | ||||||
|          |         if not freeze: | ||||||
|             for thing in objects[4]: |             objects = room.getObjects() | ||||||
|                 thing.draw(screen) |             screen.blit(room.background, (32, 32)) | ||||||
| 
 |          | ||||||
|             for weapon in objects[3]: |             for thing in objects[4]: | ||||||
|                 weapon.update(objects) |                 thing.draw(screen) | ||||||
|                 weapon.draw(screen) | 
 | ||||||
| 
 |             for weapon in objects[3]: | ||||||
|             for thing in objects[0]: |                 weapon.update(objects) | ||||||
|                 thing.book.hidden = not freeze |                 weapon.draw(screen) | ||||||
|                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) | 
 | ||||||
|                 if result == 'village': |             for thing in objects[0]: | ||||||
|                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 thing.book.hidden = not freeze | ||||||
|                 elif result == 'play': |                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) | ||||||
|                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 if result == 'village': | ||||||
|                 elif result == 'house': |                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                     house(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 elif result == 'play': | ||||||
|                 else: |                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                     thing.draw(screen) |                 elif result == 'house': | ||||||
|          |                     house(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|             for mob in objects[1]: |                 else: | ||||||
|                 mob.update(objects) |                     thing.draw(screen) | ||||||
|                 mob.draw(screen) |          | ||||||
|              |             for mob in objects[1]: | ||||||
|             for npc in objects[2]: |                 mob.update(objects) | ||||||
|                 npc.update(pygame.key.get_pressed(), objects) |                 mob.draw(screen) | ||||||
|                 npc.draw(screen) |              | ||||||
|              |             for npc in objects[2]: | ||||||
|             room.update(objects) |                 npc.update(pygame.key.get_pressed(), objects) | ||||||
| 
 |                 npc.draw(screen) | ||||||
|         else: |              | ||||||
|             objects[0][0].book.hidden = not freeze |             room.update(objects) | ||||||
|             objects[0][0].book.draw(screen) | 
 | ||||||
|             objects[0][0].book.update() |         else: | ||||||
|         # flip() the display to put your work on screen |             objects[0][0].book.hidden = not freeze | ||||||
|         pygame.display.flip() |             objects[0][0].book.draw(screen) | ||||||
| 
 |             objects[0][0].book.update() | ||||||
|         clock.tick(fps)  # limits FPS to  |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
| def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): | 
 | ||||||
|     main = [herbert] |         clock.tick(fps)  # limits FPS to  | ||||||
|     mobs = [] | 
 | ||||||
|     weapons = [] | def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     others = [] |     main = [herbert] | ||||||
|     npcs = [NPC('elder', 100, 'people/reddy.png', 0, 200, 200)] |     mobs = [] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     weapons = [] | ||||||
|     room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, 0) |     others = [] | ||||||
|     freeze = False #Gameplay is freezed in certain situations |     npcs = [NPC('elder', 100, 'people/reddy.png', 0, 200, 200)] | ||||||
| 
 |     objects = [main, mobs, npcs, weapons, others] | ||||||
|     while running: |     room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, 0) | ||||||
|         screen.fill('#000000') |     freeze = False #Gameplay is freezed in certain situations | ||||||
|         events = pygame.event.get() | 
 | ||||||
|         for event in events: |     while running: | ||||||
|             if event.type == pygame.QUIT: |         screen.fill('#000000') | ||||||
|                 quitGame() |         events = pygame.event.get() | ||||||
|             elif event.type == pygame.KEYDOWN: |         for event in events: | ||||||
|                 if event.key == pygame.K_e: #when book is open gameplay is freezed |             if event.type == pygame.QUIT: | ||||||
|                     freeze = not freeze |                 quitGame() | ||||||
|         # RENDER YOUR GAME HERE |             elif event.type == pygame.KEYDOWN: | ||||||
|         """with open(background, 'r') as i: |                 if event.key == pygame.K_e: #when book is open gameplay is freezed | ||||||
|             bg = pygame.image.load(i) |                     freeze = not freeze | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |         # RENDER YOUR GAME HERE | ||||||
|         # fill the screen with an image to clear the screen |         """with open(background, 'r') as i: | ||||||
|         screen.blit(bg, (0, 0)) |             bg = pygame.image.load(i) | ||||||
| """  |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|         if not freeze: |         # fill the screen with an image to clear the screen | ||||||
|             objects = room.getObjects() |         screen.blit(bg, (0, 0)) | ||||||
|             screen.blit(room.background, (32, 32)) | """  | ||||||
|          |         if not freeze: | ||||||
|             for thing in objects[4]: |             objects = room.getObjects() | ||||||
|                 thing.draw(screen) |             screen.blit(room.background, (32, 32)) | ||||||
| 
 |          | ||||||
|             # for weapon in objects[3]: |             for thing in objects[4]: | ||||||
|             #     weapon.update(objects) |                 thing.draw(screen) | ||||||
|             #     weapon.draw(screen) | 
 | ||||||
| 
 |             # for weapon in objects[3]: | ||||||
|             for thing in objects[0]: |             #     weapon.update(objects) | ||||||
|                 thing.book.hidden = not freeze |             #     weapon.draw(screen) | ||||||
|                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) | 
 | ||||||
|                 if result == 'village': |             for thing in objects[0]: | ||||||
|                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 thing.book.hidden = not freeze | ||||||
|                 elif result == 'play': |                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) | ||||||
|                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 if result == 'village': | ||||||
|                 elif result == 'wall': |                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 elif result == 'play': | ||||||
|                 else: |                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                     thing.draw(screen) |                 elif result == 'wall': | ||||||
|          |                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|             for npc in objects[2]: |                 else: | ||||||
|                 npc.update(pygame.key.get_pressed(), objects) |                     thing.draw(screen) | ||||||
|                 npc.draw(screen) |          | ||||||
|              |             for npc in objects[2]: | ||||||
|             objects[0][0].book.addspell('windslash') |                 npc.update(pygame.key.get_pressed(), objects) | ||||||
|             room.update(objects) |                 npc.draw(screen) | ||||||
| 
 |              | ||||||
|         else: |             objects[0][0].book.addspell('windslash') | ||||||
|             objects[0][0].book.hidden = not freeze |             room.update(objects) | ||||||
|             objects[0][0].book.draw(screen) | 
 | ||||||
|             objects[0][0].book.update() |         else: | ||||||
|         # flip() the display to put your work on screen |             objects[0][0].book.hidden = not freeze | ||||||
|         pygame.display.flip() |             objects[0][0].book.draw(screen) | ||||||
| 
 |             objects[0][0].book.update() | ||||||
|         clock.tick(fps)  # limits FPS to  |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
| 
 | 
 | ||||||
| 
 |         clock.tick(fps)  # limits FPS to  | ||||||
| def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | 
 | ||||||
|     objects = [] | 
 | ||||||
|     # List that is displayed while selecting the window resolution level  | 
 | ||||||
|     resolution = [("1920x1080", "1920x1080"),  | def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|                   ("1920x1200", "1920x1200"),  |     objects = [] | ||||||
|                   ("1280x720", "1280x720"),  |     # List that is displayed while selecting the window resolution level  | ||||||
|                   ("2560x1440", "2560x1440"),  |     resolution = [("1920x1080", "1920x1080"),  | ||||||
|                   ("3840x2160", "3840x2160")] |                   ("1920x1200", "1920x1200"),  | ||||||
|      |                   ("1280x720", "1280x720"),  | ||||||
|     # This function displays the currently selected options  |                   ("2560x1440", "2560x1440"),  | ||||||
| 
 |                   ("3840x2160", "3840x2160")] | ||||||
|     def printSettings():  |      | ||||||
|         print("\n\n")  |     # This function displays the currently selected options  | ||||||
|         # getting the data using "get_input_data" method of the Menu class  | 
 | ||||||
|         settingsData = settings.get_input_data()  |     def printSettings():  | ||||||
| 
 |         print("\n\n")  | ||||||
|         for key in settingsData.keys():  |         # getting the data using "get_input_data" method of the Menu class  | ||||||
|             print(f"{key}\t:\t{settingsData[key]}")  |         settingsData = settings.get_input_data()  | ||||||
|      | 
 | ||||||
|     while running: |         for key in settingsData.keys():  | ||||||
|         for event in pygame.event.get(): |             print(f"{key}\t:\t{settingsData[key]}")  | ||||||
|             if event.type == pygame.QUIT: |      | ||||||
|                 running = False  |     while running: | ||||||
|         # RENDER YOUR GAME HERE |         for event in pygame.event.get(): | ||||||
|         with open(background, 'r') as i: |             if event.type == pygame.QUIT: | ||||||
|             bg = pygame.image.load(i) |                 running = False  | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |         # RENDER YOUR GAME HERE | ||||||
|         # fill the screen with an image to clear the screen |         with open(background, 'r') as i: | ||||||
|         screen.blit(bg, (0, 0)) |             bg = pygame.image.load(i) | ||||||
|         for obj in objects: |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|             obj.process(screen) |         # fill the screen with an image to clear the screen | ||||||
| 
 |         screen.blit(bg, (0, 0)) | ||||||
|         # flip() the display to put your work on screen |         for obj in objects: | ||||||
|         pygame.display.flip() |             obj.process(screen) | ||||||
| 
 | 
 | ||||||
|         clock.tick(60)  # limits FPS to 60 |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
| def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | 
 | ||||||
|     objects = [] |         clock.tick(60)  # limits FPS to 60 | ||||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Play", village, attributes=[screen, clock, running, background, isblack, WIDTH, HEIGHT])) | 
 | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) | def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) |     objects = [] | ||||||
|     while running: |     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Play", village, attributes=[screen, clock, running, background, isblack, WIDTH, HEIGHT])) | ||||||
|         for event in pygame.event.get(): |     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) | ||||||
|             if event.type == pygame.QUIT: |     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) | ||||||
|                 running = False |     while running: | ||||||
|                 quitGame() |         for event in pygame.event.get(): | ||||||
|         # RENDER YOUR GAME HERE |             if event.type == pygame.QUIT: | ||||||
|         with open(f'art/images/background/{background}', 'r') as i: |                 running = False | ||||||
|             bg = pygame.image.load(i) |                 quitGame() | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |         # RENDER YOUR GAME HERE | ||||||
|         # fill the screen with an image to clear the screen |         with open(f'art/images/background/{background}', 'r') as i: | ||||||
|         screen.blit(bg, (0, 0)) |             bg = pygame.image.load(i) | ||||||
|         for obj in objects: |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|             obj.update(screen) |         # fill the screen with an image to clear the screen | ||||||
| 
 |         screen.blit(bg, (0, 0)) | ||||||
|         # flip() the display to put your work on screen |         for obj in objects: | ||||||
|         pygame.display.flip() |             obj.update(screen) | ||||||
| 
 | 
 | ||||||
|         clock.tick(60)  # limits FPS to 60 |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
| def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): | 
 | ||||||
|     main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)] |         clock.tick(60)  # limits FPS to 60 | ||||||
|     mobs = [Skeleton(i, random.randint(40, 60), 'reddy.png', random.randint(20,1000), random.randint(20,700), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))] | 
 | ||||||
|     others = [] | def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)] |     main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)] | ||||||
|     objects = [main, mobs, npcs, others] |     mobs = [Skeleton(i, random.randint(40, 60), 'reddy.png', random.randint(20,1000), random.randint(20,700), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))] | ||||||
|     level = [] |     others = [] | ||||||
|     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) |     npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)] | ||||||
|     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) |     objects = [main, mobs, npcs, others] | ||||||
|     freeze = False #Gameplay is freezed in certain situations |     level = [] | ||||||
|      |     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) | ||||||
|     #level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ |     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) | ||||||
|     #    Room('red1', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), |     freeze = False #Gameplay is freezed in certain situations | ||||||
|     #    Room('red2', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), |      | ||||||
|     #    Room('red3', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), |     #level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ | ||||||
|     #        ])) |     #    Room('red1', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), | ||||||
|      |     #    Room('red2', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), | ||||||
|     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) |     #    Room('red3', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), | ||||||
| 
 |     #        ])) | ||||||
|     # RENDER YOUR GAME HERE |      | ||||||
|     while True: |     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) | ||||||
|         screen.fill('#000000') | 
 | ||||||
|         events = pygame.event.get() |     # RENDER YOUR GAME HERE | ||||||
|         for event in events: |     while True: | ||||||
|             if event.type == pygame.QUIT: |         screen.fill('#000000') | ||||||
|                 running = False |         events = pygame.event.get() | ||||||
|                 quitGame() |         for event in events: | ||||||
|             elif event.type == pygame.KEYDOWN: |             if event.type == pygame.QUIT: | ||||||
|                 if event.key == pygame.K_e: #when book is open gameplay is freezed |                 running = False | ||||||
|                     freeze = not freeze |                 quitGame() | ||||||
|                  |             elif event.type == pygame.KEYDOWN: | ||||||
|             if not freeze: |                 if event.key == pygame.K_e: #when book is open gameplay is freezed | ||||||
|                 objects = scene.getObjects() |                     freeze = not freeze | ||||||
|                 for thing in objects[0]: |                  | ||||||
|                     thing.book.hidden = not freeze |             if not freeze: | ||||||
|                     if not thing.update(pygame.key.get_pressed(), objects): |                 objects = scene.getObjects() | ||||||
|                         menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 for thing in objects[0]: | ||||||
|                     thing.draw(screen) |                     thing.book.hidden = not freeze | ||||||
|              |                     if not thing.update(pygame.key.get_pressed(), objects): | ||||||
|                 for mob in objects[1]: |                         menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                     mob.update(objects) |                     thing.draw(screen) | ||||||
|                     mob.draw(screen) |              | ||||||
|                  |                 for mob in objects[1]: | ||||||
|                 for npc in objects[2]: |                     mob.update(objects) | ||||||
|                     npc.update(pygame.key.get_pressed(), objects) |                     mob.draw(screen) | ||||||
|                     npc.draw(screen) |                  | ||||||
|                  |                 for npc in objects[2]: | ||||||
|                 for thing in objects[3]: |                     npc.update(pygame.key.get_pressed(), objects) | ||||||
|                     thing.update(objects) |                     npc.draw(screen) | ||||||
|                     thing.draw(screen) |                  | ||||||
| 
 |                 for thing in objects[3]: | ||||||
|             else: |                     thing.update(objects) | ||||||
|                 objects[0][0].book.hidden = not freeze |                     thing.draw(screen) | ||||||
|                 objects[0][0].book.draw(screen) | 
 | ||||||
|                 objects[0][0].book.update() |             else: | ||||||
|         # flip() the display to put your work on screen |                 objects[0][0].book.hidden = not freeze | ||||||
|         pygame.display.flip() |                 objects[0][0].book.draw(screen) | ||||||
| 
 |                 objects[0][0].book.update() | ||||||
|         clock.tick(60)  # limits FPS to 60 |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
| def main(): | 
 | ||||||
|     config = readConfig() |         clock.tick(60)  # limits FPS to 60 | ||||||
|     screen, clock, running, isblack, background, objects = setUp(config["screen"]) | 
 | ||||||
|     WIDTH, HEIGHT = screen.get_size() | def main(): | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Play", play)) |     config = readConfig() | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) |     screen, clock, running, isblack, background, objects = setUp(config["screen"]) | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) |     WIDTH, HEIGHT = screen.get_size() | ||||||
|     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Play", play)) | ||||||
|     test(screen, clock, running, background, isblack, WIDTH, HEIGHT) |     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) | ||||||
|      |     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) | ||||||
|     """while running: |     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|         for event in pygame.event.get(): |     test(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|             if event.type == pygame.QUIT: |      | ||||||
|                 running = False  |     """while running: | ||||||
|         #menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |         for event in pygame.event.get(): | ||||||
|         if not isblack: |             if event.type == pygame.QUIT: | ||||||
|             with open(background, 'r') as i: |                 running = False  | ||||||
|                 bg = pygame.image.load(i) |         #menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                 bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |         if not isblack: | ||||||
|             # fill the screen with a color to wipe away anything from last frame |             with open(background, 'r') as i: | ||||||
|             screen.blit(bg, (0, 0)) |                 bg = pygame.image.load(i) | ||||||
| 
 |                 bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|         # RENDER YOUR GAME HERE |             # fill the screen with a color to wipe away anything from last frame | ||||||
| 
 |             screen.blit(bg, (0, 0)) | ||||||
|         else: | 
 | ||||||
|             for obj in objects: |         # RENDER YOUR GAME HERE | ||||||
|                 obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) | 
 | ||||||
|         # flip() the display to put your work on screen |         else: | ||||||
|         pygame.display.flip() |             for obj in objects: | ||||||
| 
 |                 obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|         clock.tick(60)  # limits FPS to 60""" |         # flip() the display to put your work on screen | ||||||
| 
 |         pygame.display.flip() | ||||||
|     pygame.quit() | 
 | ||||||
| 
 |         clock.tick(60)  # limits FPS to 60""" | ||||||
| if __name__ == '__main__': | 
 | ||||||
|     herbert = MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50) |     pygame.quit() | ||||||
|     main() | 
 | ||||||
|  | if __name__ == '__main__': | ||||||
|  |     herbert = MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50) | ||||||
|  |     main() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue