forked from InfoProjekt/game
		
	Compare commits
	
		
			No commits in common. "9147971be8bb5578e48d56d081f0396879b83735" and "c17b65d2f332cca09d81fa820b214359ab4d382a" have entirely different histories.
		
	
	
		
			9147971be8
			...
			c17b65d2f3
		
	
		
					 6 changed files with 48 additions and 121 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 771 KiB | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 197 KiB | 
| Before Width: | Height: | Size: 626 B After Width: | Height: | Size: 626 B | 
							
								
								
									
										10
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								classes.py
									
										
									
									
									
								
							|  | @ -171,12 +171,8 @@ class GameObjects(): | ||||||
|         self.type = _type |         self.type = _type | ||||||
|         self.background = bg |         self.background = bg | ||||||
|         if bg != None: |         if bg != None: | ||||||
|             if WIDTH != None and HEIGHT != None: |             with open(bg, 'r') as bg: | ||||||
|                 with open(bg, 'r') as bg: |                 self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT]) | ||||||
|                     self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT]) |  | ||||||
|             else: |  | ||||||
|                 with open(bg, 'r') as bg: |  | ||||||
|                     self.background = pygame.transform.scale2x(pygame.image.load(bg))  |  | ||||||
|         self.objects = objects |         self.objects = objects | ||||||
| 
 | 
 | ||||||
|     def update(self, objects): |     def update(self, objects): | ||||||
|  | @ -291,5 +287,3 @@ class Obstacle(GameObjects): | ||||||
|         else: |         else: | ||||||
|             pygame.draw.rect(screen, '#e7f8e0', self.rect, 2) |             pygame.draw.rect(screen, '#e7f8e0', self.rect, 2) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  |  | ||||||
							
								
								
									
										111
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										111
									
								
								main.py
									
										
									
									
									
								
							|  | @ -41,11 +41,12 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list): | ||||||
|     return rooms |     return rooms | ||||||
|          |          | ||||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     main = [herbert] |     main = [MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50)] | ||||||
|     mobs = [Skeleton(i, random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))]+[Zombie(i, random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 100) for i in range(0,random.randint(2, 8))] |     mobs = [Skeleton(i, random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))]+[Zombie(i, random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 100) for i in range(0,random.randint(2, 8))] | ||||||
|  |      | ||||||
|     weapons = [] |     weapons = [] | ||||||
|     others = [] |     others = [Fire('f1', 0, 200, 300)] | ||||||
|     npcs = [] |     npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     objects = [main, mobs, npcs, weapons, others] | ||||||
|     level = [] |     level = [] | ||||||
|     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) |     rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) | ||||||
|  | @ -73,22 +74,19 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|             objects = scene.getObjects() |             objects = scene.getObjects() | ||||||
|             screen.blit(scene.background, (32, 32)) |             screen.blit(scene.background, (32, 32)) | ||||||
|          |          | ||||||
|             for thing in objects[4]: |  | ||||||
|                 thing.draw(screen) |  | ||||||
| 
 |  | ||||||
|             for weapon in objects[3]: |             for weapon in objects[3]: | ||||||
|                 weapon.update(objects) |                 weapon.update(objects) | ||||||
|                 weapon.draw(screen) |                 weapon.draw(screen) | ||||||
|              |              | ||||||
|  |             for thing in objects[4]: | ||||||
|  |                 thing.update(objects) | ||||||
|  |                 thing.draw(screen) | ||||||
|  | 
 | ||||||
|             for thing in objects[0]: |             for thing in objects[0]: | ||||||
|                 thing.book.hidden = not freeze |                 thing.book.hidden = not freeze | ||||||
|                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) |                 if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects): | ||||||
|                 if result == 'village': |  | ||||||
|                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                 elif result == 'play': |                 thing.draw(screen) | ||||||
|                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) |  | ||||||
|                 else: |  | ||||||
|                     thing.draw(screen) |  | ||||||
|          |          | ||||||
|             for mob in objects[1]: |             for mob in objects[1]: | ||||||
|                 mob.update(objects) |                 mob.update(objects) | ||||||
|  | @ -111,17 +109,14 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|         clock.tick(fps)  # limits FPS to 60 |         clock.tick(fps)  # limits FPS to 60 | ||||||
| 
 | 
 | ||||||
| def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     main = [herbert] |     main = [MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50)] | ||||||
|     mobs = [] |     mobs = [] | ||||||
|     weapons = [] |     weapons = [] | ||||||
|     others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 500, 500), |     others = [Fire('f1', 0, 200, 300), Portal('p1', 0, 1000, 500)] | ||||||
|               Obstacle('portal', 'interactable', 'art/images/background/portal.png', False, 700, 300), |  | ||||||
|               Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] |  | ||||||
|     npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)] |     npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)] | ||||||
|     objects = [main, mobs, npcs, weapons, others] |     objects = [main, mobs, npcs, weapons, others] | ||||||
|     room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0) |     room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0) | ||||||
|     freeze = True #Gameplay is freezed in certain situations |     freeze = True #Gameplay is freezed in certain situations | ||||||
|     main[0].health.health = 20 |  | ||||||
| 
 | 
 | ||||||
|     while running: |     while running: | ||||||
|         screen.fill('#000000') |         screen.fill('#000000') | ||||||
|  | @ -144,6 +139,8 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|             screen.blit(room.background, (32, 32)) |             screen.blit(room.background, (32, 32)) | ||||||
|          |          | ||||||
|             for thing in objects[4]: |             for thing in objects[4]: | ||||||
|  |                 if thing.update(objects): | ||||||
|  |                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                 thing.draw(screen) |                 thing.draw(screen) | ||||||
| 
 | 
 | ||||||
|             for weapon in objects[3]: |             for weapon in objects[3]: | ||||||
|  | @ -152,15 +149,9 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
| 
 | 
 | ||||||
|             for thing in objects[0]: |             for thing in objects[0]: | ||||||
|                 thing.book.hidden = not freeze |                 thing.book.hidden = not freeze | ||||||
|                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) |                 if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects): | ||||||
|                 if result == 'village': |  | ||||||
|                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||||
|                 elif result == 'play': |                 thing.draw(screen) | ||||||
|                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) |  | ||||||
|                 elif result == 'house': |  | ||||||
|                     house(screen, clock, running, background, isblack, WIDTH, HEIGHT) |  | ||||||
|                 else: |  | ||||||
|                     thing.draw(screen) |  | ||||||
|          |          | ||||||
|             for mob in objects[1]: |             for mob in objects[1]: | ||||||
|                 mob.update(objects) |                 mob.update(objects) | ||||||
|  | @ -180,74 +171,7 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|         # flip() the display to put your work on screen |         # flip() the display to put your work on screen | ||||||
|         pygame.display.flip() |         pygame.display.flip() | ||||||
| 
 | 
 | ||||||
|         clock.tick(fps)  # limits FPS to  |         clock.tick(fps)  # limits FPS to 60 | ||||||
| 
 |  | ||||||
| def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): |  | ||||||
|     main = [herbert] |  | ||||||
|     mobs = [] |  | ||||||
|     weapons = [] |  | ||||||
|     others = [] |  | ||||||
|     npcs = [NPC('oldman', 100, 'people/reddy.png', 1, 200, 200)] |  | ||||||
|     objects = [main, mobs, npcs, weapons, others] |  | ||||||
|     room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, [True, True, True, True], 0) |  | ||||||
|     freeze = False #Gameplay is freezed in certain situations |  | ||||||
| 
 |  | ||||||
|     while running: |  | ||||||
|         screen.fill('#000000') |  | ||||||
|         events = pygame.event.get() |  | ||||||
|         for event in events: |  | ||||||
|             if event.type == pygame.QUIT: |  | ||||||
|                 quitGame() |  | ||||||
|             elif event.type == pygame.KEYDOWN: |  | ||||||
|                 if event.key == pygame.K_e: #when book is open gameplay is freezed |  | ||||||
|                     freeze = not freeze |  | ||||||
|         # 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)) |  | ||||||
| """  |  | ||||||
|         if not freeze: |  | ||||||
|             objects = room.getObjects() |  | ||||||
|             screen.blit(room.background, (32, 32)) |  | ||||||
|          |  | ||||||
|             for thing in objects[4]: |  | ||||||
|                 thing.draw(screen) |  | ||||||
| 
 |  | ||||||
|             # for weapon in objects[3]: |  | ||||||
|             #     weapon.update(objects) |  | ||||||
|             #     weapon.draw(screen) |  | ||||||
| 
 |  | ||||||
|             for thing in objects[0]: |  | ||||||
|                 thing.book.hidden = not freeze |  | ||||||
|                 result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) |  | ||||||
|                 if result == 'village': |  | ||||||
|                     menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) |  | ||||||
|                 elif result == 'play': |  | ||||||
|                     play(screen, clock, running, background, isblack, WIDTH, HEIGHT) |  | ||||||
|                 elif result == 'wall': |  | ||||||
|                     village(screen, clock, running, background, isblack, WIDTH, HEIGHT) |  | ||||||
|                 else: |  | ||||||
|                     thing.draw(screen) |  | ||||||
|          |  | ||||||
|             for npc in objects[2]: |  | ||||||
|                 npc.update(pygame.key.get_pressed(), objects) |  | ||||||
|                 npc.draw(screen) |  | ||||||
|              |  | ||||||
|             objects[0][0].book.addspell('windslash') |  | ||||||
|             room.update(objects) |  | ||||||
| 
 |  | ||||||
|         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(fps)  # limits FPS to  |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||||
|     objects = [] |     objects = [] | ||||||
|  | @ -405,5 +329,4 @@ def main(): | ||||||
|     pygame.quit() |     pygame.quit() | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     herbert = MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50) |  | ||||||
|     main() |     main() | ||||||
|  |  | ||||||
							
								
								
									
										48
									
								
								viecher.py
									
										
									
									
									
								
							
							
						
						
									
										48
									
								
								viecher.py
									
										
									
									
									
								
							|  | @ -136,20 +136,6 @@ class MainCharacter(Fighter): | ||||||
|         if not self.talking: |         if not self.talking: | ||||||
|             self.health.hurt(damage) |             self.health.hurt(damage) | ||||||
|      |      | ||||||
|     def obstacle_interaction(self, objects): |  | ||||||
|         touches = pg.sprite.spritecollideany(self, objects[4]) |  | ||||||
|         if touches is not None: |  | ||||||
|             if touches.name == 'fireplace': |  | ||||||
|                 self.freezing = False |  | ||||||
|             elif touches.name == 'portal': |  | ||||||
|                 return 'play' |  | ||||||
|             elif touches.name == 'house': |  | ||||||
|                 return 'house' |  | ||||||
|             elif 'wall' in touches.name: |  | ||||||
|                 return 'wall' |  | ||||||
|         else: |  | ||||||
|              return True |  | ||||||
|      |  | ||||||
|     def walk(self, keys, objects): |     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]: | ||||||
|  | @ -169,7 +155,7 @@ class MainCharacter(Fighter): | ||||||
|         if touches is not None and not isinstance(touches, Weapons): |         if touches is not None and not isinstance(touches, Weapons): | ||||||
|             if isinstance(touches, Obstacle): |             if isinstance(touches, Obstacle): | ||||||
|                 if not touches.collision: |                 if not touches.collision: | ||||||
|                     # print(touches.name) |                     print(touches.name) | ||||||
|                     return |                     return | ||||||
|                 if touches.type == 'wall': |                 if touches.type == 'wall': | ||||||
|                     if touches.name == 'wall_l': |                     if touches.name == 'wall_l': | ||||||
|  | @ -225,9 +211,9 @@ class MainCharacter(Fighter): | ||||||
|                 self.attack(objects, vec(mouse)) |                 self.attack(objects, vec(mouse)) | ||||||
|             self.thinks.update(self) |             self.thinks.update(self) | ||||||
|         if self.health.health <= 0: |         if self.health.health <= 0: | ||||||
|             return 'village' |             return False | ||||||
|         else: |         else: | ||||||
|             return self.obstacle_interaction(objects) |             return True | ||||||
| 
 | 
 | ||||||
| class Hearts(): | class Hearts(): | ||||||
|     def __init__(self, health, sprite, x, y, hurtCooldown) -> None: |     def __init__(self, health, sprite, x, y, hurtCooldown) -> None: | ||||||
|  | @ -432,8 +418,7 @@ class Weapons(Objects): | ||||||
|         if touches is not None and isinstance(touches, kills): |         if touches is not None and isinstance(touches, kills): | ||||||
|             touches.hurt(self.damage, objects) |             touches.hurt(self.damage, objects) | ||||||
|             self.hidden = True |             self.hidden = True | ||||||
|             if self in objects[3]: |             objects[3].remove(self) | ||||||
|                 objects[3].remove(self) |  | ||||||
|              |              | ||||||
|     def move(self, objects): |     def move(self, objects): | ||||||
|         self.moveto.scale_to_length(self.speed) |         self.moveto.scale_to_length(self.speed) | ||||||
|  | @ -484,3 +469,28 @@ class Punch(Weapons): | ||||||
|     def update(self, objects): |     def update(self, objects): | ||||||
|         self.move(objects) |         self.move(objects) | ||||||
|         self.die(objects, MainCharacter) |         self.die(objects, MainCharacter) | ||||||
|  | 
 | ||||||
|  | class Fire(Objects): | ||||||
|  |     def __init__(self, name, ms, x, y, sprite='background/fireplace.png') -> None: | ||||||
|  |         super().__init__(name, ms, sprite, x, y) | ||||||
|  |      | ||||||
|  |     def warming(self, objects): | ||||||
|  |         touches = pg.sprite.spritecollideany(self, objects[0]) | ||||||
|  |         if touches is not None and isinstance(touches, MainCharacter): | ||||||
|  |             touches.freezing = False | ||||||
|  | 
 | ||||||
|  |     def update(self, objects): | ||||||
|  |         self.warming(objects) | ||||||
|  |         return False | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Portal(Objects): | ||||||
|  |     def __init__(self, name, ms, x, y, sprite='portal.png') -> None: | ||||||
|  |         super().__init__(name, ms, sprite, x, y) | ||||||
|  |      | ||||||
|  |     def update(self, objects): | ||||||
|  |         touches = pg.sprite.spritecollideany(self, objects[0]) | ||||||
|  |         if touches is not None and isinstance(touches, MainCharacter): | ||||||
|  |             return True | ||||||
|  |         else: | ||||||
|  |             return False | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue