diff --git a/art/images/background/house.png b/art/images/background/house.png new file mode 100644 index 0000000..e4d6ec3 Binary files /dev/null and b/art/images/background/house.png differ diff --git a/art/images/background/insideHouse.png b/art/images/background/insideHouse.png new file mode 100644 index 0000000..dbe316e Binary files /dev/null and b/art/images/background/insideHouse.png differ diff --git a/art/images/portal.png b/art/images/background/portal.png similarity index 100% rename from art/images/portal.png rename to art/images/background/portal.png diff --git a/classes.py b/classes.py index 6e1c8ea..95cb4c5 100644 --- a/classes.py +++ b/classes.py @@ -171,8 +171,12 @@ class GameObjects(): self.type = _type self.background = bg if bg != None: - with open(bg, 'r') as bg: - self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT]) + if WIDTH != None and HEIGHT != None: + with open(bg, 'r') as bg: + 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 def update(self, objects): @@ -287,3 +291,5 @@ class Obstacle(GameObjects): else: pygame.draw.rect(screen, '#e7f8e0', self.rect, 2) + + diff --git a/main.py b/main.py index 71567dd..712f72a 100644 --- a/main.py +++ b/main.py @@ -44,8 +44,8 @@ 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))] weapons = [] - others = [Fire('f1', 0, 200, 300)] - npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)] + others = [] + npcs = [] objects = [main, mobs, npcs, weapons, others] level = [] rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) @@ -74,7 +74,6 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): screen.blit(scene.background, (32, 32)) for thing in objects[4]: - thing.update(objects) thing.draw(screen) for weapon in objects[3]: @@ -83,9 +82,13 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): for thing in objects[0]: thing.book.hidden = not freeze - if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects): + result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) + if result == 'village': village(screen, clock, running, background, isblack, WIDTH, HEIGHT) - thing.draw(screen) + elif result == 'play': + play(screen, clock, running, background, isblack, WIDTH, HEIGHT) + else: + thing.draw(screen) for mob in objects[1]: mob.update(objects) @@ -111,7 +114,9 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): main = [herbert] mobs = [] weapons = [] - others = [Fire('f1', 0, 200, 300), Portal('p1', 0, 1000, 500)] + others = [Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 500, 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)] 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) @@ -139,8 +144,6 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): screen.blit(room.background, (32, 32)) for thing in objects[4]: - if thing.update(objects): - play(screen, clock, running, background, isblack, WIDTH, HEIGHT) thing.draw(screen) for weapon in objects[3]: @@ -149,9 +152,15 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): for thing in objects[0]: thing.book.hidden = not freeze - if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects): + result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) + if result == 'village': menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) - thing.draw(screen) + elif result == 'play': + 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]: mob.update(objects) @@ -171,7 +180,74 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): # flip() the display to put your work on screen pygame.display.flip() - clock.tick(fps) # limits FPS to 60 + clock.tick(fps) # limits FPS to + +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): objects = [] diff --git a/viecher.py b/viecher.py index 8871b1d..4bc2adf 100644 --- a/viecher.py +++ b/viecher.py @@ -136,6 +136,20 @@ class MainCharacter(Fighter): if not self.talking: 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): moveto = vec(0, 0) if keys[pg.K_w] or keys[pg.K_UP]: @@ -155,7 +169,7 @@ class MainCharacter(Fighter): if touches is not None and not isinstance(touches, Weapons): if isinstance(touches, Obstacle): if not touches.collision: - print(touches.name) + # print(touches.name) return if touches.type == 'wall': if touches.name == 'wall_l': @@ -211,9 +225,9 @@ class MainCharacter(Fighter): self.attack(objects, vec(mouse)) self.thinks.update(self) if self.health.health <= 0: - return False + return 'village' else: - return True + return self.obstacle_interaction(objects) class Hearts(): def __init__(self, health, sprite, x, y, hurtCooldown) -> None: @@ -470,28 +484,3 @@ class Punch(Weapons): def update(self, objects): self.move(objects) 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 \ No newline at end of file