Compare commits

..

No commits in common. "8f78002015ee079ab752490a5c1cd2c2513cfaa3" and "ea6d64b0875759c079e3e13205e2b42a6ae40b9c" have entirely different histories.

7 changed files with 24 additions and 139 deletions

16
READ.ME
View file

@ -36,18 +36,4 @@ fonts = {
'pixel': 'yoster.ttf'
}
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
Pygame window: (0, 0) is in the top left corner, the height and width are stored in HEIGHT and WIDTH

View file

Before

Width:  |  Height:  |  Size: 644 B

After

Width:  |  Height:  |  Size: 644 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

View file

@ -44,7 +44,7 @@ class Button():
self.onePress = onePress
self.alreadyPressed = False
with open('art/images/textbox.png', 'r') as tb:
with open('art/textbox.png', 'r') as tb:
self.box = pygame.image.load(tb)
self.box = pygame.transform.scale(self.box, (width, height))
@ -53,19 +53,15 @@ class Button():
self.buttonSurf = self.font.render(buttonText, True, '#baab80')
def process(self, screen, clock, running, background, isblack, WIDTH, HEIGHT):
def process(self, screen):
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:
if 'play' in str(self.onclickFunction):
self.onclickFunction(screen, clock, running, background, isblack, WIDTH, HEIGHT)
self.alreadyPressed = True
else:
self.onclickFunction()
self.alreadyPressed = True
self.onclickFunction()
self.alreadyPressed = True
else:
self.alreadyPressed = False
self.box.blit(self.buttonSurf, [
@ -85,7 +81,7 @@ class DropDown():
self.menu_active = False
self.active_option = -1
with open('art/images/textbox.png', 'r') as tb:
with open('art/textbox.png', 'r') as tb:
self.box = pygame.image.load(tb)
self.box = pygame.transform.scale(self.box, (width, height))
@ -137,24 +133,4 @@ 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

57
main.py
View file

@ -3,8 +3,6 @@ import sys
import json
import time
from classes import *
from viecher import *
fps = 60
def setUp(config):
pygame.init()
@ -24,31 +22,10 @@ def readConfig():
def quitGame():
#save progress somehow, if needed
pygame.quit()
quit()
sys.exit()
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 uwu():
print('uwu')
def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
objects = []
@ -89,22 +66,21 @@ 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
quitGame()
running = False
# RENDER YOUR GAME HERE
with open(f'art/images/{background}', 'r') as i:
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.process(screen, clock, running, background, isblack, WIDTH, HEIGHT)
obj.process(screen)
# flip() the display to put your work on screen
pygame.display.flip()
@ -115,11 +91,9 @@ def main():
config = readConfig()
screen, clock, running, isblack, background, objects = setUp(config["screen"])
WIDTH, HEIGHT = screen.get_size()
#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:
list1 = DropDown(50, 50, 128, 48, 'simple', 32, ['#881188', '#220044'], ['#991122', '#33ff11'], 'Test', ['Test 2', 'Test 17', '982'])
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
@ -134,12 +108,17 @@ 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, clock, running, background, isblack, WIDTH, HEIGHT)
obj.process(screen)
# 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()

View file

@ -1,56 +0,0 @@
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)