forked from InfoProjekt/game
		
	Merge pull request 'Development' (#7) from InfoProjekt/game:Development into main
Reviewed-on: Spafi/game#7
This commit is contained in:
		
						commit
						67ba9a62a1
					
				
					 6 changed files with 84 additions and 36 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 626 B After Width: | Height: | Size: 1.3 KiB | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 329 B After Width: | Height: | Size: 1.1 KiB | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 68 B After Width: | Height: | Size: 87 B | 
|  | @ -85,6 +85,7 @@ class Label(): | |||
|         self.font_color = font_color | ||||
|         self.text = text | ||||
|         self.hidden = False | ||||
|         self.sprite = sprite | ||||
|         with open(f'art/images/box/{sprite}', 'r') as tb: | ||||
|             self.box = pygame.image.load(tb) | ||||
|             self.box = pygame.transform.scale(self.box, (width, height)) | ||||
|  | @ -93,6 +94,9 @@ class Label(): | |||
|     def draw(self, screen): | ||||
|         if self.hidden: | ||||
|             return | ||||
|         with open(f'art/images/box/{self.sprite}', 'r') as tb: | ||||
|             self.box = pygame.image.load(tb) | ||||
|             self.box = pygame.transform.scale(self.box, (self.width,self.height)) | ||||
|         self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height) | ||||
|         self.labelSurf = self.font.render(self.text, True, self.font_color) | ||||
|         self.box.blit(self.labelSurf, [ | ||||
|  |  | |||
							
								
								
									
										6
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								main.py
									
										
									
									
									
								
							|  | @ -42,7 +42,7 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list): | |||
|          | ||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||
|     main = [herbert] | ||||
|     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('skeleton', 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, 5))]+[Zombie('zombie', random.randint(40, 60), random.randint(50, WIDTH-50), random.randint(50, HEIGHT-50), 5, 1, 1, 1, 25) for i in range(0,random.randint(2, 5))] | ||||
|     weapons = [] | ||||
|     others = [] | ||||
|     npcs = [] | ||||
|  | @ -115,7 +115,6 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | |||
|     mobs = [] | ||||
|     weapons = [] | ||||
|     others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 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('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] | ||||
|     objects = [main, mobs, npcs, weapons, others] | ||||
|  | @ -170,7 +169,6 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): | |||
|                 npc.update(pygame.key.get_pressed(), objects) | ||||
|                 npc.draw(screen) | ||||
|              | ||||
|             objects[0][0].book.addspell('windslash') | ||||
|             room.update(objects) | ||||
| 
 | ||||
|         else: | ||||
|  | @ -187,7 +185,7 @@ def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): | |||
|     mobs = [] | ||||
|     weapons = [] | ||||
|     others = [] | ||||
|     npcs = [NPC('oldman', 100, 'people/reddy.png', 0, 200, 200)] | ||||
|     npcs = [NPC('elder', 100, 'people/reddy.png', 0, 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 | ||||
|  |  | |||
							
								
								
									
										110
									
								
								viecher.py
									
										
									
									
									
								
							
							
						
						
									
										110
									
								
								viecher.py
									
										
									
									
									
								
							|  | @ -1,6 +1,7 @@ | |||
| import pygame as pg | ||||
| from classes import * | ||||
| from main import * | ||||
| import random | ||||
| 
 | ||||
| vec = pg.math.Vector2 | ||||
| fps = 60 | ||||
|  | @ -74,7 +75,10 @@ class NPC(Objects): | |||
|         if self.talking: | ||||
|             self.conversation.draw(screen) | ||||
|      | ||||
|     def update(self, keys, objects):  | ||||
|     def update(self, keys, objects): | ||||
|         if self.name == 'oldlady': | ||||
|             if self.conversation.convo_scene==0 and 'rat' in objects[0][0].killed and objects[1]==[]: | ||||
|                 self.conversation.convo_scene=1 | ||||
|         if self.lastUpdate + 200 < pg.time.get_ticks(): | ||||
|             if self.talking: | ||||
|                 self.conversation.update(keys, objects) | ||||
|  | @ -93,28 +97,41 @@ class Convo(Label): | |||
|         self.npc = npc | ||||
|         self.convo_scene = convo_scene | ||||
|         self.convos = [ | ||||
|             ['oldlady', 0, ['Hello', 'How are you?']], | ||||
|             ['oldman', 0, ['Please help', 'there are so many bad people']] | ||||
|             ['oldlady', 0, ['There are so many rats here.', 'I wish someone would to something against that.','An experienced fighter could kill them.', 'For them it only takes a mouseclick.']], | ||||
|             ['oldlady', 1, ['Oh, did you kill all the rats?', 'You must be the chosen one!', 'It would be nice if you would go and talk to the village elder.']], | ||||
|             ['elder', 0, ['Who are you?', 'You want to help us?', 'We have a serious problem with monsters.', 'One day they appeared out of nowhere and started attacking.', 'When you jump into the portal over there,', 'You will be send to a place with monsters.', 'PLEASE help us!']], | ||||
|             ['elder', 1, ['Who are you?', 'You want to help us?', 'We have a serious problem with monsters.', 'One day they appeared out of nowhere and started attacking.', 'When you jump into the portal over there,', 'You will be send to a place with monsters.', 'PLEASE help us!']] | ||||
|         ] | ||||
| 
 | ||||
|     def draw(self, screen): | ||||
|         self.text = self.findConversation()[self.convo_act] | ||||
|         self.text = self.findConversation()[2][self.convo_act] | ||||
|         super().draw(screen) | ||||
| 
 | ||||
| 
 | ||||
|     def findConversation(self): | ||||
|         for convo in self.convos: | ||||
|             if convo[0] == self.npc.name and convo[1] == self.convo_scene: | ||||
|                 return convo[2] | ||||
|                 return convo | ||||
|         return ['ERROR'] | ||||
| 
 | ||||
|     def update(self, keys, objects): | ||||
|         if keys[pg.K_SPACE]: | ||||
|         if keys[pg.K_f]: | ||||
|             convo = self.findConversation() | ||||
|             if self.convo_act+1 < len(convo): | ||||
|                 self.text = convo[self.convo_act] | ||||
|             if self.convo_act+1 < len(convo[2]): | ||||
|                 self.text = convo[2][self.convo_act] | ||||
|                 self.convo_act += 1 | ||||
|             else: | ||||
|                 if convo[0] == 'oldlady': | ||||
|                     if convo[1] == 0: | ||||
|                         for i in range(0,5): | ||||
|                             objects[1].append(Rat('rat', random.randint(150,250), 800, 400+i*20, 1, 1, 1, 100, 25)) | ||||
|                     elif convo[1] == 1: | ||||
|                         objects[0][0].level.level = 5 | ||||
|                         while 'rat' in objects[0][0].killed: objects[0][0].killed.remove('rat') | ||||
|                 if convo[0] == 'elder': | ||||
|                     if convo[1] == 0: | ||||
|                         objects[4].append(Obstacle('portal', 'interactable', 'art/images/background/portal.png', False, 700, 300)) | ||||
|                         self.convo_scene += 1 | ||||
|                 self.convo_act = 0 | ||||
|                 self.npc.talking = False | ||||
|                 objects[0][0].talking = False | ||||
|  | @ -134,14 +151,15 @@ class Fighter(Objects): | |||
| 
 | ||||
| 
 | ||||
| class MainCharacter(Fighter): | ||||
|     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr) -> None: | ||||
|     def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, killed =[]) -> None: | ||||
|         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr) | ||||
|         self.book = Book(0, 0, [], None, None) | ||||
|         self.talking = False | ||||
|         self.level = Level(1000, 38, 150, 40, f'will to live: {level}%', 'simple', 20, ) | ||||
|         self.level = Level(1000, 38, 150, 40, level, f'will to live: {level}%', 'simple', 20, ) | ||||
|         self.health = Hearts(health, sprite=['fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png', 'fullheart.png'], x=900, y= 50, hurtCooldown=self.hurtCooldown) | ||||
|         self.thinks = Thinks(self.x+20, self.y-50, 150, 100, 'brr Im freezing') | ||||
|         self.thinks = Thinks(self.x+20, self.y-50, 150, 100, 'brr I\'m freezing') | ||||
|         self.freezing = True | ||||
|         self.killed = killed #amount of mobs that were killed | ||||
| 
 | ||||
|     def draw(self, screen): | ||||
|         if self.hidden: | ||||
|  | @ -164,9 +182,11 @@ class MainCharacter(Fighter): | |||
|         if touches is not None: | ||||
|             if touches.name == 'fireplace': | ||||
|                 self.freezing = False | ||||
|             elif touches.name == 'portal': | ||||
|             elif touches.name == 'portal' and self.level.level != 1: | ||||
|                 return 'play' | ||||
|             elif touches.name == 'house': | ||||
|             elif touches.name == 'house' and self.level.level != 1: | ||||
|                 self.x = 500 | ||||
|                 self.y = 400 | ||||
|                 return 'house' | ||||
|             elif 'wall' in touches.name: | ||||
|                 return 'wall' | ||||
|  | @ -205,11 +225,7 @@ class MainCharacter(Fighter): | |||
|                         self.y -= (2 + self.rect.height - (touches.rect.y - self.y)) | ||||
|                     return | ||||
|             elif isinstance(touches, NPC): | ||||
|                 if keys[pg.K_f]: | ||||
|                     touches.talk(objects) | ||||
|                     return | ||||
|                 else: | ||||
|                     return | ||||
|                 return | ||||
| 
 | ||||
|             if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x)) | ||||
|             elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x - touches.rect.width * 0.66)) | ||||
|  | @ -235,9 +251,9 @@ class MainCharacter(Fighter): | |||
|             if self.book.current_sp == 'fireball': | ||||
|                 weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5) | ||||
|             elif self.book.current_sp == 'windslash': | ||||
|                 weapon = Windslash('ws1', 100, self.x, self.y, moveto, 5) | ||||
|                 weapon = Windslash('ws1', 100, self.x, self.y, moveto, 10) | ||||
|             else: | ||||
|                 return | ||||
|                 weapon = Punch('punch', 100, self.x, self.y, moveto, 1, Mobs, life_ticks=500) | ||||
|             obj[3].append(weapon) | ||||
|             self.lastAttack = pg.time.get_ticks() | ||||
| 
 | ||||
|  | @ -246,7 +262,7 @@ class MainCharacter(Fighter): | |||
|             self.walk(keys, objects) | ||||
|             if pg.mouse.get_pressed()[0]: | ||||
|                 self.attack(objects, vec(mouse)) | ||||
|             self.thinks.update(self) | ||||
|         self.thinks.update(objects, self) | ||||
|         if self.health.health <= 0: | ||||
|             return 'village' | ||||
|         else: | ||||
|  | @ -301,12 +317,17 @@ class Hearts(): | |||
| 
 | ||||
| 
 | ||||
| class Level(Label): | ||||
|     def __init__(self, x, y, width, height, text, font='simple', font_size=20, font_color='#1e90ff', sprite='label.png') -> None: | ||||
|     def __init__(self, x, y, width, height, level, text, font='simple', font_size=20, font_color='#1e90ff', sprite='label.png') -> None: | ||||
|         super().__init__(x, y, width, height, text, font, font_size, font_color, sprite) | ||||
|         self.level = level | ||||
|     def draw(self, screen): | ||||
|         self.text = f'will to live: {self.level}%' | ||||
|         super().draw(screen) | ||||
| 
 | ||||
| class Thinks(Label): | ||||
|     def __init__(self, x, y, width, height, text, font='simple', font_size=15, font_color='#000000', sprite='thinks.png') -> None: | ||||
|         super().__init__(x, y, width, height, text, font, font_size, font_color, sprite) | ||||
|         self.scene = 0 | ||||
| 
 | ||||
|     def draw(self, screen, x, y): | ||||
|         if self.hidden: | ||||
|  | @ -315,10 +336,22 @@ class Thinks(Label): | |||
|         self.y = y | ||||
|         super().draw(screen) | ||||
|      | ||||
|     def update(self, main): | ||||
|     def update(self, objects, main): | ||||
|         if not self.hidden: | ||||
|             if not main.freezing: | ||||
|             if self.scene == 0 and not main.freezing: | ||||
|                 self.scene = 1 | ||||
|                 self.hidden = True | ||||
|             elif self.scene == 1 and main.talking: | ||||
|                 self.scene = 2 | ||||
|                 self.hidden = True | ||||
|         if self.scene == 1: | ||||
|             touches = pg.sprite.spritecollideany(main, objects[2]) | ||||
|             if touches is not None and isinstance(touches, NPC): | ||||
|                 self.text = 'I should press \"f\"' | ||||
|                 self.hidden = False | ||||
|             else: | ||||
|                 self.hidden = False | ||||
|                 self.text = 'the lady over there' | ||||
| 
 | ||||
| class Book(): | ||||
|     def __init__(self, x, y, spells, current_spell, current_shield) -> None: | ||||
|  | @ -332,11 +365,12 @@ class Book(): | |||
|         self.sp_list = spells | ||||
|         self.current_sp = current_spell | ||||
|         self.text_left = ["Dear User, ", "in case you fell on the ground too hard,", "here is a quick reminder:",  | ||||
|                             "You are a homeless person.","One cold day you went to the library to get warm.",  | ||||
|                             "There you saw and opened me out of boedom.", "This lead to you being thrown in this world.",  | ||||
|                             "You are a homeless person. One cold day","you went to the library to warm up yourself.",  | ||||
|                             "There you got bored and found and opened me.", "This lead to you being thrown into this world.",  | ||||
|                             "But you can find a way out of here again."]  | ||||
|         self.text_right = ["This book will help you to survive.", "Click on a picture to choose your spell.", | ||||
|                           "Talk to fairies to unlock new spells!"] | ||||
|         self.text_right = ["This book will help you to survive.", "You can open and close me when pressing e.", | ||||
|                            "Click on a picture to choose your spell.", | ||||
|                            "Talk to fairies to unlock new spells!"] | ||||
|         self.buttons=[] | ||||
|         self.buttons_y = 400 | ||||
|         self.buttons_x = 800 | ||||
|  | @ -410,6 +444,7 @@ class Mobs(Fighter): | |||
|     def hurt(self, damage, objects): | ||||
|         self.health -= damage | ||||
|         if self.health <= 0: | ||||
|             objects[0][0].killed.append(self.name) | ||||
|             self.hidden = True | ||||
|             objects[1].remove(self) | ||||
|      | ||||
|  | @ -435,7 +470,17 @@ class Zombie(Mobs): | |||
|      | ||||
|     def attack(self, moveto, obj): | ||||
|         if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): | ||||
|             obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage)) | ||||
|             obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter)) | ||||
|             self.lastAttack = pg.time.get_ticks() | ||||
| 
 | ||||
| class Rat(Mobs): | ||||
|     def __init__(self, name, ms, x, y, health, damage, level, asp, atr, sprite='people/rat.png', drops=0) -> None: | ||||
|         super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr, drops) | ||||
|      | ||||
|      | ||||
|     def attack(self, moveto, obj): | ||||
|         if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks(): | ||||
|             obj[3].append(Punch('punch', 100, self.x, self.y, moveto, self.damage, MainCharacter)) | ||||
|             self.lastAttack = pg.time.get_ticks() | ||||
| 
 | ||||
| class Weapons(Objects): | ||||
|  | @ -479,7 +524,7 @@ class Fireball(Spells): | |||
|         self.die(objects, Mobs) | ||||
| 
 | ||||
| class Windslash(Spells): | ||||
|     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/windslash.png', life_ticks=700) -> None: | ||||
|     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/windslash.png', life_ticks=1000) -> None: | ||||
|         super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) | ||||
|      | ||||
|     def update(self, objects): | ||||
|  | @ -501,9 +546,10 @@ class Arrow(Weapons): | |||
| 
 | ||||
| 
 | ||||
| class Punch(Weapons): | ||||
|     def __init__(self, name, ms, x, y, moveto, damage, sprite = 'weapons/empty.png', life_ticks=100) -> None: | ||||
|     def __init__(self, name, ms, x, y, moveto, damage, kills, sprite = 'weapons/empty.png', life_ticks=100) -> None: | ||||
|         super().__init__(name, ms, sprite, x, y, moveto, damage, life_ticks) | ||||
|         self.kills = kills | ||||
|      | ||||
|     def update(self, objects): | ||||
|         self.move(objects) | ||||
|         self.die(objects, MainCharacter) | ||||
|         self.die(objects, self.kills) | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue