diff --git a/art/images/blau1.kra b/art/images/blau1.kra new file mode 100644 index 0000000..ea14ba2 Binary files /dev/null and b/art/images/blau1.kra differ diff --git a/art/images/blau1.png b/art/images/blau1.png new file mode 100644 index 0000000..8c831a4 Binary files /dev/null and b/art/images/blau1.png differ diff --git a/art/images/blau2.png b/art/images/blau2.png new file mode 100644 index 0000000..ad3a521 Binary files /dev/null and b/art/images/blau2.png differ diff --git a/art/images/blau3.png b/art/images/blau3.png new file mode 100644 index 0000000..6432f79 Binary files /dev/null and b/art/images/blau3.png differ diff --git a/art/images/rot1.png b/art/images/rot1.png new file mode 100644 index 0000000..209753c Binary files /dev/null and b/art/images/rot1.png differ diff --git a/art/images/rot2.png b/art/images/rot2.png new file mode 100644 index 0000000..4b76d59 Binary files /dev/null and b/art/images/rot2.png differ diff --git a/art/images/rot3.png b/art/images/rot3.png new file mode 100644 index 0000000..a892101 Binary files /dev/null and b/art/images/rot3.png differ diff --git a/classes.py b/classes.py index d288c1d..d88f736 100644 --- a/classes.py +++ b/classes.py @@ -1,4 +1,5 @@ import pygame +import inspect pygame.font.init() fonts = { @@ -138,23 +139,70 @@ class DropDown(): class GameObjects(): - def __init__(self, name:str, _type:str, bg, objects:list) -> None: + def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT) -> None: self.name = name 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]) self.objects = objects class Scene(GameObjects): - def __init__(self, name:str, _type:str, bg, objects:list) -> None: - super().__init__(name, _type, bg, objects) + def __init__(self, name:str, _type:str, bg, objects:list | None, WIDTH, HEIGHT, level:list) -> None: + super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) + self.level = level + self.current_level = 0 + def update(self, change:bool): + if change: + self.current_level += 1 + self.level[self.current_level].update() + for obj in self.objects: + obj.update() + + + def draw(self, screen): + for obj in self.objects: + obj.draw(screen) + self.level[self.current_level].draw(screen) + + +class Level(GameObjects): + def __init__(self, name: str, _type: str, bg, objects: list, WIDTH, HEIGHT, stage:str, rooms:list) -> None: + super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) + self.stage = stage + self.rooms = rooms + self.current = 0 + + def update(self): + for room in self.rooms: + if room.id == self.current: + room.update() + 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: + if room.id == self.current: + room.draw(screen) class Room(GameObjects): - def __init__(self, name:str, _type:str, bg, objects:list, exits:list) -> None: - super().__init__(name, _type, bg, objects) + def __init__(self, name:str, _type:str, bg, objects:list, WIDTH, HEIGHT, exits:list, id:int) -> None: + super().__init__(name, _type, bg, objects, WIDTH, HEIGHT) self.exits = exits + self.id = id if self.type == 'normal' or self.type == 'boss': self.locked = True else: self.locked = False + + def update(self): + pass + + def draw(self, screen): + screen.blit(self.background, (0, 0)) + \ No newline at end of file diff --git a/main.py b/main.py index d4c669f..1b61739 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ def setUp(config): else: screen = pygame.display.set_mode(config["res"]) clock = pygame.time.Clock() - + return screen, clock, True, True, "start.png", [] def readConfig(): @@ -27,8 +27,8 @@ def quitGame(): quit() def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): - objects = [] - objects.append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) + objects = [[], [], []] #0 - maincharacter stuff; 1 - mobs; 2 - npcs + objects[0].append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) while running: screen.fill('#000000') events = pygame.event.get() @@ -103,6 +103,7 @@ def menu(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)) + for obj in objects: obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) @@ -111,6 +112,38 @@ def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): clock.tick(60) # limits FPS to 60 +def test(screen, clock, running, background, isblack, WIDTH, HEIGHT): + level = [] + level.append(Level('blau', 'normal', None, [], WIDTH, HEIGHT, 'blue', [ + Room('blau1', 'normal', 'art/images/blau1.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), + Room('blau2', 'normal', 'art/images/blau2.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), + Room('blau3', 'normal', 'art/images/blau3.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), + ])) + + level.append(Level('rot', 'normal', None, [], WIDTH, HEIGHT, 'red', [ + Room('red1', 'normal', 'art/images/rot1.png', [], WIDTH, HEIGHT, [True, True, True, False], 0), + Room('red2', 'normal', 'art/images/rot2.png', [], WIDTH, HEIGHT, [True, True, True, False], 1), + Room('red3', 'normal', 'art/images/rot3.png', [], WIDTH, HEIGHT, [True, True, True, False], 2), + ])) + + scene = Scene('test', 'normal', None, None, WIDTH, HEIGHT, level) + + # RENDER YOUR GAME HERE + while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + quitGame() + + scene.update() + scene.draw(screen) + # flip() the display to put your work on screen + pygame.display.flip() + + clock.tick(60) # limits FPS to 60 + + + def main(): config = readConfig() screen, clock, running, isblack, background, objects = setUp(config["screen"]) @@ -118,6 +151,7 @@ def main(): #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", play)) #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu)) #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) + test(screen, clock, running, background, isblack, WIDTH, HEIGHT) menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) """while running: for event in pygame.event.get():