added some missing spaces lol #55
					 9 changed files with 161 additions and 49 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								art/images/dirt1.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/dirt1.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 106 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/dirt2.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/dirt2.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 77 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/grass.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/grass.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 131 KiB | 
							
								
								
									
										
											BIN
										
									
								
								art/images/river1.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								art/images/river1.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 120 KiB | 
							
								
								
									
										80
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						
									
										80
									
								
								classes.py
									
										
									
									
									
								
							|  | @ -138,23 +138,93 @@ 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 |         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() | ||||||
|  |         if isinstance(self.objects, list): | ||||||
|  |             for obj in self.objects: | ||||||
|  |                 obj.update() | ||||||
|  |          | ||||||
|  |     def draw(self, screen): | ||||||
|  |         if isinstance(self.objects, list): | ||||||
|  |             for obj in self.objects: | ||||||
|  |                 obj.draw(screen) | ||||||
|  |         self.level[self.current_level].draw(screen) | ||||||
|  |          | ||||||
|  | 
 | ||||||
|  | class Stage(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 | ||||||
|  | 
 | ||||||
|  |         self.objects.append(self.genWalls(WIDTH, HEIGHT)) | ||||||
|  |          | ||||||
|  |     def genWalls(self, WIDTH, HEIGHT): | ||||||
|  |         walls = [] | ||||||
|  |         walls.append(pygame.Rect(0, 0, 4, HEIGHT)) | ||||||
|  |         walls.append(pygame.Rect(WIDTH - 4, 0, 4, HEIGHT)) | ||||||
|  |         walls.append(pygame.Rect(0, 0, WIDTH, 4)) | ||||||
|  |         walls.append(pygame.Rect(0, HEIGHT - 4, WIDTH, 4)) | ||||||
|  |         return walls | ||||||
|  | 
 | ||||||
|  |     def update(self): | ||||||
|  |         pass | ||||||
|  | 
 | ||||||
|  |     def draw(self, screen): | ||||||
|  |         screen.blit(self.background, (32, 32)) | ||||||
|  |         if isinstance(self.objects, list): | ||||||
|  |             for obj in self.objects[0]: | ||||||
|  |                 obj.draw(screen) | ||||||
|  | 
 | ||||||
|  | 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.rect = pygame.Rect((x, y), self.background.get_size()) | ||||||
|  |      | ||||||
|  |     def draw(self, screen): | ||||||
|  |         screen.blit(self.background, self.rect) | ||||||
							
								
								
									
										40
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										40
									
								
								main.py
									
										
									
									
									
								
							|  | @ -27,6 +27,16 @@ def quitGame(): | ||||||
|     pygame.quit() |     pygame.quit() | ||||||
|     quit() |     quit() | ||||||
| 
 | 
 | ||||||
|  | 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.append(Obstacle('river', 'water', 'art/images/river1.png', True, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)) | ||||||
|  |     rooms = [ | ||||||
|  |         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', [], 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], 2), | ||||||
|  |             ] | ||||||
|  |     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), 125, 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), 125, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))] | ||||||
|  | @ -47,7 +57,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|         screen.blit(bg, (0, 0)) |         screen.blit(bg, (0, 0)) | ||||||
| """  | """  | ||||||
|         for thing in objects[0]: |         for thing in objects[0]: | ||||||
|             if thing.update(pygame.key.get_pressed()) ==False: |             if not thing.update(pygame.key.get_pressed()): | ||||||
|                 menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                 menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|             thing.draw(screen) |             thing.draw(screen) | ||||||
|          |          | ||||||
|  | @ -126,6 +136,33 @@ 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 = [] | ||||||
|  |     rooms = genRooms(WIDTH, HEIGHT, 'grass') | ||||||
|  |     level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) | ||||||
|  |      | ||||||
|  |     level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ | ||||||
|  |         Room('red1', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), | ||||||
|  |         Room('red2', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), | ||||||
|  |         Room('red3', 'normal', 'art/images/grass.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() | ||||||
|  |             screen.fill('#000000') | ||||||
|  |             scene.update(False) | ||||||
|  |             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"]) | ||||||
|  | @ -133,6 +170,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(): | ||||||
|  |  | ||||||
							
								
								
									
										
											BIN
										
									
								
								test1.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test1.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 179 KiB | 
							
								
								
									
										
											BIN
										
									
								
								test2.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test2.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 166 KiB | 
							
								
								
									
										10
									
								
								viecher.py
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								viecher.py
									
										
									
									
									
								
							|  | @ -93,7 +93,7 @@ class MainCharacter(Fighter): | ||||||
|     def hurt(self, damage): |     def hurt(self, damage): | ||||||
|         self.health.hurt(damage) |         self.health.hurt(damage) | ||||||
|      |      | ||||||
|     def walk(self,keys): |     def walk(self, keys, objects): | ||||||
|         moveto = vec(0, 0) |         moveto = vec(0, 0) | ||||||
|         if keys[pg.K_w] or keys[pg.K_UP]: |         if keys[pg.K_w] or keys[pg.K_UP]: | ||||||
|             moveto += vec(0, -1) |             moveto += vec(0, -1) | ||||||
|  | @ -107,9 +107,13 @@ class MainCharacter(Fighter): | ||||||
|             moveto.scale_to_length(self.speed) |             moveto.scale_to_length(self.speed) | ||||||
|         self.x += moveto[0] / fps |         self.x += moveto[0] / fps | ||||||
|         self.y += moveto[1] / fps |         self.y += moveto[1] / fps | ||||||
|  |         touches = pg.sprite.spritecollideany(self, objects[1] + objects[2]) | ||||||
|  |         if touches is not None: | ||||||
|  |             self.x -= moveto[0] / fps #change later | ||||||
|  |             self.y -= moveto[1] / fps #change later | ||||||
| 
 | 
 | ||||||
|     def update(self, keys): |     def update(self, keys, objects): | ||||||
|         self.walk(keys) |         self.walk(keys, objects) | ||||||
|         if self.health.health <= 0: |         if self.health.health <= 0: | ||||||
|             return False |             return False | ||||||
|         else: |         else: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue