forked from InfoProjekt/game
		
	added Label class
Label class in classes, added text to book, changed wind spell a bit but dunno if really good
This commit is contained in:
		
							parent
							
								
									96c0a691b7
								
							
						
					
					
						commit
						41f8b76b90
					
				
					 3 changed files with 929 additions and 817 deletions
				
			
		
							
								
								
									
										514
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						
									
										514
									
								
								classes.py
									
										
									
									
									
								
							|  | @ -1,230 +1,284 @@ | ||||||
| import pygame | import pygame | ||||||
| 
 | 
 | ||||||
| pygame.font.init() | pygame.font.init() | ||||||
| fonts = { | fonts = { | ||||||
|     'medieval': 'medieval.ttf', |     'medieval': 'medieval.ttf', | ||||||
|     'minecraft': 'Minecraft Evenings.otf', |     'minecraft': 'Minecraft Evenings.otf', | ||||||
|     '3dpixel': '3D-Pixel.ttf', |     '3dpixel': '3D-Pixel.ttf', | ||||||
|     '8bit': '8bitlim.ttf', |     '8bit': '8bitlim.ttf', | ||||||
|     '8bito': '8blimro.ttf', |     '8bito': '8blimro.ttf', | ||||||
|     'arcade': 'ARCADECLASSIC.ttf', |     'arcade': 'ARCADECLASSIC.ttf', | ||||||
|     'modern_game': 'astron boy video.otf', |     'modern_game': 'astron boy video.otf', | ||||||
|     'modern': 'astron boy.otf', |     'modern': 'astron boy.otf', | ||||||
|     'wonder': 'Beyond Wonderland.ttf', |     'wonder': 'Beyond Wonderland.ttf', | ||||||
|     'curved': 'Digitag.ttf', |     'curved': 'Digitag.ttf', | ||||||
|     'simple': 'DisposableDroidBB.ttf', |     'simple': 'DisposableDroidBB.ttf', | ||||||
|     'rounded': 'dpcomic.ttf', |     'rounded': 'dpcomic.ttf', | ||||||
|     'playfull': 'Endalian Script.ttf', |     'playfull': 'Endalian Script.ttf', | ||||||
|     'blocky': 'FREAKSOFNATURE.ttf', |     'blocky': 'FREAKSOFNATURE.ttf', | ||||||
|     'catchy': 'Future TimeSplitters.otf', |     'catchy': 'Future TimeSplitters.otf', | ||||||
|     'simple_wide': 'Halo3.ttf', |     'simple_wide': 'Halo3.ttf', | ||||||
|     'simple_fat': 'INVASION2000.ttf', |     'simple_fat': 'INVASION2000.ttf', | ||||||
|     'very_gamy': 'ka1.ttf', |     'very_gamy': 'ka1.ttf', | ||||||
|     'simple_round': 'Karma Suture.otf', |     'simple_round': 'Karma Suture.otf', | ||||||
|     'mono': 'manaspc.ttf', |     'mono': 'manaspc.ttf', | ||||||
|     'damaged': 'Merchant Copy.ttf', |     'damaged': 'Merchant Copy.ttf', | ||||||
|     'big_natural': 'MorialCitadel.TTF', |     'big_natural': 'MorialCitadel.TTF', | ||||||
|     'spacy': 'nasalization-rg.otf', |     'spacy': 'nasalization-rg.otf', | ||||||
|     'sci-fi': 'neuropol.otf', |     'sci-fi': 'neuropol.otf', | ||||||
|     'hollow_big_edge': 'papercut.ttf', |     'hollow_big_edge': 'papercut.ttf', | ||||||
|     'space_shuttle': 'pdark.ttf', |     'space_shuttle': 'pdark.ttf', | ||||||
|     'thin': 'PixelFJVerdana12pt.ttf', |     'thin': 'PixelFJVerdana12pt.ttf', | ||||||
|     'random': 'Seattle Avenue.ttf', |     'random': 'Seattle Avenue.ttf', | ||||||
|     'pixel': 'yoster.ttf' |     'pixel': 'yoster.ttf' | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| class Button(): | class Button(): | ||||||
|     def __init__(self, x, y, width, height, image, font, font_size, buttonText='', onclickFunction=None, onePress=False): |     def __init__(self, x, y, width, height, image, font, font_size, buttonText='', onclickFunction=None, onePress=False, attributes=None): | ||||||
|         self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) |         self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) | ||||||
|         self.x = x |         self.x = x | ||||||
|         self.y = y |         self.y = y | ||||||
|         self.width = width |         self.width = width | ||||||
|         self.height = height |         self.height = height | ||||||
|         self.onclickFunction = onclickFunction |         self.attributes = attributes | ||||||
|         self.onePress = onePress |         self.onclickFunction = onclickFunction | ||||||
|         self.alreadyPressed = False |         self.onePress = onePress | ||||||
| 
 |         self.alreadyPressed = False | ||||||
|         with open(f'art/images/{image}', 'r') as tb: | 
 | ||||||
|             self.box = pygame.image.load(tb) |         with open(f'art/images/{image}', 'r') as tb: | ||||||
|             self.box = pygame.transform.scale(self.box, (width, height)) |             self.box = pygame.image.load(tb) | ||||||
| 
 |             self.box = pygame.transform.scale(self.box, (width, height)) | ||||||
| 
 | 
 | ||||||
|         self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height) | 
 | ||||||
| 
 |         self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height) | ||||||
|         self.buttonSurf = self.font.render(buttonText, True, '#baab80') | 
 | ||||||
| 
 |         self.buttonSurf = self.font.render(buttonText, True, '#baab80') | ||||||
|     def update(self, screen, clock=None, running=None, background=None, isblack=None, WIDTH=None, HEIGHT=None): | 
 | ||||||
|         mousePos = pygame.mouse.get_pos() |     def update(self, screen): | ||||||
|         if self.buttonRect.collidepoint(mousePos): |         mousePos = pygame.mouse.get_pos() | ||||||
|             if pygame.mouse.get_pressed(num_buttons=3)[0]: |         if self.buttonRect.collidepoint(mousePos): | ||||||
|                 if self.onePress: |             if pygame.mouse.get_pressed(num_buttons=3)[0]: | ||||||
|                     self.onclickFunction() |                 if self.onePress: | ||||||
|                 elif not self.alreadyPressed: |                     self.onclickFunction() | ||||||
|                     if 'play' in str(self.onclickFunction): |                 elif not self.alreadyPressed: | ||||||
|                         self.onclickFunction(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                     if self.attributes: | ||||||
|                         self.alreadyPressed = True |                         self.onclickFunction(*self.attributes) | ||||||
|                     else: |                         self.alreadyPressed = True | ||||||
|                         self.onclickFunction() |                     else: | ||||||
|                         self.alreadyPressed = True |                         self.onclickFunction() | ||||||
|             else: |                         self.alreadyPressed = True | ||||||
|                 self.alreadyPressed = False |             else: | ||||||
|         self.box.blit(self.buttonSurf, [ |                 self.alreadyPressed = False | ||||||
|             self.buttonRect.width/2 - self.buttonSurf.get_rect().width/2, |         self.box.blit(self.buttonSurf, [ | ||||||
|             self.buttonRect.height/2 - self.buttonSurf.get_rect().height/2 |             self.buttonRect.width/2 - self.buttonSurf.get_rect().width/2, | ||||||
|         ]) |             self.buttonRect.height/2 - self.buttonSurf.get_rect().height/2 | ||||||
|         screen.blit(self.box, self.buttonRect) |         ]) | ||||||
| 
 |         screen.blit(self.box, self.buttonRect) | ||||||
| 
 | 
 | ||||||
| class DropDown(): | class Label(): | ||||||
|     def __init__(self, x, y, width, height, font, font_size, color_menu, color_option, main, options): |     def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color = '#1E90FF', sprite = 'label.png') -> None: | ||||||
|         self.rect = pygame.Rect(x, y, width, height) |         self.x = x | ||||||
|         self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) |         self.y = y | ||||||
|         self.main = main |         self.width = width | ||||||
|         self.options = options |         self.height = height | ||||||
|         self.draw_menu = False |         self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) | ||||||
|         self.menu_active = False |         self.hidden = False | ||||||
|         self.active_option = -1 |         with open(f'art/images/{sprite}', 'r') as tb: | ||||||
| 
 |             self.box = pygame.image.load(tb) | ||||||
|         with open('art/images/textbox.png', 'r') as tb: |             self.box = pygame.transform.scale(self.box, (width, height)) | ||||||
|             self.box = pygame.image.load(tb) |         self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height) | ||||||
|             self.box = pygame.transform.scale(self.box, (width, height)) |         self.labelSurf = self.font.render(text, True, font_color) | ||||||
| 
 | 
 | ||||||
|     def draw(self, screen): |     def draw(self, screen): | ||||||
|         #pygame.draw.rect(screen, self.color_menu[self.menu_active], self.rect, 0) |         if self.hidden: | ||||||
|         surface = self.font.render(self.main, 1, (0, 0, 0)) |             return | ||||||
|         self.box.blit(surface, [ |         self.box.blit(self.labelSurf, [ | ||||||
|             self.rect.width/2 - surface.get_rect().width/2, |             self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2, | ||||||
|             self.rect.height/2 - surface.get_rect().height/2 |             self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2 | ||||||
|         ]) |         ]) | ||||||
|         screen.blit(self.box, surface.get_rect(center = self.rect.center)) |         screen.blit(self.box, self.labelRect) | ||||||
| 
 | 
 | ||||||
|         if self.draw_menu: | 
 | ||||||
|             for i, text in enumerate(self.options): | 
 | ||||||
|                 rect = self.rect.copy() | class DropDown(): | ||||||
|                 rect.y += (i+1) * self.rect.height |     def __init__(self, x, y, width, height, font, font_size, color_menu, color_option, main, options): | ||||||
|                 rect.x = self.rect.x |         self.rect = pygame.Rect(x, y, width, height) | ||||||
|                 #pygame.draw.rect(screen, self.color_option[1 if i == self.active_option else 0], rect, 0) |         self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size) | ||||||
|                 #msg = self.font.render(text, 1, (0, 0, 0)) |         self.main = main | ||||||
|                 #screen.blit(msg, msg.get_rect(center = rect.center)) |         self.options = options | ||||||
|                 surface = self.font.render(text, 1, (0, 0, 0)) |         self.draw_menu = False | ||||||
|                 self.box.blit(surface, [ |         self.menu_active = False | ||||||
|                     rect.width/2 - surface.get_rect().width/2, |         self.active_option = -1 | ||||||
|                     rect.height/2 - surface.get_rect().height/2 | 
 | ||||||
|                 ]) |         with open('art/images/textbox.png', 'r') as tb: | ||||||
|                 screen.blit(self.box, rect) |             self.box = pygame.image.load(tb) | ||||||
| 
 |             self.box = pygame.transform.scale(self.box, (width, height)) | ||||||
|     def update(self, event_list): | 
 | ||||||
|         mpos = pygame.mouse.get_pos() |     def draw(self, screen): | ||||||
|         self.menu_active = self.rect.collidepoint(mpos) |         #pygame.draw.rect(screen, self.color_menu[self.menu_active], self.rect, 0) | ||||||
|         self.active_option = -1 |         surface = self.font.render(self.main, 1, (0, 0, 0)) | ||||||
|         for i in range(len(self.options)): |         self.box.blit(surface, [ | ||||||
|             rect = self.rect.copy() |             self.rect.width/2 - surface.get_rect().width/2, | ||||||
|             rect.y += (i+1) * self.rect.height |             self.rect.height/2 - surface.get_rect().height/2 | ||||||
|             if rect.collidepoint(mpos): |         ]) | ||||||
|                 self.active_option = i |         screen.blit(self.box, surface.get_rect(center = self.rect.center)) | ||||||
|                 break | 
 | ||||||
| 
 |         if self.draw_menu: | ||||||
|         if not self.menu_active and self.active_option == -1: |             for i, text in enumerate(self.options): | ||||||
|             self.draw_menu = False |                 rect = self.rect.copy() | ||||||
|         #self.draw_menu = True |                 rect.y += (i+1) * self.rect.height | ||||||
|         #return -1 |                 rect.x = self.rect.x | ||||||
|         if pygame.mouse.get_pressed(num_buttons=3)[0]: |                 #pygame.draw.rect(screen, self.color_option[1 if i == self.active_option else 0], rect, 0) | ||||||
|             if self.menu_active: |                 #msg = self.font.render(text, 1, (0, 0, 0)) | ||||||
|                 self.draw_menu = not self.draw_menu |                 #screen.blit(msg, msg.get_rect(center = rect.center)) | ||||||
|             elif self.draw_menu and self.active_option >= 0: |                 surface = self.font.render(text, 1, (0, 0, 0)) | ||||||
|                 self.draw_menu = False |                 self.box.blit(surface, [ | ||||||
|                 return self.active_option |                     rect.width/2 - surface.get_rect().width/2, | ||||||
|         return -1 |                     rect.height/2 - surface.get_rect().height/2 | ||||||
| 
 |                 ]) | ||||||
| 
 |                 screen.blit(self.box, rect) | ||||||
| class GameObjects(): | 
 | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT) -> None: |     def update(self, event_list): | ||||||
|         self.name = name |         mpos = pygame.mouse.get_pos() | ||||||
|         self.type = _type |         self.menu_active = self.rect.collidepoint(mpos) | ||||||
|         self.background = bg |         self.active_option = -1 | ||||||
|         if bg != None: |         for i in range(len(self.options)): | ||||||
|             with open(bg, 'r') as bg: |             rect = self.rect.copy() | ||||||
|                 self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT]) |             rect.y += (i+1) * self.rect.height | ||||||
|         self.objects = objects |             if rect.collidepoint(mpos): | ||||||
| 
 |                 self.active_option = i | ||||||
| 
 |                 break | ||||||
| class Scene(GameObjects): | 
 | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list | None, WIDTH, HEIGHT, level:list) -> None: |         if not self.menu_active and self.active_option == -1: | ||||||
|         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) |             self.draw_menu = False | ||||||
|         self.level = level |         #self.draw_menu = True | ||||||
|         self.current_level = 0 |         #return -1 | ||||||
| 
 |         if pygame.mouse.get_pressed(num_buttons=3)[0]: | ||||||
|     def update(self, change:bool): |             if self.menu_active: | ||||||
|         if change: |                 self.draw_menu = not self.draw_menu | ||||||
|             self.current_level += 1 |             elif self.draw_menu and self.active_option >= 0: | ||||||
|         self.level[self.current_level].update() |                 self.draw_menu = False | ||||||
|         if isinstance(self.objects, list): |                 return self.active_option | ||||||
|             for obj in self.objects: |         return -1 | ||||||
|                 obj.update() | 
 | ||||||
|          | 
 | ||||||
|     def draw(self, screen): | class GameObjects(): | ||||||
|         if isinstance(self.objects, list): |     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT) -> None: | ||||||
|             for obj in self.objects: |         self.name = name | ||||||
|                 obj.draw(screen) |         self.type = _type | ||||||
|         self.level[self.current_level].draw(screen) |         self.background = bg | ||||||
|          |         if bg != None: | ||||||
| 
 |             with open(bg, 'r') as bg: | ||||||
| class Stage(GameObjects): |                 self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT]) | ||||||
|     def __init__(self, name: str, _type: str, bg, objects: list, WIDTH, HEIGHT, stage:str, rooms:list) -> None: |         self.objects = objects | ||||||
|         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | 
 | ||||||
|         self.stage = stage |     def update(self, objects): | ||||||
|         self.rooms = rooms |         return | ||||||
|         self.current = 0 |     def draw(self, screen): | ||||||
|      |         return | ||||||
|     def update(self): | 
 | ||||||
|         for room in self.rooms: | class Scene(GameObjects): | ||||||
|             if room.id == self.current: |     def __init__(self, name:str, _type:str, bg, objects:list | None, WIDTH, HEIGHT, level:list) -> None: | ||||||
|                 room.update() |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|         keys = pygame.key.get_pressed() |         self.level = level | ||||||
|         if keys[pygame.K_RIGHT]: |         self.current_level = 0 | ||||||
|             self.current += 1 | 
 | ||||||
|         if self.current >= len(self.rooms): |     def update(self, change:bool, objects): | ||||||
|             return 1 |         if change: | ||||||
| 
 |             self.current_level += 1 | ||||||
|     def draw(self, screen): |         self.level[self.current_level].update(objects) | ||||||
|         for room in self.rooms: |         self.background = self.level[self.current_level].background | ||||||
|             if room.id == self.current: |         if isinstance(self.objects, list): | ||||||
|                 room.draw(screen) |             for obj in self.objects[0] + self.objects[1] + self.objects[2]: | ||||||
| 
 |                 obj.update() | ||||||
| class Room(GameObjects): |          | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT, exits:list, id:int) -> None: |     def draw(self, screen): | ||||||
|         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) |         if isinstance(self.objects, list): | ||||||
|         self.exits = exits |             for obj in self.objects[0] + self.objects[1] + self.objects[2] + self.objects[3]: | ||||||
|         self.id = id |                 obj.draw(screen) | ||||||
|         if self.type == 'normal' or self.type == 'boss': |         self.level[self.current_level].draw(screen) | ||||||
|             self.locked = True | 
 | ||||||
|         else: |     def getObjects(self): | ||||||
|             self.locked = False |         return self.level[self.current_level].getObjects() | ||||||
| 
 |          | ||||||
|         self.objects.append(self.genWalls(WIDTH, HEIGHT)) | 
 | ||||||
|          | class Stage(GameObjects): | ||||||
|     def genWalls(self, WIDTH, HEIGHT): |     def __init__(self, name: str, _type: str, bg, objects: list, WIDTH, HEIGHT, stage:str, rooms:list) -> None: | ||||||
|         walls = [] |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|         walls.append(pygame.Rect(0, 0, 4, HEIGHT)) |         self.stage = stage | ||||||
|         walls.append(pygame.Rect(WIDTH - 4, 0, 4, HEIGHT)) |         self.rooms = rooms | ||||||
|         walls.append(pygame.Rect(0, 0, WIDTH, 4)) |         self.current = 0 | ||||||
|         walls.append(pygame.Rect(0, HEIGHT - 4, WIDTH, 4)) |      | ||||||
|         return walls |     def update(self, objects): | ||||||
| 
 |         for room in self.rooms: | ||||||
|     def update(self): |             if room.id == self.current: | ||||||
|         pass |                 room.update(objects) | ||||||
| 
 |                 self.background = room.background | ||||||
|     def draw(self, screen): |         keys = pygame.key.get_pressed() | ||||||
|         screen.blit(self.background, (32, 32)) |         if keys[pygame.K_RIGHT]: | ||||||
|         if isinstance(self.objects, list): |             self.current += 1 | ||||||
|             for obj in self.objects[0]: |         if self.current >= len(self.rooms): | ||||||
|                 obj.draw(screen) |             return 1 | ||||||
| 
 | 
 | ||||||
| class Obstacle(GameObjects): |     def draw(self, screen): | ||||||
|     def __init__(self, name: str, _type: str, bg, collision: bool, x: int, y: int, hidden: bool=False, objects: list = None, WIDTH=None, HEIGHT=None) -> None: |         for room in self.rooms: | ||||||
|         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) |             if room.id == self.current: | ||||||
|         self.collision = collision |                 room.draw(screen) | ||||||
|         self.rect = pygame.Rect((x, y), self.background.get_size()) | 
 | ||||||
|      |     def getObjects(self): | ||||||
|     def draw(self, screen): |         for room in self.rooms: | ||||||
|         screen.blit(self.background, self.rect) |             if room.id == self.current: | ||||||
|  |                 return room.getObjects() | ||||||
|  | 
 | ||||||
|  | class Room(GameObjects): | ||||||
|  |     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT, exits:list, id:int) -> None: | ||||||
|  |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|  |         self.exits = exits | ||||||
|  |         self.id = id | ||||||
|  |         if self.type == 'normal' or self.type == 'boss': | ||||||
|  |             self.locked = True | ||||||
|  |         else: | ||||||
|  |             self.locked = False | ||||||
|  |         [self.objects[3].append(wall) for wall in self.genWalls(WIDTH, HEIGHT)] | ||||||
|  |          | ||||||
|  |     def genWalls(self, WIDTH, HEIGHT): | ||||||
|  |         walls = [] | ||||||
|  |         walls.append(Obstacle('wall_l', 'wall', None, True, 32, 32, True, WIDTH=4, HEIGHT=HEIGHT)) | ||||||
|  |         walls.append(Obstacle('wall_r', 'wall', None, True, WIDTH + 28, 32, True, WIDTH=4, HEIGHT=HEIGHT)) | ||||||
|  |         walls.append(Obstacle('wall_t', 'wall', None, True, 32, 32, True, WIDTH=WIDTH, HEIGHT=4)) | ||||||
|  |         walls.append(Obstacle('wall_b', 'wall', None, True, 32, HEIGHT + 28, True, WIDTH=WIDTH, HEIGHT=4)) | ||||||
|  |         return walls | ||||||
|  | 
 | ||||||
|  |     def update(self, objects): | ||||||
|  |         self.objects = objects | ||||||
|  |         if not self.objects[1]: | ||||||
|  |             self.locked = False | ||||||
|  |         return | ||||||
|  |      | ||||||
|  |     def draw(self, screen): | ||||||
|  |         screen.blit(self.background, (32, 32)) | ||||||
|  |         if isinstance(self.objects, list): | ||||||
|  |             for obj in self.objects[3] + self.objects[0] + self.objects[1] + self.objects[2]: | ||||||
|  |                 obj.draw(screen) | ||||||
|  | 
 | ||||||
|  |     def getObjects(self): | ||||||
|  |         return self.objects | ||||||
|  | 
 | ||||||
|  | class Obstacle(GameObjects): | ||||||
|  |     def __init__(self, name: str, _type: str, bg, collision: bool, x: int, y: int, hidden: bool=False, objects: list = None, WIDTH=None, HEIGHT=None) -> None: | ||||||
|  |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|  |         self.collision = collision | ||||||
|  |         self.hidden = hidden | ||||||
|  |         self.width = WIDTH | ||||||
|  |         self.height = HEIGHT | ||||||
|  |         if self.background is not None: | ||||||
|  |             self.rect = pygame.Rect((x, y), self.background.get_size()) | ||||||
|  |         else: | ||||||
|  |             self.rect = pygame.Rect(x, y, WIDTH, HEIGHT) | ||||||
|  |      | ||||||
|  |     def draw(self, screen): | ||||||
|  |         if not self.hidden: | ||||||
|  |             screen.blit(self.background, self.rect) | ||||||
|  |         else: | ||||||
|  |             pygame.draw.rect(screen, '#e0a77f', self.rect, 2) | ||||||
|  | 
 | ||||||
|  |  | ||||||
							
								
								
									
										472
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										472
									
								
								main.py
									
										
									
									
									
								
							|  | @ -1,214 +1,258 @@ | ||||||
| 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 | fps = 60 | ||||||
| 
 | 
 | ||||||
| def setUp(config): | def setUp(config): | ||||||
|     pygame.init() |     pygame.init() | ||||||
|     if config["fullscreen"]: |     if config["fullscreen"]: | ||||||
|         screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN) |         screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN) | ||||||
|     else: |     else: | ||||||
|         screen = pygame.display.set_mode(config["res"]) |         screen = pygame.display.set_mode(config["res"]) | ||||||
|     clock = pygame.time.Clock() |     clock = pygame.time.Clock() | ||||||
|      |     return screen, clock, True, True, "start.png", [] | ||||||
|     return screen, clock, True, True, "start.png", [] | 
 | ||||||
| 
 | def readConfig(): | ||||||
| def readConfig(): |     with open('config.json', 'r') as c: | ||||||
|     with open('config.json', 'r') as c: |         json_data = c.read() | ||||||
|         json_data = c.read() |     return json.loads(json_data) | ||||||
|     return json.loads(json_data) | 
 | ||||||
| 
 | def quitGame(): | ||||||
| def quitGame(): |     #save progress somehow, if needed | ||||||
|     #save progress somehow, if needed |     pygame.quit() | ||||||
|     pygame.quit() |     quit() | ||||||
|     quit() | 
 | ||||||
| 
 | def genRooms(WIDTH, HEIGHT, type:str, objects:list): | ||||||
| def genRooms(WIDTH, HEIGHT, type:str): |     room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)] | ||||||
|     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/river1.png', True, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)) | ||||||
|     room_objects.append(Obstacle('river', 'water', 'art/images/river1.png', True, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)) |     rooms = [ | ||||||
|     rooms = [ |         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, 5)]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 0), | ||||||
|         Room(type, 'normal', f'art/images/{type}.png', [[room_objects[i] for i in range(0, random.randint(0, len(room_objects)))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 0), |         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, 5)]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 1), | ||||||
|         Room(type, 'normal', f'art/images/{type}.png', [], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 1), |         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, 5)]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 2), | ||||||
|         Room(type, 'normal', f'art/images/{type}.png', [], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 2), |             ] | ||||||
|             ] |     return rooms | ||||||
|     return rooms | 
 | ||||||
| 
 |          | ||||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)] |     main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)] | ||||||
|     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))] |     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 = [] |     others = [] | ||||||
|     npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)] |     npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)] | ||||||
|     objects = [main, mobs, npcs, others] |     objects = [main, mobs, npcs, others] | ||||||
|     freeze = False #Gameplay is freezed in certain situations |     level = [] | ||||||
| 
 |     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) | ||||||
