forked from InfoProjekt/game
		
	Development #2
					 9 changed files with 91 additions and 9 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								art/images/blau1.kra
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/blau1.kra
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								art/images/blau1.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/blau1.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 11 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/blau2.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/blau2.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 11 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/blau3.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/blau3.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 11 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/rot1.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/rot1.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 11 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/rot2.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/rot2.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 11 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/rot3.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/rot3.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 11 KiB | 
							
								
								
									
										60
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						
									
										60
									
								
								classes.py
									
										
									
									
									
								
							|  | @ -1,4 +1,5 @@ | ||||||
| import pygame | import pygame | ||||||
|  | import inspect | ||||||
| 
 | 
 | ||||||
| pygame.font.init() | pygame.font.init() | ||||||
| fonts = { | fonts = { | ||||||
|  | @ -138,23 +139,70 @@ class DropDown(): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class GameObjects(): | class GameObjects(): | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list) -> None: |     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT) -> None: | ||||||
|         self.name = name |         self.name = name | ||||||
|         self.type = _type |         self.type = _type | ||||||
|         self.background = bg |         if bg != None: | ||||||
|  |             with open(bg, 'r') as bg: | ||||||
|  |                 self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT]) | ||||||
|         self.objects = objects |         self.objects = objects | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Scene(GameObjects): | class Scene(GameObjects): | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list) -> None: |     def __init__(self, name:str, _type:str, bg, objects:list | None, WIDTH, HEIGHT, level:list) -> None: | ||||||
|         super().__init__(name, _type, bg, objects) |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|  |         self.level = level | ||||||
|  |         self.current_level = 0 | ||||||
| 
 | 
 | ||||||
|  |     def update(self, change:bool): | ||||||
|  |         if change: | ||||||
|  |             self.current_level += 1 | ||||||
|  |         self.level[self.current_level].update() | ||||||
|  |         for obj in self.objects: | ||||||
|  |             obj.update() | ||||||
|  |          | ||||||
|  | 
 | ||||||
|  |     def draw(self, screen): | ||||||
|  |         for obj in self.objects: | ||||||
|  |             obj.draw(screen) | ||||||
|  |         self.level[self.current_level].draw(screen) | ||||||
|  |          | ||||||
|  | 
 | ||||||
|  | class Level(GameObjects): | ||||||
|  |     def __init__(self, name: str, _type: str, bg, objects: list, WIDTH, HEIGHT, stage:str, rooms:list) -> None: | ||||||
|  |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|  |         self.stage = stage | ||||||
|  |         self.rooms = rooms | ||||||
|  |         self.current = 0 | ||||||
|  |      | ||||||
|  |     def update(self): | ||||||
|  |         for room in self.rooms: | ||||||
|  |             if room.id == self.current: | ||||||
|  |                 room.update() | ||||||
|  |         keys = pygame.key.get_pressed() | ||||||
|  |         if keys[pygame.K_RIGHT]: | ||||||
|  |             self.current += 1 | ||||||
|  |         if self.current >= len(self.rooms): | ||||||
|  |             return 1 | ||||||
|  | 
 | ||||||
|  |     def draw(self, screen): | ||||||
|  |         for room in self.rooms: | ||||||
|  |             if room.id == self.current: | ||||||
|  |                 room.draw(screen) | ||||||
| 
 | 
 | ||||||
| class Room(GameObjects): | class Room(GameObjects): | ||||||
|     def __init__(self, name:str, _type:str, bg, objects:list, exits:list) -> None: |     def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT, exits:list, id:int) -> None: | ||||||
|         super().__init__(name, _type, bg, objects) |         super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) | ||||||
|         self.exits = exits |         self.exits = exits | ||||||
|  |         self.id = id | ||||||
|         if self.type == 'normal' or self.type == 'boss': |         if self.type == 'normal' or self.type == 'boss': | ||||||
|             self.locked = True |             self.locked = True | ||||||
|         else: |         else: | ||||||
|             self.locked = False |             self.locked = False | ||||||
|  | 
 | ||||||
|  |     def update(self): | ||||||
|  |         pass | ||||||
|  | 
 | ||||||
|  |     def draw(self, screen): | ||||||
|  |         screen.blit(self.background, (0, 0)) | ||||||
|  |          | ||||||
							
								
								
									
										40
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										40
									
								
								main.py
									
										
									
									
									
								
							|  | @ -13,7 +13,7 @@ def setUp(config): | ||||||
|     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(): | ||||||
|  | @ -27,8 +27,8 @@ def quitGame(): | ||||||
|     quit() |     quit() | ||||||
| 
 | 
 | ||||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     objects = [] |     objects = [[], [], []] #0 - maincharacter stuff; 1 - mobs; 2 - npcs | ||||||
|     objects.append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) |     objects[0].append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) | ||||||
|     while running: |     while running: | ||||||
|         screen.fill('#000000') |         screen.fill('#000000') | ||||||
|         events = pygame.event.get() |         events = pygame.event.get() | ||||||
|  | @ -103,6 +103,7 @@ def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) |             bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) | ||||||
|         # fill the screen with an image to clear the screen |         # fill the screen with an image to clear the screen | ||||||
|         screen.blit(bg, (0, 0)) |         screen.blit(bg, (0, 0)) | ||||||
|  |          | ||||||
|         for obj in objects: |         for obj in objects: | ||||||
|             obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) |             obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
| 
 | 
 | ||||||
|  | @ -111,6 +112,38 @@ def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
| 
 | 
 | ||||||
|         clock.tick(60)  # limits FPS to 60 |         clock.tick(60)  # limits FPS to 60 | ||||||
| 
 | 
 | ||||||
|  | def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|  |     level = [] | ||||||
|  |     level.append(Level('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', [ | ||||||
|  |         Room('blau1', 'normal', 'art/images/blau1.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), | ||||||
|  |         Room('blau2', 'normal', 'art/images/blau2.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), | ||||||
|  |         Room('blau3', 'normal', 'art/images/blau3.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), | ||||||
|  |             ])) | ||||||
|  |      | ||||||
|  |     level.append(Level('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ | ||||||
|  |         Room('red1', 'normal', 'art/images/rot1.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), | ||||||
|  |         Room('red2', 'normal', 'art/images/rot2.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), | ||||||
|  |         Room('red3', 'normal', 'art/images/rot3.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), | ||||||
|  |             ])) | ||||||
|  |      | ||||||
|  |     scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) | ||||||
|  | 
 | ||||||
|  |     # RENDER YOUR GAME HERE | ||||||
|  |     while True: | ||||||
|  |         for event in pygame.event.get(): | ||||||
|  |             if event.type == pygame.QUIT: | ||||||
|  |                 running = False | ||||||
|  |                 quitGame() | ||||||
|  |              | ||||||
|  |             scene.update() | ||||||
|  |             scene.draw(screen) | ||||||
|  |         # flip() the display to put your work on screen | ||||||
|  |         pygame.display.flip() | ||||||
|  | 
 | ||||||
|  |         clock.tick(60)  # limits FPS to 60 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def main(): | def main(): | ||||||
|     config = readConfig() |     config = readConfig() | ||||||
|     screen, clock, running, isblack, background, objects = setUp(config["screen"]) |     screen, clock, running, isblack, background, objects = setUp(config["screen"]) | ||||||
|  | @ -118,6 +151,7 @@ def main(): | ||||||
|     #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", play)) |     #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, 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 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) | ||||||
|  |     test(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|     """while running: |     """while running: | ||||||
|         for event in pygame.event.get(): |         for event in pygame.event.get(): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue