forked from InfoProjekt/game
		
	Compare commits
	
		
			3 commits
		
	
	
		
			ea6d64b087
			...
			8f78002015
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 8f78002015 | ||
|   | 4e1674d6f3 | ||
|   | 2e66145dcc | 
					 7 changed files with 139 additions and 24 deletions
				
			
		
							
								
								
									
										16
									
								
								READ.ME
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								READ.ME
									
										
									
									
									
								
							|  | @ -36,4 +36,18 @@ fonts = { | |||
|     'pixel': 'yoster.ttf' | ||||
| } | ||||
| 
 | ||||
| Pygame window: (0, 0) is in the top left corner, the height and width are stored in HEIGHT and WIDTH | ||||
| Pygame window: (0, 0) is in the top left corner, the height and width are stored in HEIGHT and WIDTH | ||||
| 
 | ||||
| GameObjects for rooms, scenes and maybe MorialCitadel | ||||
| 
 | ||||
| Scene: | ||||
|     type - normal, dungeon, cutscene | ||||
|     objects - contain rooms, npcs, mobs, the character etc. | ||||
| 
 | ||||
| Room: | ||||
|     type - normal, shop, special (?), boss | ||||
|     objects - npcs, mobs, the character etc. | ||||
|     exits - position of exits --> [top:bool, right:bool, down:bool, left:bool]; 1 to 4 exits per room | ||||
|     locked - bool if the room is unlocked; locked upon first entering unless all mobs are dead | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								art/images/reddy.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/reddy.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 654 B | 
							
								
								
									
										
											BIN
										
									
								
								art/images/start.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/start.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.3 MiB | 
| Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B | 
							
								
								
									
										34
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								classes.py
									
										
									
									
									
								
							|  | @ -44,7 +44,7 @@ class Button(): | |||
|         self.onePress = onePress | ||||
|         self.alreadyPressed = False | ||||
| 
 | ||||
|         with open('art/textbox.png', 'r') as tb: | ||||
|         with open('art/images/textbox.png', 'r') as tb: | ||||
|             self.box = pygame.image.load(tb) | ||||
|             self.box = pygame.transform.scale(self.box, (width, height)) | ||||
| 
 | ||||
|  | @ -53,15 +53,19 @@ class Button(): | |||
| 
 | ||||
|         self.buttonSurf = self.font.render(buttonText, True, '#baab80') | ||||
| 
 | ||||
|     def process(self, screen): | ||||
|     def process(self, screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||
|         mousePos = pygame.mouse.get_pos() | ||||
|         if self.buttonRect.collidepoint(mousePos): | ||||
|             if pygame.mouse.get_pressed(num_buttons=3)[0]: | ||||
|                 if self.onePress: | ||||
|                     self.onclickFunction() | ||||
|                 elif not self.alreadyPressed: | ||||
|                     self.onclickFunction() | ||||
|                     self.alreadyPressed = True | ||||
|                     if 'play' in str(self.onclickFunction): | ||||
|                         self.onclickFunction(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||
|                         self.alreadyPressed = True | ||||
|                     else: | ||||
|                         self.onclickFunction() | ||||
|                         self.alreadyPressed = True | ||||
|             else: | ||||
|                 self.alreadyPressed = False | ||||
|         self.box.blit(self.buttonSurf, [ | ||||
|  | @ -81,7 +85,7 @@ class DropDown(): | |||
|         self.menu_active = False | ||||
|         self.active_option = -1 | ||||
| 
 | ||||
|         with open('art/textbox.png', 'r') as tb: | ||||
|         with open('art/images/textbox.png', 'r') as tb: | ||||
|             self.box = pygame.image.load(tb) | ||||
|             self.box = pygame.transform.scale(self.box, (width, height)) | ||||
| 
 | ||||
|  | @ -133,4 +137,24 @@ class DropDown(): | |||
|         return -1 | ||||
| 
 | ||||
| 
 | ||||
| class GameObjects(): | ||||
|     def __init__(self, name:str, _type:str, bg, objects:list) -> None: | ||||
|         self.name = name | ||||
|         self.type = _type | ||||
|         self.background = bg | ||||
|         self.objects = objects | ||||
| 
 | ||||
| 
 | ||||
| class Scene(GameObjects): | ||||
|     def __init__(self, name:str, _type:str, bg, objects:list) -> None: | ||||
|         super().__init__(name, _type, bg, objects) | ||||
| 
 | ||||
| 
 | ||||
| class Room(GameObjects): | ||||
|     def __init__(self, name:str, _type:str, bg, objects:list, exits:list) -> None: | ||||
|         super().__init__(name, _type, bg, objects) | ||||
|         self.exits = exits | ||||
|         if self.type == 'normal' or self.type == 'boss': | ||||
|             self.locked = True | ||||
|         else: | ||||
|             self.locked = False | ||||
|  |  | |||
							
								
								
									
										57
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										57
									
								
								main.py
									
										
									
									
									
								
							|  | @ -3,6 +3,8 @@ import sys | |||
| import json | ||||
| import time | ||||
| from classes import * | ||||
| from viecher import * | ||||
| fps = 60 | ||||
| 
 | ||||
| def setUp(config): | ||||
|     pygame.init() | ||||
|  | @ -22,10 +24,31 @@ def readConfig(): | |||
| def quitGame(): | ||||
|     #save progress somehow, if needed | ||||
|     pygame.quit() | ||||
|     sys.exit() | ||||
|     quit() | ||||
| 
 | ||||
| def uwu(): | ||||
|     print('uwu') | ||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||
|     objects = [] | ||||
|     objects.append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) | ||||
|     while running: | ||||
|         screen.fill('#000000') | ||||
|         events = pygame.event.get() | ||||
|         for event in events: | ||||
|             if event.type == pygame.QUIT: | ||||
|                 quitGame() | ||||
|         # RENDER YOUR GAME HERE | ||||
|         """with open(background, 'r') as i: | ||||
|             bg = pygame.image.load(i) | ||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||
|         # fill the screen with an image to clear the screen | ||||
|         screen.blit(bg, (0, 0)) | ||||
| """  | ||||
|         for obj in objects: | ||||
|             obj.update(pygame.key.get_pressed()) | ||||
|             obj.draw(screen) | ||||
|         # flip() the display to put your work on screen | ||||
|         pygame.display.flip() | ||||
| 
 | ||||
|         clock.tick(fps)  # limits FPS to 60 | ||||
| 
 | ||||
| def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||
|     objects = [] | ||||
|  | @ -66,21 +89,22 @@ def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | |||
| 
 | ||||
| def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||
|     objects = [] | ||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Play", play)) | ||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Options", uwu)) | ||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) | ||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu)) | ||||
|     objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", uwu)) | ||||
|     while running: | ||||
|         for event in pygame.event.get(): | ||||
|             if event.type == pygame.QUIT: | ||||
|                 running = False  | ||||
|                 running = False | ||||
|                 quitGame() | ||||
|         # RENDER YOUR GAME HERE | ||||
|         with open(background, 'r') as i: | ||||
|         with open(f'art/images/{background}', 'r') as i: | ||||
|             bg = pygame.image.load(i) | ||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||
|         # fill the screen with an image to clear the screen | ||||
|         screen.blit(bg, (0, 0)) | ||||
|         for obj in objects: | ||||
|             obj.process(screen) | ||||
|             obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||
| 
 | ||||
|         # flip() the display to put your work on screen | ||||
|         pygame.display.flip() | ||||
|  | @ -91,9 +115,11 @@ def main(): | |||
|     config = readConfig() | ||||
|     screen, clock, running, isblack, background, objects = setUp(config["screen"]) | ||||
|     WIDTH, HEIGHT = screen.get_size() | ||||
|     list1 = DropDown(50, 50, 128, 48, 'simple', 32, ['#881188', '#220044'], ['#991122', '#33ff11'], 'Test', ['Test 2', 'Test 17', '982']) | ||||
|      | ||||
|     while running: | ||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", play)) | ||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu)) | ||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) | ||||
|     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||
|     """while running: | ||||
|         for event in pygame.event.get(): | ||||
|             if event.type == pygame.QUIT: | ||||
|                 running = False  | ||||
|  | @ -108,17 +134,12 @@ def main(): | |||
|         # RENDER YOUR GAME HERE | ||||
| 
 | ||||
|         else: | ||||
|             selected_option = list1.update(pygame.event.get()) | ||||
|             if selected_option >= 0: | ||||
|                 list1.main = list1.options[selected_option] | ||||
|             screen.fill('#000000') | ||||
|             list1.draw(screen) | ||||
|             for obj in objects: | ||||
|                 obj.process(screen) | ||||
|                 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 | ||||
|         clock.tick(60)  # limits FPS to 60""" | ||||
| 
 | ||||
|     pygame.quit() | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										56
									
								
								viecher.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								viecher.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,56 @@ | |||
| import pygame | ||||
| fps = 60 | ||||
| 
 | ||||
| class Character(): | ||||
|     def __init__(self, name, ms, sprite) -> None: | ||||
|         self.name = name | ||||
|         self.speed = ms | ||||
|         with open(f'art/images/{sprite}') as i: | ||||
|             self.sprite = pygame.image.load(i) | ||||
|         self.x = 524 | ||||
|         self.y = 524 | ||||
|         self.hidden = False | ||||
| 
 | ||||
|         self.rect = pygame.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) | ||||
|      | ||||
|     def draw(self, screen): | ||||
|         if self.hidden: | ||||
|             return | ||||
|         self.rect.x, self.rect.y = self.x, self.y | ||||
|         screen.blit(self.sprite, self.rect) | ||||
| 
 | ||||
| 
 | ||||
| class NPC(Character): | ||||
|     pass | ||||
| 
 | ||||
| 
 | ||||
| class Fighter(Character): | ||||
|     def __init__(self, name, ms, sprite, health, damage, level, asp, atr) -> None: | ||||
|         super().__init__(name, ms, sprite) | ||||
|         self.health = health | ||||
|         self.damage = damage | ||||
|         self.level = level | ||||
|         self.attack_speed = asp | ||||
|         self.attack_range = atr | ||||
| 
 | ||||
| class MainCharacter(Fighter): | ||||
|     def __init__(self, name, ms, sprite, health, damage, level, asp, atr, weapon=None, shield=None) -> None: | ||||
|         super().__init__(name, ms, sprite, health, damage, level, asp, atr) | ||||
|         self.attack_spell = weapon | ||||
|         self.shield_spell = shield | ||||
|         self.talking = False | ||||
| 
 | ||||
|     def update(self, keys): | ||||
|         if keys[pygame.K_w]: | ||||
|             self.y -= self.speed / fps | ||||
|         if keys[pygame.K_a]: | ||||
|             self.x -= self.speed / fps | ||||
|         if keys[pygame.K_s]: | ||||
|             self.y += self.speed / fps | ||||
|         if keys[pygame.K_d]: | ||||
|             self.x += self.speed / fps | ||||
| 
 | ||||
| class Mobs(Fighter): | ||||
|     def __init__(self, name, ms, sprite, health, damage, level, asp, atr, drops) -> None: | ||||
|         super().__init__(name, ms, sprite, health, damage, level, asp, atr) | ||||
|         self.drops = drops * (self.level / 2) | ||||
		Loading…
	
	Add table
		
		Reference in a new issue