|     while running: |     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) | ||||||
|         screen.fill('#000000') |     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) | ||||||
|         events = pygame.event.get() |     freeze = False #Gameplay is freezed in certain situations | ||||||
|         for event in events: | 
 | ||||||
|             if event.type == pygame.QUIT: |     while running: | ||||||
|                 quitGame() |         screen.fill('#000000') | ||||||
|             elif event.type == pygame.KEYDOWN: |         events = pygame.event.get() | ||||||
|                 if event.key == pygame.K_e: #when book is open gameplay is freezed |         for event in events: | ||||||
|                     freeze = not freeze |             if event.type == pygame.QUIT: | ||||||
|         # RENDER YOUR GAME HERE |                 quitGame() | ||||||
|         """with open(background, 'r') as i: |             elif event.type == pygame.KEYDOWN: | ||||||
|             bg = pygame.image.load(i) |                 if event.key == pygame.K_e: #when book is open gameplay is freezed | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |                     freeze = not freeze | ||||||
|         # fill the screen with an image to clear the screen |         # RENDER YOUR GAME HERE | ||||||
|         screen.blit(bg, (0, 0)) |         """with open(background, 'r') as i: | ||||||
| """  |             bg = pygame.image.load(i) | ||||||
|         if not freeze: |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|             for thing in objects[0]: |         # fill the screen with an image to clear the screen | ||||||
|                 thing.book.hidden = not freeze |         screen.blit(bg, (0, 0)) | ||||||
|                 if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects): | """  | ||||||
|                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |         if not freeze: | ||||||
|                 thing.draw(screen) |             scene.update(False, objects) | ||||||
|          |             objects = scene.getObjects() | ||||||
|             for mob in objects[1]: |             screen.blit(scene.background, (32, 32)) | ||||||
|                 mob.update(objects) |             for thing in objects[3]: | ||||||
|                 mob.draw(screen) |                 thing.update(objects) | ||||||
|              |                 thing.draw(screen) | ||||||
|             for npc in objects[2]: |                  | ||||||
|                 npc.update(pygame.key.get_pressed(), objects) |             for thing in objects[0]: | ||||||
|                 npc.draw(screen) |                 thing.book.hidden = not freeze | ||||||
|              |                 if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects): | ||||||
|             for thing in objects[3]: |                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                 thing.update(objects) |                 thing.draw(screen) | ||||||
|                 thing.draw(screen) |          | ||||||
|         else: |             for mob in objects[1]: | ||||||
|             objects[0][0].book.hidden = not freeze |                 mob.update(objects) | ||||||
|             objects[0][0].book.draw(screen) |                 mob.draw(screen) | ||||||
|             objects[0][0].book.update() |              | ||||||
|         # flip() the display to put your work on screen |             for npc in objects[2]: | ||||||
|         pygame.display.flip() |                 npc.update(pygame.key.get_pressed(), objects) | ||||||
| 
 |                 npc.draw(screen) | ||||||
|         clock.tick(fps)  # limits FPS to 60 |              | ||||||
| 
 |             objects[0][0].book.addspell('windslash') | ||||||
| def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | 
 | ||||||
|     objects = [] |          | ||||||
|     # List that is displayed while selecting the window resolution level  |         else: | ||||||
|     resolution = [("1920x1080", "1920x1080"),  |             objects[0][0].book.hidden = not freeze | ||||||
|                   ("1920x1200", "1920x1200"),  |             objects[0][0].book.draw(screen) | ||||||
|                   ("1280x720", "1280x720"),  |             objects[0][0].book.update() | ||||||
|                   ("2560x1440", "2560x1440"),  |         # flip() the display to put your work on screen | ||||||
|                   ("3840x2160", "3840x2160")] |         pygame.display.flip() | ||||||
|      | 
 | ||||||
|     # This function displays the currently selected options  |         clock.tick(fps)  # limits FPS to 60 | ||||||
| 
 | 
 | ||||||
|     def printSettings():  | def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|         print("\n\n")  |     objects = [] | ||||||
|         # getting the data using "get_input_data" method of the Menu class  |     # List that is displayed while selecting the window resolution level  | ||||||
|         settingsData = settings.get_input_data()  |     resolution = [("1920x1080", "1920x1080"),  | ||||||
| 
 |                   ("1920x1200", "1920x1200"),  | ||||||
|         for key in settingsData.keys():  |                   ("1280x720", "1280x720"),  | ||||||
|             print(f"{key}\t:\t{settingsData[key]}")  |                   ("2560x1440", "2560x1440"),  | ||||||
|      |                   ("3840x2160", "3840x2160")] | ||||||
|     while running: |      | ||||||
|         for event in pygame.event.get(): |     # This function displays the currently selected options  | ||||||
|             if event.type == pygame.QUIT: | 
 | ||||||
|                 running = False  |     def printSettings():  | ||||||
|         # RENDER YOUR GAME HERE |         print("\n\n")  | ||||||
|         with open(background, 'r') as i: |         # getting the data using "get_input_data" method of the Menu class  | ||||||
|             bg = pygame.image.load(i) |         settingsData = settings.get_input_data()  | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | 
 | ||||||
|         # fill the screen with an image to clear the screen |         for key in settingsData.keys():  | ||||||
|         screen.blit(bg, (0, 0)) |             print(f"{key}\t:\t{settingsData[key]}")  | ||||||
|         for obj in objects: |      | ||||||
|             obj.process(screen) |     while running: | ||||||
| 
 |         for event in pygame.event.get(): | ||||||
|         # flip() the display to put your work on screen |             if event.type == pygame.QUIT: | ||||||
|         pygame.display.flip() |                 running = False  | ||||||
| 
 |         # RENDER YOUR GAME HERE | ||||||
|         clock.tick(60)  # limits FPS to 60 |         with open(background, 'r') as i: | ||||||
| 
 |             bg = pygame.image.load(i) | ||||||
| def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|     objects = [] |         # fill the screen with an image to clear the screen | ||||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Play", play)) |         screen.blit(bg, (0, 0)) | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) |         for obj in objects: | ||||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) |             obj.process(screen) | ||||||
|     while running: | 
 | ||||||
|         for event in pygame.event.get(): |         # flip() the display to put your work on screen | ||||||
|             if event.type == pygame.QUIT: |         pygame.display.flip() | ||||||
|                 running = False | 
 | ||||||
|                 quitGame() |         clock.tick(60)  # limits FPS to 60 | ||||||
|         # RENDER YOUR GAME HERE | 
 | ||||||
|         with open(f'art/images/{background}', 'r') as i: | def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|             bg = pygame.image.load(i) |     objects = [] | ||||||
|             bg = pygame.transform.scale(bg, (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])) | ||||||
|         # fill the screen with an image to clear the screen |     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) | ||||||
|         screen.blit(bg, (0, 0)) |     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) | ||||||
|         for obj in objects: |     while running: | ||||||
|             obj.update(screen, clock, running, background, isblack, WIDTH, HEIGHT) |         for event in pygame.event.get(): | ||||||
| 
 |             if event.type == pygame.QUIT: | ||||||
|         # flip() the display to put your work on screen |                 running = False | ||||||
|         pygame.display.flip() |                 quitGame() | ||||||
| 
 |         # RENDER YOUR GAME HERE | ||||||
|         clock.tick(60)  # limits FPS to 60 |         with open(f'art/images/{background}', 'r') as i: | ||||||
| 
 |             bg = pygame.image.load(i) | ||||||
| def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|     level = [] |         # fill the screen with an image to clear the screen | ||||||
|     rooms = genRooms(WIDTH, HEIGHT, 'grass') |         screen.blit(bg, (0, 0)) | ||||||
|     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) |         for obj in objects: | ||||||
|      |             obj.update(screen) | ||||||
|     level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ | 
 | ||||||
|         Room('red1', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), |         # flip() the display to put your work on screen | ||||||
|         Room('red2', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), |         pygame.display.flip() | ||||||
|         Room('red3', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), | 
 | ||||||
|             ])) |         clock.tick(60)  # limits FPS to 60 | ||||||
|      | 
 | ||||||
|     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) | def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
| 
 |     main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)] | ||||||
|     # RENDER YOUR GAME HERE |     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))] | ||||||
|     while True: |     others = [] | ||||||
|         for event in pygame.event.get(): |     npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)] | ||||||
|             if event.type == pygame.QUIT: |     objects = [main, mobs, npcs, others] | ||||||
|                 running = False |     level = [] | ||||||
|                 quitGame() |     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) | ||||||
|             screen.fill('#000000') |     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) | ||||||
|             scene.update(False) |     freeze = False #Gameplay is freezed in certain situations | ||||||
|             scene.draw(screen) |      | ||||||
|         # flip() the display to put your work on screen |     #level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ | ||||||
|         pygame.display.flip() |     #    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), | ||||||
|         clock.tick(60)  # limits FPS to 60 |     #    Room('red3', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), | ||||||
| 
 |     #        ])) | ||||||
| def main(): |      | ||||||
|     config = readConfig() |     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) | ||||||
|     screen, clock, running, isblack, background, objects = setUp(config["screen"]) | 
 | ||||||
|     WIDTH, HEIGHT = screen.get_size() |     # RENDER YOUR GAME HERE | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Play", play)) |     while True: | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) |         screen.fill('#000000') | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) |         events = pygame.event.get() | ||||||
|     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |         for event in events: | ||||||
|     test(screen, clock, running, background, isblack, WIDTH, HEIGHT) |             if event.type == pygame.QUIT: | ||||||
|      |                 running = False | ||||||
|     """while running: |                 quitGame() | ||||||
|         for event in pygame.event.get(): |             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 | ||||||
|         #menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                  | ||||||
|         if not isblack: |             if not freeze: | ||||||
|             with open(background, 'r') as i: |                 objects = scene.getObjects() | ||||||
|                 bg = pygame.image.load(i) |                 for thing in objects[0]: | ||||||
|                 bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |                     thing.book.hidden = not freeze | ||||||
|             # fill the screen with a color to wipe away anything from last frame |                     if not thing.update(pygame.key.get_pressed(), objects): | ||||||
|             screen.blit(bg, (0, 0)) |                         menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
| 
 |                     thing.draw(screen) | ||||||
|         # RENDER YOUR GAME HERE |              | ||||||
| 
 |                 for mob in objects[1]: | ||||||
|         else: |                     mob.update(objects) | ||||||
|             for obj in objects: |                     mob.draw(screen) | ||||||
|                 obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                  | ||||||
|         # flip() the display to put your work on screen |                 for npc in objects[2]: | ||||||
|         pygame.display.flip() |                     npc.update(pygame.key.get_pressed(), objects) | ||||||
| 
 |                     npc.draw(screen) | ||||||
|         clock.tick(60)  # limits FPS to 60""" |                  | ||||||
| 
 |                 for thing in objects[3]: | ||||||
|     pygame.quit() |                     thing.update(objects) | ||||||
| 
 |                     thing.draw(screen) | ||||||
| if __name__ == '__main__': | 
 | ||||||
|     main() |             else: | ||||||
|  |                 objects[0][0].book.hidden = not freeze | ||||||
|  |                 objects[0][0].book.draw(screen) | ||||||
|  |                 objects[0][0].book.update() | ||||||
|  |         # 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, 'textbox.png', 'medieval', 48, "Play", play)) | ||||||
|  |     #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)) | ||||||
|  |     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|  |     test(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() | ||||||
|  |  | ||||||
							
								
								
									
										760
									
								
								viecher.py
									
										
									
									
									
								
							
							
						
						
									
										760
									
								
								viecher.py
									
										
									
									
									
								
							|  | @ -1,373 +1,387 @@ | ||||||
| import pygame as pg | import pygame as pg | ||||||
| from classes import * | from classes import * | ||||||
| 
 | from main import * | ||||||
| vec = pg.math.Vector2 | 
 | ||||||
| fps = 60 | vec = pg.math.Vector2 | ||||||
| 
 | fps = 60 | ||||||
| 
 | 
 | ||||||
| pg.font.init() | 
 | ||||||
| fonts = { | pg.font.init() | ||||||
|     'medieval': 'medieval.ttf', | fonts = { | ||||||
|     'minecraft': 'Minecraft Evenings.otf', |     'medieval': 'medieval.ttf', | ||||||
|     '3dpixel': '3D-Pixel.ttf', |     'minecraft': 'Minecraft Evenings.otf', | ||||||
|     '8bit': '8bitlim.ttf', |     '3dpixel': '3D-Pixel.ttf', | ||||||
|     '8bito': '8blimro.ttf', |     '8bit': '8bitlim.ttf', | ||||||
|     'arcade': 'ARCADECLASSIC.ttf', |     '8bito': '8blimro.ttf', | ||||||
|     'modern_game': 'astron boy video.otf', |     'arcade': 'ARCADECLASSIC.ttf', | ||||||
|     'modern': 'astron boy.otf', |     'modern_game': 'astron boy video.otf', | ||||||
|     'wonder': 'Beyond Wonderland.ttf', |     'modern': 'astron boy.otf', | ||||||
|     'curved': 'Digitag.ttf', |     'wonder': 'Beyond Wonderland.ttf', | ||||||
|     'simple': 'DisposableDroidBB.ttf', |     'curved': 'Digitag.ttf', | ||||||
|     'rounded': 'dpcomic.ttf', |     'simple': 'DisposableDroidBB.ttf', | ||||||
|     'playfull': 'Endalian Script.ttf', |     'rounded': 'dpcomic.ttf', | ||||||
|     'blocky': 'FREAKSOFNATURE.ttf', |     'playfull': 'Endalian Script.ttf', | ||||||
|     'catchy': 'Future TimeSplitters.otf', |     'blocky': 'FREAKSOFNATURE.ttf', | ||||||
|     'simple_wide': 'Halo3.ttf', |     'catchy': 'Future TimeSplitters.otf', | ||||||
|     'simple_fat': 'INVASION2000.ttf', |     'simple_wide': 'Halo3.ttf', | ||||||
|     'very_gamy': 'ka1.ttf', |     'simple_fat': 'INVASION2000.ttf', | ||||||
|     'simple_round': 'Karma Suture.otf', |     'very_gamy': 'ka1.ttf', | ||||||
|     'mono': 'manaspc.ttf', |     'simple_round': 'Karma Suture.otf', | ||||||
|     'damaged': 'Merchant Copy.ttf', |     'mono': 'manaspc.ttf', | ||||||
|     'big_natural': 'MorialCitadel.TTF', |     'damaged': 'Merchant Copy.ttf', | ||||||
|     'spacy': 'nasalization-rg.otf', |     'big_natural': 'MorialCitadel.TTF', | ||||||
|     'sci-fi': 'neuropol.otf', |     'spacy': 'nasalization-rg.otf', | ||||||
|     'hollow_big_edge': 'papercut.ttf', |     'sci-fi': 'neuropol.otf', | ||||||
|     'space_shuttle': 'pdark.ttf', |     'hollow_big_edge': 'papercut.ttf', | ||||||
|     'thin': 'PixelFJVerdana12pt.ttf', |     'space_shuttle': 'pdark.ttf', | ||||||
|     'random': 'Seattle Avenue.ttf', |     'thin': 'PixelFJVerdana12pt.ttf', | ||||||
|     'pixel': 'yoster.ttf' |     'random': 'Seattle Avenue.ttf', | ||||||
| } |     'pixel': 'yoster.ttf' | ||||||
| 
 | } | ||||||
| class Objects(): | 
 | ||||||
|     def __init__(self, name, ms, sprite, x, y) -> None: | class Objects(): | ||||||
|         self.name = name |     def __init__(self, name, ms, sprite, x, y) -> None: | ||||||
|         self.speed = ms |         self.name = name | ||||||
|         with open(f'art/images/{sprite}') as i: |         self.speed = ms | ||||||
|             self.sprite = pg.image.load(i) |         with open(f'art/images/{sprite}') as i: | ||||||
|         self.x = x |             self.sprite = pg.image.load(i) | ||||||
|         self.y = y |         self.x = x | ||||||
|         self.hidden = False |         self.y = y | ||||||
|         self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) |         self.hidden = False | ||||||
|      |         self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) | ||||||
|     def draw(self, screen): |      | ||||||
|         if self.hidden: |     def draw(self, screen): | ||||||
|             return |         if self.hidden: | ||||||
|         self.rect.x, self.rect.y = self.x, self.y |             return | ||||||
|         screen.blit(self.sprite, self.rect) |         self.rect.x, self.rect.y = self.x, self.y | ||||||
| 
 |         screen.blit(self.sprite, self.rect) | ||||||
| class NPC(Objects): |         pg.draw.rect(screen, '#ff0000', self.rect,  2) | ||||||
|     def __init__(self, name, ms, sprite, convo_act, x, y) -> None: | 
 | ||||||
|         self.talking = False | class NPC(Objects): | ||||||
|         self.hidden = True |     def __init__(self, name, ms, sprite, convo_act, x, y) -> None: | ||||||
|         super().__init__(name, ms, sprite, x, y) |         self.talking = False | ||||||
|         self.conversation = Convo('Hello, you can shoot fireballs with f now.', convo_act, 'person') |         self.hidden = True | ||||||
|      |         super().__init__(name, ms, sprite, x, y) | ||||||
|     def talk(self, objects): |         self.conversation = Convo('Hello, you can shoot fireballs with f now.', convo_act, 'person') | ||||||
|         self.talking = True |      | ||||||
|         objects[0][0].talking = True |     def talk(self, objects): | ||||||
|         self.conversation.hidden = False |         self.talking = True | ||||||
|      |         objects[0][0].talking = True | ||||||
|     def draw(self, screen): |         self.conversation.hidden = False | ||||||
|         super().draw(screen) |      | ||||||
|         if self.talking == True: |     def draw(self, screen): | ||||||
|             self.conversation.draw(screen) |         super().draw(screen) | ||||||
|      |         if self.talking == True: | ||||||
|     def update(self, keys, objects): |             self.conversation.draw(screen) | ||||||
|         if self.talking: |      | ||||||
|             self.conversation.update(keys, objects) |     def update(self, keys, objects): | ||||||
| 
 |         if self.talking: | ||||||
| class Convo(): |             self.conversation.update(keys, objects) | ||||||
|     def __init__(self, text, convo_act, person, x = 140, y = 600, width = 1000, height = 100, font='simple', font_size = 20) -> None: | 
 | ||||||
|         self.x = x | class Convo(Label): | ||||||
|         self.y = y |     def __init__(self, text, convo_act, person, x = 140, y = 600, width = 1000, height = 100, font='simple', font_size = 20) -> None: | ||||||
|         self.width = width |         super().__init__(x, y, width, height, text, font, font_size) | ||||||
|         self.height = height |      | ||||||
|         self.hidden = False |     def update(self, keys, objects): | ||||||
|         self.font = pg.font.Font(f'fonts/{fonts[font]}', font_size) |         if keys[pg.K_SPACE]: | ||||||
|         with open('art/images/label.png', 'r') as tb: |             objects[0][0].book.addspell('fireball') | ||||||
|             self.box = pg.image.load(tb) |             self.talking = False | ||||||
|             self.box = pg.transform.scale(self.box, (width, height)) |             objects[0][0].talking = False | ||||||
|         self.labelRect = pg.Rect(self.x, self.y, self.width, self.height) |             self.hidden = True | ||||||
|         self.labelSurf = self.font.render(text, True, '#1E90FF') | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     def draw(self, screen): | 
 | ||||||
|         if self.hidden: | class Fighter(Objects): | ||||||
|             return |     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: | ||||||
|         self.box.blit(self.labelSurf, [ |         super().__init__(name, ms, sprite, x, y) | ||||||
|             self.labelRect.width/2 - self.labelSurf.get_rect().width/2, |         self.health = health | ||||||
|             self.labelRect.height/2 - self.labelSurf.get_rect().height/2 |         self.damage = damage | ||||||
|         ]) |         self.level = level | ||||||
|         screen.blit(self.box, self.labelRect) |         self.attack_speed = asp | ||||||
|      |         self.attack_range = atr | ||||||
|     def update(self, keys, objects): |         self.lastHurt = pg.time.get_ticks() | ||||||
|         if keys[pg.K_SPACE]: |         self.lastAttack = pg.time.get_ticks() | ||||||
|             objects[0][0].book.addspell('fireball') |         self.hurtCooldown = 0 | ||||||
|             self.talking = False | 
 | ||||||
|             objects[0][0].talking = False | 
 | ||||||
|             self.hidden = True | class MainCharacter(Fighter): | ||||||
| 
 |     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: | ||||||
| 
 |         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) | ||||||
| 
 |         self.book = Book(0, 0, [], None, None) | ||||||
| 
 |         self.talking = False | ||||||
| class Fighter(Objects): |         self.level = Level(1000, 38, 150, 40, f'will to live: {level}%', 'simple', 20) | ||||||
|     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: |         self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y= 50, hurtCooldown=self.hurtCooldown) | ||||||
|         super().__init__(name, ms, sprite, x, y) |      | ||||||
|         self.health = health |     def draw(self, screen): | ||||||
|         self.damage = damage |         if self.hidden: | ||||||
|         self.level = level |             return | ||||||
|         self.attack_speed = asp |         self.rect.x, self.rect.y = self.x, self.y | ||||||
|         self.attack_range = atr |         screen.blit(self.sprite, self.rect) | ||||||
|         self.lastHurt = pg.time.get_ticks() |         self.health.draw(screen) | ||||||
|         self.lastAttack = pg.time.get_ticks() |         self.level.draw(screen) | ||||||
|         self.hurtCooldown = 0 |         self.book.draw(screen) | ||||||
| 
 |         pg.draw.rect(screen, '#ff00ee', self.rect, 2) | ||||||
| 
 | 
 | ||||||
| class MainCharacter(Fighter): |     def hurt(self, damage, objects): | ||||||
|     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: |         if not self.talking: | ||||||
|         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) |             self.health.hurt(damage) | ||||||
|         self.book = Book(0, 0, [], None, None) |      | ||||||
|         self.talking = False |     def walk(self, keys, objects): | ||||||
|         self.level = Level(1000, 38, level, 150, 40, f'will to live: {level}%', 'simple', 20) |         moveto = vec(0, 0) | ||||||
|         self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y= 50, hurtCooldown=self.hurtCooldown) |         if keys[pg.K_w] or keys[pg.K_UP]: | ||||||
|      |             moveto += vec(0, -1) | ||||||
|     def draw(self, screen): |         if keys[pg.K_a] or keys[pg.K_LEFT]: | ||||||
|         if self.hidden: |             moveto += vec(-1, 0) | ||||||
|             return |         if keys[pg.K_s] or keys[pg.K_DOWN]: | ||||||
|         self.rect.x, self.rect.y = self.x, self.y |             moveto += vec(0, 1) | ||||||
|         screen.blit(self.sprite, self.rect) |         if keys[pg.K_d] or keys[pg.K_RIGHT]: | ||||||
|         self.health.draw(screen) |             moveto += vec(1, 0) | ||||||
|         self.level.draw(screen) |         if not moveto == vec(0, 0): | ||||||
|         self.book.draw(screen) |             moveto.scale_to_length(self.speed) | ||||||
| 
 | 
 | ||||||
|     def hurt(self, damage, objects): |         self.x += moveto[0] / fps | ||||||
|         if not self.talking: |         self.y += moveto[1] / fps  | ||||||
|             self.health.hurt(damage) |         touches = pg.sprite.spritecollideany(self, objects[1] + objects[2] + objects[3]) | ||||||
|      |         if touches is not None and not isinstance(touches, Weapons): | ||||||
|     def walk(self, keys, objects): |             if isinstance(touches, Obstacle): | ||||||
|         moveto = vec(0, 0) |                 if not touches.collision: | ||||||
|         if keys[pg.K_w] or keys[pg.K_UP]: |                     return | ||||||
|             moveto += vec(0, -1) |                 if touches.type == 'wall': | ||||||
|         if keys[pg.K_a] or keys[pg.K_LEFT]: |                     if touches.name == 'wall_l': | ||||||
|             moveto += vec(-1, 0) |                         self.x += (2 + (self.x - touches.rect.x)) | ||||||
|         if keys[pg.K_s] or keys[pg.K_DOWN]: |                     elif touches.name == 'wall_r': | ||||||
|             moveto += vec(0, 1) |                         self.x -= (2 + self.rect.width - (touches.rect.x - self.x)) | ||||||
|         if keys[pg.K_d] or keys[pg.K_RIGHT]: |                     if touches.name == 'wall_t': | ||||||
|             moveto += vec(1, 0) |                         self.y += (2 + (self.y - touches.rect.y)) | ||||||
|         if not moveto == vec(0, 0): |                     elif touches.name == 'wall_b': | ||||||
|             moveto.scale_to_length(self.speed) |                         self.y -= (2 + self.rect.height - (touches.rect.y - self.y)) | ||||||
|         self.x += moveto[0] / fps |                     return | ||||||
|         self.y += moveto[1] / fps  |                  | ||||||
|         touches = pg.sprite.spritecollideany(self, objects[1] + objects[2]) |             if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x)) | ||||||
|         if touches is not None: |             elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x)) | ||||||
|             self.x -= moveto[0]*1.5 / fps #change later |             #if self.y <= touches.y: pass | ||||||
|             self.y -= moveto[1]*1.5 / fps #change later |             #elif self.y > touches.y: pass | ||||||
|             if isinstance(touches, NPC): |             self.x -= moveto[0] * 2 / fps | ||||||
|                     touches.talk(objects) |             self.y -= moveto[1] * 2 / fps | ||||||
|      |             if isinstance(touches, NPC): | ||||||
|     def attack(self, obj, mouse): |                     touches.talk(objects) | ||||||
|         if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): |         """ | ||||||
|             moveto = mouse- vec(self.x, self.y) |         if self.x <= 32: | ||||||
|             if self.book.current_sp == 'fireball': |             self.x = 33 | ||||||
|                 weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5) |         elif self.x >= objects[3][0].width - 32: | ||||||
|             else: |             self.x = objects[3][0].width - 32 - self.rect.width + 1 | ||||||
|                 return |         if self.y <= 32: | ||||||
|             obj[3].append(weapon) |             self.y = 33 | ||||||
|             self.lastAttack = pg.time.get_ticks() |         elif self.y >= objects[3][0].height - 32: | ||||||
| 
 |             self.y = objects[3][0].height - 32 - self.rect.height + 1 | ||||||
|     def update(self, keys, mouse, objects): |         """ | ||||||
|         if not self.talking: |      | ||||||
|             self.walk(keys, objects) |     def attack(self, obj, mouse): | ||||||
|             if keys[pg.K_f]: |         if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): | ||||||
|                 self.attack(objects, vec(mouse)) |             moveto = mouse- vec(self.x, self.y) | ||||||
|         if self.health.health <= 0: |             if self.book.current_sp == 'fireball': | ||||||
|             return False |                 weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5) | ||||||
|         else: |             elif self.book.current_sp == 'windslash': | ||||||
|             return True |                 weapon = Windslash('ws1', 100, self.x, self.y, moveto, 5) | ||||||
| 
 |             else: | ||||||
| class Hearts(): |                 return | ||||||
|     def __init__(self, health, sprite, x, y, hurtCooldown) -> None: |             obj[3].append(weapon) | ||||||
|         self.x = x |             self.lastAttack = pg.time.get_ticks() | ||||||
|         self.y = y | 
 | ||||||
|         self.health = health |     def update(self, keys, mouse, objects): | ||||||
|         self.lastHurt = pg.time.get_ticks() |         if not self.talking: | ||||||
|         self.hurtCooldown = hurtCooldown |             self.walk(keys, objects) | ||||||
|         self.hidden = False |             if keys[pg.K_f]: | ||||||
|         self.sprite=[] |                 self.attack(objects, vec(mouse)) | ||||||
|         for parts in sprite: |         if self.health.health <= 0: | ||||||
|             with open(f'art/images/{parts}') as i: |             return False | ||||||
|                 self.sprite.append(pg.image.load(i)) |         else: | ||||||
|         self.rect = [] |             return True | ||||||
|         for each in self.sprite: | 
 | ||||||
|             self.rect.append(pg.Rect(self.x, self.y, each.get_width(), each.get_height())) | class Hearts(): | ||||||
|          |     def __init__(self, health, sprite, x, y, hurtCooldown) -> None: | ||||||
|     def hurt(self,damage): |         self.x = x | ||||||
|         if self.lastHurt + self.hurtCooldown < pg.time.get_ticks(): |         self.y = y | ||||||
|             self.health -= damage |         self.health = health | ||||||
|             self.lastHurt = pg.time.get_ticks() |         self.lastHurt = pg.time.get_ticks() | ||||||
|             self.update() |         self.hurtCooldown = hurtCooldown | ||||||
| 
 |         self.hidden = False | ||||||
|     def draw(self, screen): |         self.sprite=[] | ||||||
|         if self.hidden: |         for parts in sprite: | ||||||
|             return |             with open(f'art/images/{parts}') as i: | ||||||
|         for i in range(0, 5): |                 self.sprite.append(pg.image.load(i)) | ||||||
|             self.rect[i].x, self.rect[i].y = self.x + i * 20, self.y |         self.rect = [] | ||||||
|             screen.blit(self.sprite[i], self.rect[i]) |         for each in self.sprite: | ||||||
|      |             self.rect.append(pg.Rect(self.x, self.y, each.get_width(), each.get_height())) | ||||||
|     def update(self): |          | ||||||
|         sprite = [] |     def hurt(self,damage): | ||||||
|         for i in range(0, 5): |         if self.lastHurt + self.hurtCooldown < pg.time.get_ticks(): | ||||||
|             if self.health >= 4 + 4 * i: |             self.health -= damage | ||||||
|                 sprite.append('fullheart.png') |             self.lastHurt = pg.time.get_ticks() | ||||||
|             elif self.health == 3 + 4 * i: |             self.update() | ||||||
|                 sprite.append('dreiviertelheart.png') | 
 | ||||||
|             elif self.health >= 2 + 4 * i: |     def draw(self, screen): | ||||||
|                 sprite.append('halfheart.png') |         if self.hidden: | ||||||
|             elif self.health >= 1 + 4 * i: |             return | ||||||
|                 sprite.append('viertelheart.png') |         for i in range(0, 5): | ||||||
|             elif self.health <= 4 * i: |             self.rect[i].x, self.rect[i].y = self.x + i * 20, self.y | ||||||
|                 sprite.append('noheart.png')   |             screen.blit(self.sprite[i], self.rect[i]) | ||||||
|         self.sprite = [] |      | ||||||
|         for parts in sprite: |     def update(self): | ||||||
|             with open(f'art/images/{parts}') as i: |         sprite = [] | ||||||
|                 self.sprite.append(pg.image.load(i)) |         for i in range(0, 5): | ||||||
| 
 |             if self.health >= 4 + 4 * i: | ||||||
| 
 |                 sprite.append('fullheart.png') | ||||||
| class Level(): |             elif self.health == 3 + 4 * i: | ||||||
|     def __init__(self, x, y, level, width, height, text, font, font_size) -> None: |                 sprite.append('dreiviertelheart.png') | ||||||
|         self.x = x |             elif self.health >= 2 + 4 * i: | ||||||
|         self.y = y |                 sprite.append('halfheart.png') | ||||||
|         self.level = level |             elif self.health >= 1 + 4 * i: | ||||||
|         self.width = width |                 sprite.append('viertelheart.png') | ||||||
|         self.height = height |             elif self.health <= 4 * i: | ||||||
|         self.font = pg.font.Font(f'fonts/{fonts[font]}', font_size) |                 sprite.append('noheart.png')   | ||||||
|         self.hidden = False |         self.sprite = [] | ||||||
|         with open('art/images/label.png', 'r') as tb: |         for parts in sprite: | ||||||
|             self.box = pg.image.load(tb) |             with open(f'art/images/{parts}') as i: | ||||||
|             self.box = pg.transform.scale(self.box, (width, height)) |                 self.sprite.append(pg.image.load(i)) | ||||||
|         self.labelRect = pg.Rect(self.x, self.y, self.width, self.height) | 
 | ||||||
|         self.labelSurf = self.font.render(text, True, '#1E90FF') | 
 | ||||||
| 
 | class Level(Label): | ||||||
|     def draw(self, screen): |     def __init__(self, x, y, width, height, text, font, font_size) -> None: | ||||||
|         self.box.blit(self.labelSurf, [ |         super().__init__(x, y, width, height, text, font, font_size) | ||||||
|             self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2, | 
 | ||||||
|             self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2 | class Book(): | ||||||
|         ]) |     def __init__(self, x, y, spells, current_spell, current_shield) -> None: | ||||||
|         screen.blit(self.box, self.labelRect) |         with open(f'art/images/book.png') as i: | ||||||
| 
 |             self.sprite = pg.image.load(i) | ||||||
| class Book(): |             self.sprite = pg.transform.scale(self.sprite, (1280, 720)) | ||||||
|     def __init__(self, x, y, spells, current_spell, current_shield) -> None: |         self.x = x | ||||||
|         with open(f'art/images/book.png') as i: |         self.y = y | ||||||
|             self.sprite = pg.image.load(i) |         self.hidden = True | ||||||
|             self.sprite = pg.transform.scale(self.sprite, (1280, 720)) |         self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) | ||||||
|         self.x = x |         self.sp_list = spells | ||||||
|         self.y = y |         self.current_sp = current_spell | ||||||
|         self.hidden = True |         self.labels = [Label(100, 100, 500, 50, "Dear User, ", font_color='#000000', sprite='empty.png'), | ||||||
|         self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) |                        Label(100, 150, 500, 50, "this book will help you to survive.", font_color='#000000', sprite='empty.png'), | ||||||
|         self.sp_list = spells |                        Label(100, 200, 500, 50, "Click on a picture to choose your spell.", font_color='#000000', sprite='empty.png'), | ||||||
|         self.current_sp = current_spell |                        Label(100, 250, 500, 50, "Talk to fairies to unlock new spells!", font_color='#000000', sprite='empty.png')] | ||||||
|         self.buttons=[] |         self.buttons=[] | ||||||
|         self.buttons_height = 150 |         self.buttons_height = 400 | ||||||
|      |      | ||||||
|     def draw(self, screen): |     def draw(self, screen): | ||||||
|         if self.hidden: |         if self.hidden: | ||||||
|             return |             return | ||||||
|         self.rect.x, self.rect.y = self.x, self.y |         self.rect.x, self.rect.y = self.x, self.y | ||||||
|         screen.blit(self.sprite, self.rect) |         screen.blit(self.sprite, self.rect) | ||||||
|         for button in self.buttons: |         for label in self.labels: | ||||||
|             button.update(screen) |             label.draw(screen) | ||||||
|      |         for button in self.buttons: | ||||||
|     def addspell(self, spell): |             button.update(screen) | ||||||
|         if spell not in self.sp_list: |      | ||||||
|             self.sp_list.append(spell) |     def addspell(self, spell): | ||||||
|             self.current_sp = spell |         if spell not in self.sp_list: | ||||||
|             self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}.png', 'medieval', 23)) |             self.sp_list.append(spell) | ||||||
|             self.buttons_height += 100 |             self.current_sp = spell | ||||||
| 
 |             self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}_icon.png', 'medieval', 23, attributes=[spell], onclickFunction=self.update_spell)) | ||||||
|     def update_spell(self): |             self.buttons_height += 100 | ||||||
|         self.current_sp = None | 
 | ||||||
|          |     def update_spell(self, spell): | ||||||
|     def update(self): |         self.current_sp = spell | ||||||
|         pass | 
 | ||||||
| 
 |     def update(self): | ||||||
| class Mobs(Fighter): |         pass | ||||||
|     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None: | class Mobs(Fighter): | ||||||
|         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) |     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None: | ||||||
|         self.drops = drops * (self.level / 2) |         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) | ||||||
| 
 |         self.drops = drops * (self.level / 2) | ||||||
| class Skeleton(Mobs): | 
 | ||||||
|     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops=0) -> None: | class Skeleton(Mobs): | ||||||
|         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops) |     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops=0) -> None: | ||||||
|      |         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops) | ||||||
|     def chase(self, obj): |      | ||||||
|         x = obj[0][0].x |     def chase(self, obj): | ||||||
|         y = obj[0][0].y |         x = obj[0][0].x | ||||||
|         moveto = vec(x, y) - vec(self.x, self.y) |         y = obj[0][0].y | ||||||
|         if not (moveto).length() <= self.attack_range: |         moveto = vec(x, y) - vec(self.x, self.y) | ||||||
|             moveto.scale_to_length(self.speed) |         if not (moveto).length() <= self.attack_range: | ||||||
|             self.x += moveto[0] / fps |             moveto.scale_to_length(self.speed) | ||||||
|             self.y += moveto[1] / fps |             self.x += moveto[0] / fps | ||||||
|         else: |             self.y += moveto[1] / fps | ||||||
|             self.attack(moveto, obj) |         else: | ||||||
| 
 |             self.attack(moveto, obj) | ||||||
|     def attack(self, moveto, obj): | 
 | ||||||
|         if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): |     def attack(self, moveto, obj): | ||||||
|             obj[3].append(Arrow("arrow", 200, self.x, self.y, moveto, self.damage)) |         if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): | ||||||
|             self.lastAttack = pg.time.get_ticks() |             obj[3].append(Arrow("arrow", 200, self.x, self.y, moveto, self.damage)) | ||||||
|      |             self.lastAttack = pg.time.get_ticks() | ||||||
|     def hurt(self, damage, objects): |      | ||||||
|         self.health -= damage |     def hurt(self, damage, objects): | ||||||
|         if self.health <= 0: |         self.health -= damage | ||||||
|             self.hidden = True |         if self.health <= 0: | ||||||
|             objects[1].remove(self) |             self.hidden = True | ||||||
| 
 |             objects[1].remove(self) | ||||||
|     def update(self, obj): | 
 | ||||||
|         self.chase(obj) |     def update(self, obj): | ||||||
| 
 |         self.chase(obj) | ||||||
| 
 | 
 | ||||||
| class Weapons(Objects): | 
 | ||||||
|     def __init__(self, name, ms, sprite, x, y, moveto, damage) -> None: | class Weapons(Objects): | ||||||
|         super().__init__(name, ms, sprite, x, y) |     def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None: | ||||||
|         self.moveto = moveto |         super().__init__(name, ms, sprite, x, y) | ||||||
|         self.damage = damage |         self.moveto = moveto | ||||||
|         pos = vec(1,0) |         self.damage = damage | ||||||
|         angle = pos.angle_to(moveto) |         self.life_ticks= life_ticks | ||||||
|         with open(f'art/images/{sprite}') as i: |         self.spawn_tick = pg.time.get_ticks() | ||||||
|             self.sprite = pg.transform.rotate(pg.image.load(i), -angle) |         pos = vec(1,0) | ||||||
|      |         angle = pos.angle_to(moveto) | ||||||
|     def die(self, objects, kills): |         with open(f'art/images/{sprite}') as i: | ||||||
|         touches = pg.sprite.spritecollideany(self, objects[0] + objects[1]) |             self.sprite = pg.transform.rotate(pg.image.load(i), -angle) | ||||||
|         if touches is not None and isinstance(touches, kills): |      | ||||||
|             touches.hurt(self.damage, objects) |     def die(self, objects, kills): | ||||||
|             self.hidden = True |         touches = pg.sprite.spritecollideany(self, objects[0] + objects[1]) | ||||||
|             objects[3].remove(self) |         if touches is not None and isinstance(touches, kills): | ||||||
| 
 |             touches.hurt(self.damage, objects) | ||||||
| class Spells(Weapons): |             self.hidden = True | ||||||
|     def __init__(self, name, ms, sprite, x, y, moveto, damage) -> None: |             objects[3].remove(self) | ||||||
|         super().__init__(name, ms, sprite, x, y, moveto, damage) |              | ||||||
| 
 |     def move(self, objects): | ||||||
| class Fireball(Spells): |         self.moveto.scale_to_length(self.speed) | ||||||
|     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'fireball.png') -> None: |         self.x += self.moveto[0] / fps | ||||||
|         super().__init__(name, ms, sprite, x, y, moveto, damage) |         self.y += self.moveto[1] / fps | ||||||
|      |         if pg.time.get_ticks() - self.spawn_tick > self.life_ticks: | ||||||
|     def move(self): |             self.hidden = True | ||||||
|         self.moveto.scale_to_length(self.speed) |             objects[3].remove(self) | ||||||
|         self.x += self.moveto[0] / fps | 
 | ||||||
|         self.y += self.moveto[1] / fps | class Spells(Weapons): | ||||||
|      |     def __init__(self, name, ms, sprite, x, y, moveto, damage, life_ticks) -> None: | ||||||
|     def update(self, objects): |         super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) | ||||||
|         self.move() | 
 | ||||||
|         self.die(objects, Mobs) | class Fireball(Spells): | ||||||
|          |     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'fireball.png', life_ticks=5000) -> None: | ||||||
| class Arrow(Weapons): |         super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) | ||||||
|     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'arrow.png') -> None: |      | ||||||
|         super().__init__(name, ms, sprite, x, y, moveto, damage) |     def update(self, objects): | ||||||
| 
 |         self.move(objects) | ||||||
|     def move(self): |         self.die(objects, Mobs) | ||||||
|         self.moveto.scale_to_length(self.speed) | 
 | ||||||
|         self.x += self.moveto[0] / fps | class Windslash(Spells): | ||||||
|         self.y += self.moveto[1] / fps |     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'windslash.png', life_ticks=500) -> None: | ||||||
|      |         super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) | ||||||
|     def update(self, objects): |      | ||||||
|         self.move() |     def update(self, objects): | ||||||
|         self.die(objects, MainCharacter) |         self.move(objects) | ||||||
|  |         self.die(objects, Mobs) | ||||||
|  |      | ||||||
|  |     def move(self, objects): | ||||||
|  |         super().move(objects) | ||||||
|  |         self.moveto = self.moveto.rotate(5) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Arrow(Weapons): | ||||||
|  |     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'arrow.png', life_ticks=5000) -> None: | ||||||
|  |         super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) | ||||||
|  |      | ||||||
|  |     def update(self, objects): | ||||||
|  |         self.move(objects) | ||||||
|  |         self.die(objects, MainCharacter) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue