added new npc

started migrating object creation into the room classs

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
This commit is contained in:
SpagettiFisch 2024-03-12 07:39:36 +01:00
parent 74abed824d
commit d132757717
4 changed files with 55 additions and 22 deletions

BIN
art/images/people/fairy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -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

40
main.py
View file

@ -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():

View file

@ -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):