Development #8
							
								
								
									
										
											BIN
										
									
								
								art/image files/dooor.kra
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								art/image files/door.kra
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								art/image files/startscreen.kra
									
										
									
									
									
										Normal file
									
								
							
							
						
						
							
								
								
									
										
											BIN
										
									
								
								art/images/background/door_boss.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| Before Width: | Height: | Size: 210 B After Width: | Height: | Size: 210 B | 
							
								
								
									
										
											BIN
										
									
								
								art/images/background/door_normal.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 172 B | 
							
								
								
									
										
											BIN
										
									
								
								art/images/background/startscreen.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| Before Width: | Height: | Size: 4.2 MiB After Width: | Height: | Size: 4.2 MiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/icon.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						| Before Width: | Height: | Size: 488 KiB After Width: | Height: | Size: 488 KiB | 
							
								
								
									
										62
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						|  | @ -1,4 +1,5 @@ | ||||||
| import pygame | import pygame | ||||||
|  | import random | ||||||
| 
 | 
 | ||||||
| pygame.font.init() | pygame.font.init() | ||||||
| fonts = { | fonts = { | ||||||
|  | @ -205,9 +206,9 @@ class Scene(GameObjects): | ||||||
|                 obj.update()""" |                 obj.update()""" | ||||||
|          |          | ||||||
|     def draw(self, screen): |     def draw(self, screen): | ||||||
|         if isinstance(self.objects, list): |         """if isinstance(self.objects, list): | ||||||
|             for obj in self.objects[0] + self.objects[1] + self.objects[2] + self.objects[3]: |             for obj in self.objects[0] + self.objects[1] + self.objects[2] + self.objects[3]: | ||||||
|                 obj.draw(screen) |                 obj.draw(screen)""" | ||||||
|         self.level[self.current_level].draw(screen) |         self.level[self.current_level].draw(screen) | ||||||
| 
 | 
 | ||||||
|     def getObjects(self): |     def getObjects(self): | ||||||
|  | @ -220,6 +221,7 @@ class Stage(GameObjects): | ||||||
|         self.stage = stage |         self.stage = stage | ||||||
|         self.rooms = rooms |         self.rooms = rooms | ||||||
|         self.current = 0 |         self.current = 0 | ||||||
|  |         self.sortRooms(WIDTH) | ||||||
|      |      | ||||||
|     def update(self, objects): |     def update(self, objects): | ||||||
|         for room in self.rooms: |         for room in self.rooms: | ||||||
|  | @ -242,11 +244,40 @@ class Stage(GameObjects): | ||||||
|             if room.id == self.current: |             if room.id == self.current: | ||||||
|                 return room.getObjects() |                 return room.getObjects() | ||||||
|      |      | ||||||
|  |     def sortRooms(self, WIDTH): | ||||||
|  |         rooms = self.rooms | ||||||
|  |         for i, room in enumerate(rooms): | ||||||
|  |             if room.type != 'boss': | ||||||
|  |                 i += 1 | ||||||
|  |                 rand = random.randint(0, 25) | ||||||
|  |                 if rand < 7.5: | ||||||
|  |                     if rooms[i].id <= room.id: i += 1 | ||||||
|  |                     room.exits.append([rooms[i].id, rooms[i].type]) | ||||||
|  |                 elif rand < 20: | ||||||
|  |                     if rooms[i].id <= room.id: i += 1 | ||||||
|  |                     room.exits.append([rooms[i].id, rooms[i].type]) | ||||||
|  |                     if rand % 2 == 0: i += 1 | ||||||
|  |                     if not i >= len(self.rooms) - 2: | ||||||
|  |                         room.exits.append([rooms[i + 1].id, rooms[i + 1].type]) | ||||||
|  |                 else: | ||||||
|  |                     if rooms[i].id <= room.id: i += 1 | ||||||
|  |                     room.exits.append([rooms[i].id, rooms[i].type]) | ||||||
|  |                     if rand % 2 == 0: i += 1 | ||||||
|  |                     if not i >= len(self.rooms) - 2: | ||||||
|  |                         room.exits.append([rooms[i + 1].id, rooms[i + 1].type]) | ||||||
|  |                         if not i >= len(self.rooms) - 3: | ||||||
|  |                             room.exits.append([rooms[i + 2].id, rooms[i + 2].type]) | ||||||
|  |              | ||||||
|  |         for room in self.rooms: | ||||||
|  |             print(str(room.id) + str(room.exits)) | ||||||
|  |             room.createDoors(WIDTH) | ||||||
|  | 
 | ||||||
| class Room(GameObjects): | class Room(GameObjects): | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT, exits:list, id:int) -> None: |     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT, id:int) -> None: | ||||||
|         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|         self.exits = exits |         self.exits = [] | ||||||
|         self.id = id |         self.id = id | ||||||
|  |         self.doors = [] | ||||||
|         if self.type == 'normal' or self.type == 'boss': |         if self.type == 'normal' or self.type == 'boss': | ||||||
|             self.locked = True |             self.locked = True | ||||||
|         else: |         else: | ||||||
|  | @ -261,6 +292,17 @@ class Room(GameObjects): | ||||||
|         walls.append(Obstacle('wall_b', 'wall', None, True, 32, HEIGHT + 28, True, WIDTH=WIDTH, HEIGHT=4)) |         walls.append(Obstacle('wall_b', 'wall', None, True, 32, HEIGHT + 28, True, WIDTH=WIDTH, HEIGHT=4)) | ||||||
|         return walls |         return walls | ||||||
| 
 | 
 | ||||||
|  |     def createDoors(self, WIDTH): | ||||||
|  |         if len(self.exits) == 1: | ||||||
|  |             self.doors.append(Door(f'door{self.id}', self.exits[0][1], random.randint(64, round(WIDTH * 0.75)), 4, self.exits[0][0])) | ||||||
|  |         elif len(self.exits) == 2: | ||||||
|  |             self.doors.append(Door(f'door{self.id}', self.exits[0][1], random.randint(64, round(WIDTH * 0.45)), self.exits[0][0])) | ||||||
|  |             self.doors.append(Door(f'door{self.id}', self.exits[1][1], random.randint(round(WIDTH * 0.5), round(WIDTH * 0.9)), self.exits[1][0])) | ||||||
|  |         else: | ||||||
|  |             self.doors.append(Door(f'door{self.id}', self.exits[0][1], random.randint(64, round(WIDTH * 0.3)), self.exits[0][0])) | ||||||
|  |             self.doors.append(Door(f'door{self.id}', self.exits[1][1], random.randint(round(WIDTH * 0.33), round(WIDTH * 0.6)), self.exits[1][0])) | ||||||
|  |             self.doors.append(Door(f'door{self.id}', self.exits[2][1], random.randint(round(WIDTH * 0.63), round(WIDTH * 0.95)), self.exits[2][0])) | ||||||
|  | 
 | ||||||
|     def update(self, objects): |     def update(self, objects): | ||||||
|         if objects is not None: |         if objects is not None: | ||||||
|             self.objects = objects |             self.objects = objects | ||||||
|  | @ -269,10 +311,12 @@ class Room(GameObjects): | ||||||
|         return |         return | ||||||
|      |      | ||||||
|     def draw(self, screen): |     def draw(self, screen): | ||||||
|         screen.blit(self.background, (32, 32)) |         """screen.blit(self.background, (32, 32)) | ||||||
|         if isinstance(self.objects, list): |         if isinstance(self.objects, list): | ||||||
|             for obj in self.objects[3] + self.objects[0] + self.objects[1] + self.objects[2]: |             for obj in self.objects[3] + self.objects[0] + self.objects[1] + self.objects[2]: | ||||||
|                 obj.draw(screen) |                 obj.draw(screen)""" | ||||||
|  |         for door in self.doors: | ||||||
|  |             door.draw(screen) | ||||||
| 
 | 
 | ||||||
|     def getObjects(self): |     def getObjects(self): | ||||||
|         return self.objects |         return self.objects | ||||||
|  | @ -292,12 +336,10 @@ class Obstacle(GameObjects): | ||||||
|     def draw(self, screen): |     def draw(self, screen): | ||||||
|         if not self.hidden: |         if not self.hidden: | ||||||
|             screen.blit(self.background, self.rect) |             screen.blit(self.background, self.rect) | ||||||
|         else: |  | ||||||
|             pygame.draw.rect(screen, '#e7f8e0', self.rect, 2) |  | ||||||
| 
 | 
 | ||||||
| class Door(GameObjects): | class Door(GameObjects): | ||||||
|     def __init__(self, name: str, _type: str, bg, objects: list, WIDTH, HEIGHT, x: int, y: int, islocked=True) -> None: |     def __init__(self, name: str, _type: str, x: int, target:int, y: int=8, objects: list=None, WIDTH=None, HEIGHT=None, islocked=True) -> None: | ||||||
|         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) |         super().__init__(name, _type, f'art/images/background/door_{_type}.png', objects, WIDTH, HEIGHT) | ||||||
|         self.rect = pygame.Rect((x, y), self.background.get_size()) |         self.rect = pygame.Rect((x, y), self.background.get_size()) | ||||||
|         self.locked = islocked |         self.locked = islocked | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								main.py
									
										
									
									
									
								
							
							
						
						|  | @ -15,7 +15,9 @@ def setUp(config): | ||||||
|         screen = pygame.display.set_mode(config["res"]) |         screen = pygame.display.set_mode(config["res"]) | ||||||
|     clock = pygame.time.Clock() |     clock = pygame.time.Clock() | ||||||
|     pygame.display.set_caption('Between The Pages') |     pygame.display.set_caption('Between The Pages') | ||||||
|     return screen, clock, True, True, "start.png", [] |     with open('art/images/icon.png', 'r') as i: | ||||||
|  |         pygame.display.set_icon(pygame.image.load(i)) | ||||||
|  |     return screen, clock, True, True, "startscreen.png", [] | ||||||
| 
 | 
 | ||||||
| def readConfig(): | def readConfig(): | ||||||
|     with open('config.json', 'r') as c: |     with open('config.json', 'r') as c: | ||||||
|  | @ -33,9 +35,10 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list): | ||||||
|     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))) |     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))) | ||||||
|     room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)] |     room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)] | ||||||
|     rooms = [ |     rooms = [ | ||||||
|         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, [True, True, True, True], j) |         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) | ||||||
|         for j in range(random.randint(5, 10)) |         for j in range(random.randint(5, 10)) | ||||||
|     ] |     ] | ||||||
|  |     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) |     #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) | ||||||
|      |      | ||||||
|     return rooms |     return rooms | ||||||
|  | @ -100,6 +103,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|              |              | ||||||
|             objects[0][0].book.addspell('windslash') |             objects[0][0].book.addspell('windslash') | ||||||
|             scene.update(False, objects) |             scene.update(False, objects) | ||||||
|  |             scene.draw(screen) | ||||||
| 
 | 
 | ||||||
|         else: |         else: | ||||||
|             objects[0][0].book.hidden = not freeze |             objects[0][0].book.hidden = not freeze | ||||||
|  | @ -118,7 +122,7 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|               Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] |               Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] | ||||||
|     npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] |     npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     objects = [main, mobs, npcs, weapons, others] | ||||||
|     room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0) |     room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, 0) | ||||||
|     freeze = True #Gameplay is freezed in certain situations |     freeze = True #Gameplay is freezed in certain situations | ||||||
|     main[0].health.health = 20 |     main[0].health.health = 20 | ||||||
| 
 | 
 | ||||||
|  | @ -187,7 +191,7 @@ def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     others = [] |     others = [] | ||||||
|     npcs = [NPC('elder', 100, 'people/reddy.png', 0, 200, 200)] |     npcs = [NPC('elder', 100, 'people/reddy.png', 0, 200, 200)] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     objects = [main, mobs, npcs, weapons, others] | ||||||
|     room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0) |     room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, 0) | ||||||
|     freeze = False #Gameplay is freezed in certain situations |     freeze = False #Gameplay is freezed in certain situations | ||||||
| 
 | 
 | ||||||
|     while running: |     while running: | ||||||
|  | @ -286,7 +290,7 @@ def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
| 
 | 
 | ||||||
| def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     objects = [] |     objects = [] | ||||||
|     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, 160, 64, 'textbox.png', 'medieval', 48, "Play", play, 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)) |     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 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)) |     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) | ||||||
|     while running: |     while running: | ||||||
|  |  | ||||||