diff --git a/READ.ME b/READ.ME index bf83747..156111f 100644 --- a/READ.ME +++ b/READ.ME @@ -36,4 +36,18 @@ fonts = { 'pixel': 'yoster.ttf' } -Pygame window: (0, 0) is in the top left corner, the height and width are stored in HEIGHT and WIDTH \ No newline at end of file +Pygame window: (0, 0) is in the top left corner, the height and width are stored in HEIGHT and WIDTH + +GameObjects for rooms, scenes and maybe MorialCitadel + +Scene: + type - normal, dungeon, cutscene + objects - contain rooms, npcs, mobs, the character etc. + +Room: + type - normal, shop, special (?), boss + objects - npcs, mobs, the character etc. + exits - position of exits --> [top:bool, right:bool, down:bool, left:bool]; 1 to 4 exits per room + locked - bool if the room is unlocked; locked upon first entering unless all mobs are dead + + diff --git a/art/images/reddy.png b/art/images/reddy.png new file mode 100644 index 0000000..40954a2 Binary files /dev/null and b/art/images/reddy.png differ diff --git a/art/images/start.png b/art/images/start.png new file mode 100644 index 0000000..3d7f7c5 Binary files /dev/null and b/art/images/start.png differ diff --git a/art/image files/textbox.png b/art/images/textbox.png similarity index 100% rename from art/image files/textbox.png rename to art/images/textbox.png diff --git a/classes.py b/classes.py index 8231fcd..d288c1d 100644 --- a/classes.py +++ b/classes.py @@ -44,7 +44,7 @@ class Button(): self.onePress = onePress self.alreadyPressed = False - with open('art/textbox.png', 'r') as tb: + with open('art/images/textbox.png', 'r') as tb: self.box = pygame.image.load(tb) self.box = pygame.transform.scale(self.box, (width, height)) @@ -53,15 +53,19 @@ class Button(): self.buttonSurf = self.font.render(buttonText, True, '#baab80') - def process(self, screen): + def process(self, screen, clock, running, background, isblack, WIDTH, HEIGHT): mousePos = pygame.mouse.get_pos() if self.buttonRect.collidepoint(mousePos): if pygame.mouse.get_pressed(num_buttons=3)[0]: if self.onePress: self.onclickFunction() elif not self.alreadyPressed: - self.onclickFunction() - self.alreadyPressed = True + if 'play' in str(self.onclickFunction): + self.onclickFunction(screen, clock, running, background, isblack, WIDTH, HEIGHT) + self.alreadyPressed = True + else: + self.onclickFunction() + self.alreadyPressed = True else: self.alreadyPressed = False self.box.blit(self.buttonSurf, [ @@ -81,7 +85,7 @@ class DropDown(): self.menu_active = False self.active_option = -1 - with open('art/textbox.png', 'r') as tb: + with open('art/images/textbox.png', 'r') as tb: self.box = pygame.image.load(tb) self.box = pygame.transform.scale(self.box, (width, height)) @@ -133,4 +137,24 @@ class DropDown(): return -1 +class GameObjects(): + def __init__(self, name:str, _type:str, bg, objects:list) -> None: + self.name = name + self.type = _type + self.background = bg + self.objects = objects + +class Scene(GameObjects): + def __init__(self, name:str, _type:str, bg, objects:list) -> None: + super().__init__(name, _type, bg, objects) + + +class Room(GameObjects): + def __init__(self, name:str, _type:str, bg, objects:list, exits:list) -> None: + super().__init__(name, _type, bg, objects) + self.exits = exits + if self.type == 'normal' or self.type == 'boss': + self.locked = True + else: + self.locked = False diff --git a/main.py b/main.py index e7a7046..d4c669f 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ import sys import json import time from classes import * +from viecher import * +fps = 60 def setUp(config): pygame.init() @@ -22,10 +24,31 @@ def readConfig(): def quitGame(): #save progress somehow, if needed pygame.quit() - sys.exit() + quit() -def uwu(): - print('uwu') +def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): + objects = [] + objects.append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50)) + while running: + screen.fill('#000000') + events = pygame.event.get() + for event in events: + if event.type == pygame.QUIT: + quitGame() + # 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)) +""" + for obj in objects: + obj.update(pygame.key.get_pressed()) + obj.draw(screen) + # flip() the display to put your work on screen + pygame.display.flip() + + clock.tick(fps) # limits FPS to 60 def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): objects = [] @@ -66,21 +89,22 @@ def options(screen, clock, running, background, isblack, WIDTH, HEIGHT): def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT): objects = [] + objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Play", play)) + #objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Options", uwu)) objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame)) - 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, "Play", uwu)) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: - running = False + running = False + quitGame() # RENDER YOUR GAME HERE - with open(background, 'r') as i: + with open(f'art/images/{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)) for obj in objects: - obj.process(screen) + obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) # flip() the display to put your work on screen pygame.display.flip() @@ -91,9 +115,11 @@ def main(): config = readConfig() screen, clock, running, isblack, background, objects = setUp(config["screen"]) WIDTH, HEIGHT = screen.get_size() - list1 = DropDown(50, 50, 128, 48, 'simple', 32, ['#881188', '#220044'], ['#991122', '#33ff11'], 'Test', ['Test 2', 'Test 17', '982']) - - while running: + #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)) + menu(screen, clock, running, background, isblack, WIDTH, HEIGHT) + """while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False @@ -108,17 +134,12 @@ def main(): # RENDER YOUR GAME HERE else: - selected_option = list1.update(pygame.event.get()) - if selected_option >= 0: - list1.main = list1.options[selected_option] - screen.fill('#000000') - list1.draw(screen) for obj in objects: - obj.process(screen) + obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT) # flip() the display to put your work on screen pygame.display.flip() - clock.tick(60) # limits FPS to 60 + clock.tick(60) # limits FPS to 60""" pygame.quit() diff --git a/viecher.py b/viecher.py new file mode 100644 index 0000000..1cb3211 --- /dev/null +++ b/viecher.py @@ -0,0 +1,56 @@ +import pygame +fps = 60 + +class Character(): + def __init__(self, name, ms, sprite) -> None: + self.name = name + self.speed = ms + with open(f'art/images/{sprite}') as i: + self.sprite = pygame.image.load(i) + self.x = 524 + self.y = 524 + self.hidden = False + + self.rect = pygame.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height()) + + def draw(self, screen): + if self.hidden: + return + self.rect.x, self.rect.y = self.x, self.y + screen.blit(self.sprite, self.rect) + + +class NPC(Character): + pass + + +class Fighter(Character): + def __init__(self, name, ms, sprite, health, damage, level, asp, atr) -> None: + super().__init__(name, ms, sprite) + self.health = health + self.damage = damage + self.level = level + self.attack_speed = asp + self.attack_range = atr + +class MainCharacter(Fighter): + def __init__(self, name, ms, sprite, health, damage, level, asp, atr, weapon=None, shield=None) -> None: + super().__init__(name, ms, sprite, health, damage, level, asp, atr) + self.attack_spell = weapon + self.shield_spell = shield + self.talking = False + + def update(self, keys): + if keys[pygame.K_w]: + self.y -= self.speed / fps + if keys[pygame.K_a]: + self.x -= self.speed / fps + if keys[pygame.K_s]: + self.y += self.speed / fps + if keys[pygame.K_d]: + self.x += self.speed / fps + +class Mobs(Fighter): + def __init__(self, name, ms, sprite, health, damage, level, asp, atr, drops) -> None: + super().__init__(name, ms, sprite, health, damage, level, asp, atr) + self.drops = drops * (self.level / 2)