From d132757717d0184b22fce82495b6ad08f17b3282 Mon Sep 17 00:00:00 2001 From: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com> Date: Tue, 12 Mar 2024 07:39:36 +0100 Subject: [PATCH] added new npc started migrating object creation into the room classs Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com> --- art/images/people/fairy.png | Bin 0 -> 1738 bytes classes.py | 20 ++++++++++++++++-- main.py | 40 ++++++++++++++++++++++++------------ viecher.py | 17 ++++++++------- 4 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 art/images/people/fairy.png diff --git a/art/images/people/fairy.png b/art/images/people/fairy.png new file mode 100644 index 0000000000000000000000000000000000000000..d2d6ee67f9af12c5e77a4debc0b9b6fa660f48a2 GIT binary patch literal 1738 zcmV;*1~vJKP)RCr$Hn_p-gMI6U}cRADJ(p+Lp)YKr+nAC#!uNufhz(0uC z3VksM)mG?>KKLMrA{d`k5Q;t()E7ZPLF$90R#6c_!IJo|7EH7)h6bsMwI-K89`Um4 z{bu*KH#ReeFYErCX}I=rWc2BY6vef4|{gdqGcT{33koeQ2@Px=u^pF#!L5C*4rc zlW{fd#8W{yQj@m_Sm1bo%?CXhya$*hZx3L`i-oGd2hr9BvB+Bh1|RrTxI@4=c?;kR zd^%hajCw(y0t6O3d0-@xCP3MXd#cZQ*W&z-xWUj^yG^_Zy~xs460ncE8VtVhuU9xc z?aYWMg3Nftv;b+R!6L*LfLZ=F9CYrcTMtka6oiC8+7B-ngJPr}}NABA^5eqFZpHP&upFOt9nIJfZ=yZNL3i|^qTM9Gc&`^S0vE1Yjx`cHHlCH$GECET8IN=VK6VEY%}05Q?+GWbZ!MQmnuY z-Mf9|f)`+$E&~Ik3WC`CjOto=MR1JYJN2-x8k}94gRaKq&P}b$Ipn17eI$wizU?R9 z`{&C3JfGOZy7IV~`e__b6ajn$GQ8OP*h{V#kg<5CgE)Bf3ExLmi=p+>dEY&~M~E>- zW`fuP@US7kyC{m#Jn$zjc6F5<{If!Y;7!?M%=sOGXEe3bqn!m*c;mkbYiKQ4r@J@+ zcU7HPLzl~Yp!B#m6@Gf*Rj-^x*aI&~KbMxo9w3f?8LQS`x++RmzI+X8U$lg17l{Qx z*89%#ZW_qh+3xOF*ZXHmC)gRifZ(%53XH^n#6tk#T{R8(B?yYZZ-|=fkC0E8Bb5h4 zf$x1`P49uhQQQp@xZ*jQc#H!=jv>qoE(v+YNFqSguciWQS{3E9u;Gw` z){hVsBoQDHVa5}(q)0>($AZiR&@oZE&%4GM0LQ-yMUo{^&hVlTK;`}z0By~8DQUOJ zab|(GK*k?$d?bBdsBM*&-!pUoDy1syx^W-77qUf>V^rHc0LOlm@z3MWIXJe6NtMCM z2=sIgK%r0+e>;Rk9tv$2AVyn!EUmjq5jV$x$TCY950WHaiFOPDpT!-;e`0$8f?i-j zgMDS*QD{!*WhV!LBG6X66(0&Pzj#9Y4k6M|&{l{@vTjy@o1+qJX-?wG|2!2Ht$o@G g5iu%&LA3V$2f?99$NMVGp8x;=07*qoM6N<$f|G+Z761SM literal 0 HcmV?d00001 diff --git a/classes.py b/classes.py index d6dacb2..13327f2 100644 --- a/classes.py +++ b/classes.py @@ -1,5 +1,6 @@ import pygame import random +from viecher import * pygame.font.init() fonts = { @@ -223,9 +224,15 @@ class Stage(GameObjects): def update(self, target, objects): if target is not None: + old = self.current self.current = target for room in self.rooms: + try: + if room.id == old: + objects = room.objects + except UnboundLocalError: + pass if room.id == self.current: room.update(objects) self.background = room.background @@ -278,7 +285,6 @@ class Room(GameObjects): self.locked = True else: self.locked = False - [self.objects[4].append(wall) for wall in self.genWalls(WIDTH, HEIGHT)] def genWalls(self, WIDTH, HEIGHT): walls = [] @@ -291,7 +297,7 @@ class Room(GameObjects): def createDoors(self, WIDTH): if not self.type == 'boss': if len(self.exits) == 1: - self.doors.append(Door(f'door{self.id}', self.exits[0][1], random.randint(64, round(WIDTH * 0.75)), 4, self.exits[0][0])) + self.doors.append(Door(f'door{self.id}', self.exits[0][1], random.randint(64, round(WIDTH * 0.75)), self.exits[0][0])) elif len(self.exits) == 2: self.doors.append(Door(f'door{self.id}', self.exits[0][1], random.randint(64, round(WIDTH * 0.45)), self.exits[0][0])) self.doors.append(Door(f'door{self.id}', self.exits[1][1], random.randint(round(WIDTH * 0.5), round(WIDTH * 0.9)), self.exits[1][0])) @@ -302,6 +308,16 @@ class Room(GameObjects): self.objects.append(self.doors) + def objectCreation(self, WIDTH, HEIGHT): + main = [herbert] + self.objects[2] = [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 = [NPC('vivi', 100, 'people/vivi.png', 0, 200, 200), + NPC('fairy', 100, 'people/fairy.png', 0, 200, 200)] + r = [main, mobs, npcs, weapons, others] + [self.objects[4].append(wall) for wall in self.genWalls(WIDTH, HEIGHT)] + def update(self, objects): if objects is not None: self.objects = objects diff --git a/main.py b/main.py index 51149ac..ef0f6cc 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def setUp(config): pygame.display.set_caption('Between The Pages') with open('art/images/icon.png', 'r') as i: pygame.display.set_icon(pygame.image.load(i)) - return screen, clock, True, True, "startscreen.png", [] + return screen, clock, True, False, "startscreen.png", [] def readConfig(): with open('config.json', 'r') as c: @@ -44,17 +44,20 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list): return rooms def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): - main = [herbert] - 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 = [] - objects = [main, mobs, npcs, weapons, others] + # main = [herbert] + # 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 = [] + # objects = [main, mobs, npcs, weapons, others] level = [] rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) freeze = False #Gameplay is freezed in certain situations + tbc = Label(WIDTH / 2 - 128, HEIGHT / 2 - 32, 256, 32, "To be continued", "damaged", 30, '#ffffff', 'empty.png') + tbc_tick = 0 + while running: screen.fill('#000000') @@ -71,8 +74,14 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): 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: +""" + if isblack: + if tbc_tick == 0: + tbc_tick = pygame.time.get_ticks() + elif tbc_tick + 5000 <= pygame.time.get_ticks(): + quitGame() + tbc.draw(screen) + elif not freeze: objects = scene.getObjects() screen.blit(scene.background, (32, 32)) target = None @@ -87,6 +96,8 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): for thing in objects[0]: thing.book.hidden = not freeze result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) + if objects[0][0].level.level >= 100: + isblack = True if isinstance(result, str): if result == 'village': village(screen, clock, running, background, isblack, WIDTH, HEIGHT) @@ -94,6 +105,8 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): play(screen, clock, running, background, isblack, WIDTH, HEIGHT) elif 'door-' in result: target = result.split('-')[1] + objects[0][0].level.level += 25 + play(screen, clock, running, background, isblack, WIDTH, HEIGHT) else: thing.draw(screen) else: @@ -108,6 +121,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): npc.draw(screen) objects[0][0].book.addspell('windslash') + objects[0][0].book.addspell('fireball') scene.update(target, objects) scene.draw(screen) @@ -124,8 +138,8 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): main = [herbert] mobs = [] weapons = [] - others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500), - Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] + others = [ Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500), + 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] room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, 0) @@ -195,7 +209,7 @@ def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): mobs = [] weapons = [] others = [] - npcs = [NPC('elder', 100, 'people/reddy.png', 0, 200, 200)] + npcs = [NPC('elder', 100, 'people/dorfaelteste.png', 0, 200, 200)] objects = [main, mobs, npcs, weapons, others] room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, 0) freeze = False #Gameplay is freezed in certain situations @@ -386,7 +400,7 @@ def main(): #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) - test(screen, clock, running, background, isblack, WIDTH, HEIGHT) + #test(screen, clock, running, background, isblack, WIDTH, HEIGHT) """while running: for event in pygame.event.get(): diff --git a/viecher.py b/viecher.py index 65054f3..91aae11 100644 --- a/viecher.py +++ b/viecher.py @@ -77,8 +77,8 @@ class NPC(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.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) @@ -100,7 +100,8 @@ class Convo(Label): ['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!']] + ['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!']], + ['vivi', 0, ['Wer bist du denn?', 'Aber du kannst gerne aus dem Fenster springen, solange es nicht in meinem Unterricht ist.']] ] def draw(self, screen): @@ -117,7 +118,7 @@ class Convo(Label): def update(self, keys, objects): if keys[pg.K_f]: convo = self.findConversation() - if self.convo_act+1 < len(convo[2]): + if self.convo_act + 1 < len(convo[2]): self.text = convo[2][self.convo_act] self.convo_act += 1 else: @@ -126,12 +127,14 @@ class Convo(Label): 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 + objects[0][0].level.level = 50 while 'rat' in objects[0][0].killed: objects[0][0].killed.remove('rat') - if convo[0] == 'elder': + elif 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 + elif convo[0] == 'vivi': + objects[0][0].health.health = 0 self.convo_act = 0 self.npc.talking = False objects[0][0].talking = False @@ -575,7 +578,7 @@ 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):