added house
This commit is contained in:
parent
52d3ec6e8d
commit
9147971be8
6 changed files with 112 additions and 41 deletions
BIN
art/images/background/house.png
Normal file
BIN
art/images/background/house.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 771 KiB |
BIN
art/images/background/insideHouse.png
Normal file
BIN
art/images/background/insideHouse.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 197 KiB |
|
Before Width: | Height: | Size: 626 B After Width: | Height: | Size: 626 B |
|
|
@ -171,8 +171,12 @@ class GameObjects():
|
||||||
self.type = _type
|
self.type = _type
|
||||||
self.background = bg
|
self.background = bg
|
||||||
if bg != None:
|
if bg != None:
|
||||||
|
if WIDTH != None and HEIGHT != None:
|
||||||
with open(bg, 'r') as bg:
|
with open(bg, 'r') as bg:
|
||||||
self.background = pygame.transform.scale(pygame.image.load(bg), [WIDTH, HEIGHT])
|
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
|
self.objects = objects
|
||||||
|
|
||||||
def update(self, objects):
|
def update(self, objects):
|
||||||
|
|
@ -287,3 +291,5 @@ class Obstacle(GameObjects):
|
||||||
else:
|
else:
|
||||||
pygame.draw.rect(screen, '#e7f8e0', self.rect, 2)
|
pygame.draw.rect(screen, '#e7f8e0', self.rect, 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
94
main.py
94
main.py
|
|
@ -44,8 +44,8 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
main = [herbert]
|
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(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 = []
|
weapons = []
|
||||||
others = [Fire('f1', 0, 200, 300)]
|
others = []
|
||||||
npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)]
|
npcs = []
|
||||||
objects = [main, mobs, npcs, weapons, others]
|
objects = [main, mobs, npcs, weapons, others]
|
||||||
level = []
|
level = []
|
||||||
rooms = genRooms(WIDTH, HEIGHT, 'grass', objects)
|
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))
|
screen.blit(scene.background, (32, 32))
|
||||||
|
|
||||||
for thing in objects[4]:
|
for thing in objects[4]:
|
||||||
thing.update(objects)
|
|
||||||
thing.draw(screen)
|
thing.draw(screen)
|
||||||
|
|
||||||
for weapon in objects[3]:
|
for weapon in objects[3]:
|
||||||
|
|
@ -83,8 +82,12 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
|
|
||||||
for thing in objects[0]:
|
for thing in objects[0]:
|
||||||
thing.book.hidden = not freeze
|
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)
|
village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||||
|
elif result == 'play':
|
||||||
|
play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||||
|
else:
|
||||||
thing.draw(screen)
|
thing.draw(screen)
|
||||||
|
|
||||||
for mob in objects[1]:
|
for mob in objects[1]:
|
||||||
|
|
@ -111,7 +114,9 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
main = [herbert]
|
main = [herbert]
|
||||||
mobs = []
|
mobs = []
|
||||||
weapons = []
|
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)]
|
npcs = [NPC('name', 100, 'people/oldlady.png', 1, 200, 200)]
|
||||||
objects = [main, mobs, npcs, weapons, others]
|
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)
|
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))
|
screen.blit(room.background, (32, 32))
|
||||||
|
|
||||||
for thing in objects[4]:
|
for thing in objects[4]:
|
||||||
if thing.update(objects):
|
|
||||||
play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
|
||||||
thing.draw(screen)
|
thing.draw(screen)
|
||||||
|
|
||||||
for weapon in objects[3]:
|
for weapon in objects[3]:
|
||||||
|
|
@ -149,8 +152,14 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
|
|
||||||
for thing in objects[0]:
|
for thing in objects[0]:
|
||||||
thing.book.hidden = not freeze
|
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)
|
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||||
|
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)
|
thing.draw(screen)
|
||||||
|
|
||||||
for mob in objects[1]:
|
for mob in objects[1]:
|
||||||
|
|
@ -171,7 +180,74 @@ def village(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
# flip() the display to put your work on screen
|
# flip() the display to put your work on screen
|
||||||
pygame.display.flip()
|
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):
|
def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
objects = []
|
objects = []
|
||||||
|
|
|
||||||
45
viecher.py
45
viecher.py
|
|
@ -136,6 +136,20 @@ class MainCharacter(Fighter):
|
||||||
if not self.talking:
|
if not self.talking:
|
||||||
self.health.hurt(damage)
|
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):
|
def walk(self, keys, objects):
|
||||||
moveto = vec(0, 0)
|
moveto = vec(0, 0)
|
||||||
if keys[pg.K_w] or keys[pg.K_UP]:
|
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 touches is not None and not isinstance(touches, Weapons):
|
||||||
if isinstance(touches, Obstacle):
|
if isinstance(touches, Obstacle):
|
||||||
if not touches.collision:
|
if not touches.collision:
|
||||||
print(touches.name)
|
# print(touches.name)
|
||||||
return
|
return
|
||||||
if touches.type == 'wall':
|
if touches.type == 'wall':
|
||||||
if touches.name == 'wall_l':
|
if touches.name == 'wall_l':
|
||||||
|
|
@ -211,9 +225,9 @@ class MainCharacter(Fighter):
|
||||||
self.attack(objects, vec(mouse))
|
self.attack(objects, vec(mouse))
|
||||||
self.thinks.update(self)
|
self.thinks.update(self)
|
||||||
if self.health.health <= 0:
|
if self.health.health <= 0:
|
||||||
return False
|
return 'village'
|
||||||
else:
|
else:
|
||||||
return True
|
return self.obstacle_interaction(objects)
|
||||||
|
|
||||||
class Hearts():
|
class Hearts():
|
||||||
def __init__(self, health, sprite, x, y, hurtCooldown) -> None:
|
def __init__(self, health, sprite, x, y, hurtCooldown) -> None:
|
||||||
|
|
@ -470,28 +484,3 @@ class Punch(Weapons):
|
||||||
def update(self, objects):
|
def update(self, objects):
|
||||||
self.move(objects)
|
self.move(objects)
|
||||||
self.die(objects, MainCharacter)
|
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
|
|
||||||
Loading…
Add table
Reference in a new issue