forked from InfoProjekt/game
Compare commits
2 commits
073062ce0c
...
74abed824d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74abed824d | ||
|
|
76ef4f6559 |
3 changed files with 33 additions and 22 deletions
23
classes.py
23
classes.py
|
|
@ -196,10 +196,8 @@ class Scene(GameObjects):
|
|||
self.current_level = 0
|
||||
self.update()
|
||||
|
||||
def update(self, change:bool=False, objects=None):
|
||||
if change:
|
||||
self.current_level += 1
|
||||
self.level[self.current_level].update(objects)
|
||||
def update(self, change:int=None, objects=None):
|
||||
self.level[self.current_level].update(change, objects)
|
||||
self.background = self.level[self.current_level].background
|
||||
"""if isinstance(self.objects, list):
|
||||
for obj in self.objects[0] + self.objects[1] + self.objects[2]:
|
||||
|
|
@ -223,16 +221,14 @@ class Stage(GameObjects):
|
|||
self.current = 0
|
||||
self.sortRooms(WIDTH)
|
||||
|
||||
def update(self, objects):
|
||||
def update(self, target, objects):
|
||||
if target is not None:
|
||||
self.current = target
|
||||
|
||||
for room in self.rooms:
|
||||
if room.id == self.current:
|
||||
room.update(objects)
|
||||
self.background = room.background
|
||||
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:
|
||||
|
|
@ -304,11 +300,15 @@ class Room(GameObjects):
|
|||
self.doors.append(Door(f'door{self.id}', self.exits[1][1], random.randint(round(WIDTH * 0.33), round(WIDTH * 0.6)), self.exits[1][0]))
|
||||
self.doors.append(Door(f'door{self.id}', self.exits[2][1], random.randint(round(WIDTH * 0.63), round(WIDTH * 0.95)), self.exits[2][0]))
|
||||
|
||||
self.objects.append(self.doors)
|
||||
|
||||
def update(self, objects):
|
||||
if objects is not None:
|
||||
self.objects = objects
|
||||
if not self.objects[1]:
|
||||
self.locked = False
|
||||
for door in self.doors:
|
||||
door.update(False)
|
||||
return
|
||||
|
||||
def draw(self, screen):
|
||||
|
|
@ -339,10 +339,11 @@ class Obstacle(GameObjects):
|
|||
screen.blit(self.background, self.rect)
|
||||
|
||||
class Door(GameObjects):
|
||||
def __init__(self, name: str, _type: str, x: int, target:int, y: int=8, objects: list=None, WIDTH=None, HEIGHT=None, islocked=True) -> None:
|
||||
def __init__(self, name: str, _type: str, x: int, target:int, y: int=16, objects: list=None, WIDTH=None, HEIGHT=None, islocked=True) -> None:
|
||||
super().__init__(name, _type, f'art/images/background/door_{_type}.png', objects, WIDTH, HEIGHT)
|
||||
self.rect = pygame.Rect((x, y), self.background.get_size())
|
||||
self.locked = islocked
|
||||
self.target = target
|
||||
|
||||
def draw(self, screen):
|
||||
screen.blit(self.background, self.rect)
|
||||
|
|
|
|||
16
main.py
16
main.py
|
|
@ -75,6 +75,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
|||
if not freeze:
|
||||
objects = scene.getObjects()
|
||||
screen.blit(scene.background, (32, 32))
|
||||
target = None
|
||||
|
||||
for thing in objects[4]:
|
||||
thing.draw(screen)
|
||||
|
|
@ -86,10 +87,15 @@ 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 result == 'village':
|
||||
village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
elif result == 'play':
|
||||
play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
if isinstance(result, str):
|
||||
if result == 'village':
|
||||
village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
elif result == 'play':
|
||||
play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
elif 'door-' in result:
|
||||
target = result.split('-')[1]
|
||||
else:
|
||||
thing.draw(screen)
|
||||
else:
|
||||
thing.draw(screen)
|
||||
|
||||
|
|
@ -102,7 +108,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
|||
npc.draw(screen)
|
||||
|
||||
objects[0][0].book.addspell('windslash')
|
||||
scene.update(False, objects)
|
||||
scene.update(target, objects)
|
||||
scene.draw(screen)
|
||||
|
||||
else:
|
||||
|
|
|
|||
16
viecher.py
16
viecher.py
|
|
@ -229,7 +229,9 @@ class MainCharacter(Fighter):
|
|||
self.health.hurt(damage)
|
||||
|
||||
def obstacle_interaction(self, objects):
|
||||
touches = pg.sprite.spritecollideany(self, objects[4])
|
||||
if len(objects) <= 5:
|
||||
objects.append([])
|
||||
touches = pg.sprite.spritecollideany(self, objects[4] + objects[5])
|
||||
if touches is not None:
|
||||
if touches.name == 'fireplace':
|
||||
self.freezing = False
|
||||
|
|
@ -241,8 +243,11 @@ class MainCharacter(Fighter):
|
|||
return 'house'
|
||||
elif 'wall' in touches.name:
|
||||
return 'wall'
|
||||
elif isinstance(touches, Door):
|
||||
if not touches.locked:
|
||||
return f'door-{touches.target}'
|
||||
else:
|
||||
return True
|
||||
return True
|
||||
|
||||
def walk(self, keys, objects):
|
||||
moveto = vec(0, 0)
|
||||
|
|
@ -259,7 +264,7 @@ class MainCharacter(Fighter):
|
|||
|
||||
self.x += moveto[0] / fps
|
||||
self.y += moveto[1] / fps
|
||||
touches = pg.sprite.spritecollideany(self, objects[2] + objects[4])
|
||||
touches = pg.sprite.spritecollideany(self, objects[4])
|
||||
if touches is not None and not isinstance(touches, Weapons):
|
||||
if isinstance(touches, Obstacle):
|
||||
if not touches.collision:
|
||||
|
|
@ -275,11 +280,10 @@ class MainCharacter(Fighter):
|
|||
elif touches.name == 'wall_b':
|
||||
self.y -= (2 + self.rect.height - (touches.rect.y - self.y))
|
||||
return
|
||||
elif isinstance(touches, NPC):
|
||||
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))
|
||||
elif self.x > touches.rect.x: self.x += (self.rect.width - (self.x - touches.rect.x - touches.rect.width * 0.7))
|
||||
#if self.y <= touches.y: pass
|
||||
#elif self.y > touches.y: pass
|
||||
#self.x -= moveto[0] * 2 / fps
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue