Compare commits

..

5 commits

Author SHA1 Message Date
SpagettiFisch
690a00b718 Merge branch 'Development' of https://git.spafi.eu/InfoProjekt/game
Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-13 10:38:09 +01:00
SpagettiFisch
368b033aab implemented boss health bar
Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-03-13 10:37:44 +01:00
57ffcf133c changed will to live (level) back to non dev
Signed-off-by: Spafi <spafi@noreply.git.spafi.eu>
2024-03-12 21:02:21 +00:00
45c18a7713 changed will to live (level) back to non dev
Signed-off-by: Spafi <spafi@noreply.git.spafi.eu>
2024-03-12 21:00:05 +00:00
e383c8afed Merge pull request 'changed to normal version again (no dev shortcuts)' (#84) from Spafi/game:main into Development
Reviewed-on: InfoProjekt/game#84
2024-03-12 20:51:23 +00:00
4 changed files with 488 additions and 440 deletions

Binary file not shown.

View file

@ -101,7 +101,7 @@ class Label():
return return
with open(f'art/images/box/{self.sprite}', 'r') as tb: with open(f'art/images/box/{self.sprite}', 'r') as tb:
self.box = pygame.image.load(tb) self.box = pygame.image.load(tb)
self.box = pygame.transform.scale(self.box, (self.width,self.height)) self.box = pygame.transform.scale(self.box, (self.width, self.height))
self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height) self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height)
self.labelSurf = self.font.render(self.text, True, self.font_color) self.labelSurf = self.font.render(self.text, True, self.font_color)
self.box.blit(self.labelSurf, [ self.box.blit(self.labelSurf, [
@ -110,6 +110,50 @@ class Label():
]) ])
screen.blit(self.box, self.labelRect) screen.blit(self.box, self.labelRect)
class HealthBar(Label):
def __init__(self, text, hp, x, y=8, width=256, height=24, font='simple', font_size=20, font_color='#e3d807', sprite='bossbar') -> None:
super().__init__(x, y, width, height, text, font, font_size, font_color)
self.text = text.capitalize()
self.max = hp
self.sprite = [f'{sprite}_empty.png', f'{sprite}_full.png', f'{sprite}_edge.png']
self.box = []
self.filling_should = self.width
self.filling_is = self.filling_should
self.rect = pygame.Rect(0, 0, 0, 0)
self.percentage = 100
for sprite in self.sprite:
with open(f'art/images/box/{sprite}', 'r') as tb:
tmp = pygame.image.load(tb)
self.box.append(pygame.transform.scale(tmp, (width, height)))
def draw(self, screen):
if self.hidden:
return
for i, sprite in enumerate(self.sprite):
with open(f'art/images/box/{sprite}', 'r') as tb:
if i != 1:
self.box[i] = pygame.image.load(tb)
self.box[i] = pygame.transform.scale(self.box[i], (self.width, self.height))
else:
self.box[i] = pygame.image.load(tb)
if not self.filling_is <= self.filling_should:
self.filling_is -= 1.5
self.box[i] = pygame.transform.scale(self.box[i], (self.filling_is, self.height))
self.labelRect = pygame.Rect(self.x, self.y, self.width, self.height)
self.labelSurf = self.font.render(f'{self.text}: {self.percentage}%', True, self.font_color)
self.box[-1].blit(self.labelSurf, [
self.labelRect.width / 2 - self.labelSurf.get_rect().width / 2,
self.labelRect.height / 2 - self.labelSurf.get_rect().height / 2
])
for box in self.box:
screen.blit(box, self.labelRect)
def update(self, objects):
for mob in objects[1]:
if isinstance(mob, Boss):
self.percentage = mob.health / (self.max / 100)
self.filling_should = self.width * (self.percentage / 100)
class DropDown(): class DropDown():
@ -318,6 +362,7 @@ class Room(GameObjects):
self.objects.append(self.doors) self.objects.append(self.doors)
def objectCreation(self, WIDTH, HEIGHT): def objectCreation(self, WIDTH, HEIGHT):
self.objects[4] = [wall for wall in self.genWalls(WIDTH, HEIGHT)]
if self.type != 'boss': if self.type != 'boss':
self.objects[1] = [Skeleton('skeleton', random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 2, 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))] self.objects[1] = [Skeleton('skeleton', random.randint(40, 60), random.randint(50, WIDTH - 50), random.randint(50, HEIGHT - 50), 5, 1, 1, 2, 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))]
npcs = [NPC('vivi', 100, 'people/vivi.png', 0, 400, 600), npcs = [NPC('vivi', 100, 'people/vivi.png', 0, 400, 600),
@ -327,7 +372,7 @@ class Room(GameObjects):
self.objects[2] = [random.choice(npcs)] self.objects[2] = [random.choice(npcs)]
else: else:
self.objects[1] = [Boss('reddy', 40, WIDTH / 2 - 16, HEIGHT /2 - 32, 50, 0.1, 1, 5, 5000)] self.objects[1] = [Boss('reddy', 40, WIDTH / 2 - 16, HEIGHT /2 - 32, 50, 0.1, 1, 5, 5000)]
self.objects[4] = [wall for wall in self.genWalls(WIDTH, HEIGHT)] self.objects[4].append(HealthBar(self.objects[1][0].name, self.objects[1][0].health, WIDTH / 2 - 128))
return self.objects return self.objects
@ -450,7 +495,8 @@ class Convo(Label):
['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.']], ['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', 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.']] ['vivi', 0, ['Wer bist du denn?', 'Aber du kannst gerne aus dem Fenster springen, solange es nicht in meinem Unterricht ist.']],
['fairy', 0, ['Hello fellow traveler.', 'I am Aurelia, a Whisperwind Fairy.', '''Do not worry about me. I won't harm anybody.''', 'You should still be careful around other fairies, many of them are insidious.', 'But fear not lonely traveller, I will help you survive.', 'Please take this spell for your further journey']]
] ]
def draw(self, screen): def draw(self, screen):
@ -476,7 +522,7 @@ class Convo(Label):
for i in range(0,5): for i in range(0,5):
objects[1].append(Rat('rat', random.randint(150,250), 800, 400+i*20, 1, 1, 1, 100, 25)) objects[1].append(Rat('rat', random.randint(150,250), 800, 400+i*20, 1, 1, 1, 100, 25))
elif convo[1] == 1: elif convo[1] == 1:
objects[0][0].level.level = 50 objects[0][0].level.level = 5
while 'rat' in objects[0][0].killed: objects[0][0].killed.remove('rat') while 'rat' in objects[0][0].killed: objects[0][0].killed.remove('rat')
elif convo[0] == 'elder': elif convo[0] == 'elder':
if convo[1] == 0: if convo[1] == 0:

874
main.py
View file

@ -1,436 +1,438 @@
import pygame import pygame
import sys import sys
import json import json
import time import time
import random import random
from classes import * from classes import *
# from viecher import * # from viecher import *
from pygame import mixer from pygame import mixer
fps = 60 fps = 60
def setUp(config): def setUp(config):
pygame.init() pygame.init()
mixer.music.load('audio/music/thebritons(1.1).mp3') mixer.music.load('audio/music/thebritons(1.1).mp3')
mixer.music.play(-1) mixer.music.play(-1)
if config["fullscreen"]: if config["fullscreen"]:
screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN) screen = pygame.display.set_mode(config["res"], pygame.FULLSCREEN)
else: else:
screen = pygame.display.set_mode(config["res"]) screen = pygame.display.set_mode(config["res"])
clock = pygame.time.Clock() clock = pygame.time.Clock()
pygame.display.set_caption('Between The Pages') pygame.display.set_caption('Between The Pages')
with open('art/images/icon.png', 'r') as i: with open('art/images/icon.png', 'r') as i:
pygame.display.set_icon(pygame.image.load(i)) pygame.display.set_icon(pygame.image.load(i))
return screen, clock, True, False, "startscreen.png", [] return screen, clock, True, False, "startscreen.png", []
def readConfig(): def readConfig():
with open('config.json', 'r') as c: with open('config.json', 'r') as c:
json_data = c.read() json_data = c.read()
return json.loads(json_data) return json.loads(json_data)
def quitGame(): def quitGame():
#save progress somehow, if needed #save progress somehow, if needed
pygame.quit() pygame.quit()
quit() quit()
def genRooms(WIDTH, HEIGHT, type:str, objects:list): def genRooms(WIDTH, HEIGHT, type:str, objects:list):
room_objects = [] room_objects = []
#room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)] #room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)]
room_objects.append(Obstacle('river', 'water', 'art/images/background/river.png', True, random.randint(32, round(WIDTH * 0.75)), 32, WIDTH=96, HEIGHT=round(HEIGHT * 0.66))) room_objects.append(Obstacle('river', 'water', 'art/images/background/river.png', True, random.randint(32, round(WIDTH * 0.75)), 32, WIDTH=96, HEIGHT=round(HEIGHT * 0.66)))
room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)] room_backgrounds = [f'art/images/background/{type}{i}.png' for i in range(1)]
rooms = [ rooms = [
Room(type, 'normal', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, 0)] for _ in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, j) Room(type, 'normal', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], objects[2], objects[3], objects[4] + [room_objects[random.randint(0, 0)] for _ in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, j)
for j in range(random.randint(5, 10)) for j in range(random.randint(5, 10))
] ]
rooms.append(Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88)) rooms.append(Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88))
#rooms = [Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88)] #rooms = [Room(type, 'boss', room_backgrounds[random.randint(0, 0)], [objects[0], objects[1], [], [], objects[4] + [room_objects[random.randint(0, 0)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, 88)]
#rooms =Room(type, 'normal', room_backgrounds[random.randint(0, 4)], [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j) #rooms =Room(type, 'normal', room_backgrounds[random.randint(0, 4)], [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, random.randint(0, 1))]], WIDTH - 64, HEIGHT - 64, [True, True, True, True], j)
return rooms return rooms
def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
main = [herbert] 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))] 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 = [] weapons = []
others = [] others = []
npcs = [] 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)
level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms))
scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level)
freeze = False #Gameplay is freezed in certain situations 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 = Label(WIDTH / 2 - 128, HEIGHT / 2 - 32, 256, 32, "To be continued", "damaged", 30, '#ffffff', 'empty.png')
tbc_tick = 0 tbc_tick = 0
objects = scene.getObjects() objects = scene.getObjects()
while running: while running:
screen.fill('#000000') screen.fill('#000000')
events = pygame.event.get() events = pygame.event.get()
for event in events: for event in events:
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
quitGame() quitGame()
elif event.type == pygame.KEYDOWN: elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_e: #when book is open gameplay is freezed if event.key == pygame.K_e: #when book is open gameplay is freezed
freeze = not freeze freeze = not freeze
# RENDER YOUR GAME HERE # RENDER YOUR GAME HERE
"""with open(background, 'r') as i: """with open(background, 'r') as i:
bg = pygame.image.load(i) bg = pygame.image.load(i)
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
# fill the screen with an image to clear the screen # fill the screen with an image to clear the screen
screen.blit(bg, (0, 0)) screen.blit(bg, (0, 0))
""" """
if isblack: if isblack:
if tbc_tick == 0: if tbc_tick == 0:
tbc_tick = pygame.time.get_ticks() tbc_tick = pygame.time.get_ticks()
elif tbc_tick + 5000 <= pygame.time.get_ticks(): elif tbc_tick + 5000 <= pygame.time.get_ticks():
quitGame() quitGame()
tbc.draw(screen) tbc.draw(screen)
elif not freeze: elif not freeze:
screen.blit(scene.background, (32, 32)) screen.blit(scene.background, (32, 32))
target = None target = None
for thing in objects[4]: for thing in objects[4]:
thing.draw(screen) thing.draw(screen)
if isinstance(thing, HealthBar):
for weapon in objects[3]: thing.update(objects)
weapon.update(objects)
weapon.draw(screen) for weapon in objects[3]:
weapon.update(objects)
for thing in objects[0]: weapon.draw(screen)
thing.book.hidden = not freeze
result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) for thing in objects[0]:
if objects[0][0].level.level >= 100: thing.book.hidden = not freeze
isblack = True result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects)
if isinstance(result, str): if objects[0][0].level.level >= 100:
if result == 'village': isblack = True
village(screen, clock, running, background, isblack, WIDTH, HEIGHT) if isinstance(result, str):
elif result == 'play': if result == 'village':
play(screen, clock, running, background, isblack, WIDTH, HEIGHT) village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
elif 'door-' in result: elif result == 'play':
target = result.split('-')[1] play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
objects[0][0].level.level += 25 elif 'door-' in result:
objects = scene.update(target, objects) target = result.split('-')[1]
#play(screen, clock, running, background, isblack, WIDTH, HEIGHT) objects[0][0].level.level += 6.33
else: objects = scene.update(target, objects)
thing.draw(screen) #play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
else: else:
thing.draw(screen) thing.draw(screen)
else:
for mob in objects[1]: thing.draw(screen)
mob.update(objects)
mob.draw(screen) for mob in objects[1]:
mob.update(objects)
for npc in objects[2]: mob.draw(screen)
npc.update(pygame.key.get_pressed(), objects)
npc.draw(screen) for npc in objects[2]:
npc.update(pygame.key.get_pressed(), objects)
objects[0][0].book.addspell('windslash') npc.draw(screen)
objects[0][0].book.addspell('fireball')
scene.update(target, objects) objects[0][0].book.addspell('windslash')
scene.draw(screen) objects[0][0].book.addspell('fireball')
scene.update(target, objects)
else: scene.draw(screen)
objects[0][0].book.hidden = not freeze
objects[0][0].book.draw(screen) else:
objects[0][0].book.update() objects[0][0].book.hidden = not freeze
# flip() the display to put your work on screen objects[0][0].book.draw(screen)
pygame.display.flip() objects[0][0].book.update()
# flip() the display to put your work on screen
clock.tick(fps) # limits FPS to 60 pygame.display.flip()
def village(screen, clock, running, background, isblack, WIDTH, HEIGHT): clock.tick(fps) # limits FPS to 60
main = [herbert]
mobs = [] def village(screen, clock, running, background, isblack, WIDTH, HEIGHT):
weapons = [] main = [herbert]
others = [ Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500), mobs = []
Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)] weapons = []
npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)] others = [ Obstacle('fireplace', 'interactable', 'art/images/background/fireplace.png', False, 200, 500),
objects = [main, mobs, npcs, weapons, others] Obstacle('house', 'Interactable', 'art/images/background/house.png', False, 500, 150, WIDTH=180, HEIGHT=160)]
room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, 0) npcs = [NPC('oldlady', 100, 'people/oldlady.png', 0, 200, 200)]
freeze = True #Gameplay is freezed in certain situations objects = [main, mobs, npcs, weapons, others]
main[0].health.health = 20 room = Room('village', 'village', 'art/images/background/village.png', objects, WIDTH - 64, HEIGHT - 64, 0)
freeze = True #Gameplay is freezed in certain situations
while running: main[0].health.health = 20
screen.fill('#000000')
events = pygame.event.get() while running:
for event in events: screen.fill('#000000')
if event.type == pygame.QUIT: events = pygame.event.get()
quitGame() for event in events:
elif event.type == pygame.KEYDOWN: if event.type == pygame.QUIT:
if event.key == pygame.K_e: #when book is open gameplay is freezed quitGame()
freeze = not freeze elif event.type == pygame.KEYDOWN:
# RENDER YOUR GAME HERE if event.key == pygame.K_e: #when book is open gameplay is freezed
"""with open(background, 'r') as i: freeze = not freeze
bg = pygame.image.load(i) # RENDER YOUR GAME HERE
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) """with open(background, 'r') as i:
# fill the screen with an image to clear the screen bg = pygame.image.load(i)
screen.blit(bg, (0, 0)) bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
""" # fill the screen with an image to clear the screen
if not freeze: screen.blit(bg, (0, 0))
objects = room.getObjects() """
screen.blit(room.background, (32, 32)) if not freeze:
objects = room.getObjects()
for thing in objects[4]: screen.blit(room.background, (32, 32))
thing.draw(screen)
for thing in objects[4]:
for weapon in objects[3]: thing.draw(screen)
weapon.update(objects)
weapon.draw(screen) for weapon in objects[3]:
weapon.update(objects)
for thing in objects[0]: weapon.draw(screen)
thing.book.hidden = not freeze
result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) for thing in objects[0]:
if result == 'village': thing.book.hidden = not freeze
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects)
elif result == 'play': if result == 'village':
play(screen, clock, running, background, isblack, WIDTH, HEIGHT) menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
elif result == 'house': elif result == 'play':
house(screen, clock, running, background, isblack, WIDTH, HEIGHT) play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
else: elif result == 'house':
thing.draw(screen) house(screen, clock, running, background, isblack, WIDTH, HEIGHT)
else:
for mob in objects[1]: thing.draw(screen)
mob.update(objects)
mob.draw(screen) for mob in objects[1]:
mob.update(objects)
for npc in objects[2]: mob.draw(screen)
npc.update(pygame.key.get_pressed(), objects)
npc.draw(screen) for npc in objects[2]:
npc.update(pygame.key.get_pressed(), objects)
room.update(objects) npc.draw(screen)
else: room.update(objects)
objects[0][0].book.hidden = not freeze
objects[0][0].book.draw(screen) else:
objects[0][0].book.update() objects[0][0].book.hidden = not freeze
# flip() the display to put your work on screen objects[0][0].book.draw(screen)
pygame.display.flip() objects[0][0].book.update()
# flip() the display to put your work on screen
clock.tick(fps) # limits FPS to pygame.display.flip()
def house(screen, clock, running, background, isblack, WIDTH, HEIGHT): clock.tick(fps) # limits FPS to
main = [herbert]
mobs = [] def house(screen, clock, running, background, isblack, WIDTH, HEIGHT):
weapons = [] main = [herbert]
others = [] mobs = []
npcs = [NPC('elder', 100, 'people/dorfaelteste.png', 0, 200, 200)] weapons = []
objects = [main, mobs, npcs, weapons, others] others = []
room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, 0) npcs = [NPC('elder', 100, 'people/dorfaelteste.png', 0, 200, 200)]
freeze = False #Gameplay is freezed in certain situations objects = [main, mobs, npcs, weapons, others]
room = Room('house', 'house', 'art/images/background/insideHouse.png', objects, WIDTH - 64, HEIGHT - 64, 0)
while running: freeze = False #Gameplay is freezed in certain situations
screen.fill('#000000')
events = pygame.event.get() while running:
for event in events: screen.fill('#000000')
if event.type == pygame.QUIT: events = pygame.event.get()
quitGame() for event in events:
elif event.type == pygame.KEYDOWN: if event.type == pygame.QUIT:
if event.key == pygame.K_e: #when book is open gameplay is freezed quitGame()
freeze = not freeze elif event.type == pygame.KEYDOWN:
# RENDER YOUR GAME HERE if event.key == pygame.K_e: #when book is open gameplay is freezed
"""with open(background, 'r') as i: freeze = not freeze
bg = pygame.image.load(i) # RENDER YOUR GAME HERE
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) """with open(background, 'r') as i:
# fill the screen with an image to clear the screen bg = pygame.image.load(i)
screen.blit(bg, (0, 0)) bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
""" # fill the screen with an image to clear the screen
if not freeze: screen.blit(bg, (0, 0))
objects = room.getObjects() """
screen.blit(room.background, (32, 32)) if not freeze:
objects = room.getObjects()
for thing in objects[4]: screen.blit(room.background, (32, 32))
thing.draw(screen)
for thing in objects[4]:
# for weapon in objects[3]: thing.draw(screen)
# weapon.update(objects)
# weapon.draw(screen) # for weapon in objects[3]:
# weapon.update(objects)
for thing in objects[0]: # weapon.draw(screen)
thing.book.hidden = not freeze
result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects) for thing in objects[0]:
if result == 'village': thing.book.hidden = not freeze
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) result = thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects)
elif result == 'play': if result == 'village':
play(screen, clock, running, background, isblack, WIDTH, HEIGHT) menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
elif result == 'wall': elif result == 'play':
village(screen, clock, running, background, isblack, WIDTH, HEIGHT) play(screen, clock, running, background, isblack, WIDTH, HEIGHT)
else: elif result == 'wall':
thing.draw(screen) village(screen, clock, running, background, isblack, WIDTH, HEIGHT)
else:
for npc in objects[2]: thing.draw(screen)
npc.update(pygame.key.get_pressed(), objects)
npc.draw(screen) for npc in objects[2]:
npc.update(pygame.key.get_pressed(), objects)
objects[0][0].book.addspell('windslash') npc.draw(screen)
room.update(objects)
objects[0][0].book.addspell('windslash')
else: room.update(objects)
objects[0][0].book.hidden = not freeze
objects[0][0].book.draw(screen) else:
objects[0][0].book.update() objects[0][0].book.hidden = not freeze
# flip() the display to put your work on screen objects[0][0].book.draw(screen)
pygame.display.flip() objects[0][0].book.update()
# flip() the display to put your work on screen
clock.tick(fps) # limits FPS to pygame.display.flip()
clock.tick(fps) # limits FPS to
def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
objects = []
# List that is displayed while selecting the window resolution level def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
resolution = [("1920x1080", "1920x1080"), objects = []
("1920x1200", "1920x1200"), # List that is displayed while selecting the window resolution level
("1280x720", "1280x720"), resolution = [("1920x1080", "1920x1080"),
("2560x1440", "2560x1440"), ("1920x1200", "1920x1200"),
("3840x2160", "3840x2160")] ("1280x720", "1280x720"),
("2560x1440", "2560x1440"),
# This function displays the currently selected options ("3840x2160", "3840x2160")]
def printSettings(): # This function displays the currently selected options
print("\n\n")
# getting the data using "get_input_data" method of the Menu class def printSettings():
settingsData = settings.get_input_data() print("\n\n")
# getting the data using "get_input_data" method of the Menu class
for key in settingsData.keys(): settingsData = settings.get_input_data()
print(f"{key}\t:\t{settingsData[key]}")
for key in settingsData.keys():
while running: print(f"{key}\t:\t{settingsData[key]}")
for event in pygame.event.get():
if event.type == pygame.QUIT: while running:
running = False for event in pygame.event.get():
# RENDER YOUR GAME HERE if event.type == pygame.QUIT:
with open(background, 'r') as i: running = False
bg = pygame.image.load(i) # RENDER YOUR GAME HERE
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) with open(background, 'r') as i:
# fill the screen with an image to clear the screen bg = pygame.image.load(i)
screen.blit(bg, (0, 0)) bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
for obj in objects: # fill the screen with an image to clear the screen
obj.process(screen) screen.blit(bg, (0, 0))
for obj in objects:
# flip() the display to put your work on screen obj.process(screen)
pygame.display.flip()
# flip() the display to put your work on screen
clock.tick(60) # limits FPS to 60 pygame.display.flip()
def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): clock.tick(60) # limits FPS to 60
objects = []
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Play", village, attributes=[screen, clock, running, background, isblack, WIDTH, HEIGHT])) def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) objects = []
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Play", village, attributes=[screen, clock, running, background, isblack, WIDTH, HEIGHT]))
while running: #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu))
for event in pygame.event.get(): objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame))
if event.type == pygame.QUIT: while running:
running = False for event in pygame.event.get():
quitGame() if event.type == pygame.QUIT:
# RENDER YOUR GAME HERE running = False
with open(f'art/images/background/{background}', 'r') as i: quitGame()
bg = pygame.image.load(i) # RENDER YOUR GAME HERE
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) with open(f'art/images/background/{background}', 'r') as i:
# fill the screen with an image to clear the screen bg = pygame.image.load(i)
screen.blit(bg, (0, 0)) bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
for obj in objects: # fill the screen with an image to clear the screen
obj.update(screen) screen.blit(bg, (0, 0))
for obj in objects:
# flip() the display to put your work on screen obj.update(screen)
pygame.display.flip()
# flip() the display to put your work on screen
clock.tick(60) # limits FPS to 60 pygame.display.flip()
def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): clock.tick(60) # limits FPS to 60
main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)]
mobs = [Skeleton(i, random.randint(40, 60), 'reddy.png', random.randint(20,1000), random.randint(20,700), 5, 1, 1, 1, 200) for i in range(0, random.randint(2, 8))] def test(screen, clock, running, background, isblack, WIDTH, HEIGHT):
others = [] main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)]
npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)] mobs = [Skeleton(i, random.randint(40, 60), 'reddy.png', random.randint(20,1000), random.randint(20,700), 5, 1, 1, 1, 200) for i in range(0, random.randint(2, 8))]
objects = [main, mobs, npcs, others] others = []
level = [] npcs = [NPC('name', 100, 'reddy.png', 1, 200, 200)]
rooms = genRooms(WIDTH, HEIGHT, 'grass', objects) objects = [main, mobs, npcs, others]
level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms)) level = []
freeze = False #Gameplay is freezed in certain situations rooms = genRooms(WIDTH, HEIGHT, 'grass', objects)
level.append(Stage('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', rooms))
#level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ freeze = False #Gameplay is freezed in certain situations
# Room('red1', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 0),
# Room('red2', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), #level.append(Stage('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [
# Room('red3', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), # Room('red1', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 0),
# ])) # Room('red2', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 1),
# Room('red3', 'normal', 'art/images/grass.png', [], WIDTH, HEIGHT, [True, True, True, False], 2),
scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) # ]))
# RENDER YOUR GAME HERE scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level)
while True:
screen.fill('#000000') # RENDER YOUR GAME HERE
events = pygame.event.get() while True:
for event in events: screen.fill('#000000')
if event.type == pygame.QUIT: events = pygame.event.get()
running = False for event in events:
quitGame() if event.type == pygame.QUIT:
elif event.type == pygame.KEYDOWN: running = False
if event.key == pygame.K_e: #when book is open gameplay is freezed quitGame()
freeze = not freeze elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_e: #when book is open gameplay is freezed
if not freeze: freeze = not freeze
objects = scene.getObjects()
for thing in objects[0]: if not freeze:
thing.book.hidden = not freeze objects = scene.getObjects()
if not thing.update(pygame.key.get_pressed(), objects): for thing in objects[0]:
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) thing.book.hidden = not freeze
thing.draw(screen) if not thing.update(pygame.key.get_pressed(), objects):
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
for mob in objects[1]: thing.draw(screen)
mob.update(objects)
mob.draw(screen) for mob in objects[1]:
mob.update(objects)
for npc in objects[2]: mob.draw(screen)
npc.update(pygame.key.get_pressed(), objects)
npc.draw(screen) for npc in objects[2]:
npc.update(pygame.key.get_pressed(), objects)
for thing in objects[3]: npc.draw(screen)
thing.update(objects)
thing.draw(screen) for thing in objects[3]:
thing.update(objects)
else: thing.draw(screen)
objects[0][0].book.hidden = not freeze
objects[0][0].book.draw(screen) else:
objects[0][0].book.update() objects[0][0].book.hidden = not freeze
# flip() the display to put your work on screen objects[0][0].book.draw(screen)
pygame.display.flip() objects[0][0].book.update()
# flip() the display to put your work on screen
clock.tick(60) # limits FPS to 60 pygame.display.flip()
def main(): clock.tick(60) # limits FPS to 60
config = readConfig()
screen, clock, running, isblack, background, objects = setUp(config["screen"]) def main():
WIDTH, HEIGHT = screen.get_size() config = readConfig()
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Play", play)) screen, clock, running, isblack, background, objects = setUp(config["screen"])
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu)) WIDTH, HEIGHT = screen.get_size()
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame)) #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Play", play))
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu))
#test(screen, clock, running, background, isblack, WIDTH, HEIGHT) #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)
"""while running: #test(screen, clock, running, background, isblack, WIDTH, HEIGHT)
for event in pygame.event.get():
if event.type == pygame.QUIT: """while running:
running = False for event in pygame.event.get():
#menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) if event.type == pygame.QUIT:
if not isblack: running = False
with open(background, 'r') as i: #menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
bg = pygame.image.load(i) if not isblack:
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT)) with open(background, 'r') as i:
# fill the screen with a color to wipe away anything from last frame bg = pygame.image.load(i)
screen.blit(bg, (0, 0)) bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
# fill the screen with a color to wipe away anything from last frame
# RENDER YOUR GAME HERE screen.blit(bg, (0, 0))
else: # RENDER YOUR GAME HERE
for obj in objects:
obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) else:
# flip() the display to put your work on screen for obj in objects:
pygame.display.flip() obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT)
# flip() the display to put your work on screen
clock.tick(60) # limits FPS to 60""" pygame.display.flip()
pygame.quit() clock.tick(60) # limits FPS to 60"""
if __name__ == '__main__': pygame.quit()
herbert = MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50)
main() if __name__ == '__main__':
herbert = MainCharacter('Herbert', 100, 'people/oldman.png', 500, 500, 20, 5, 1, 1, 50)
main()