Compare commits

...

4 commits

Author SHA1 Message Date
b921da8a9a Merge pull request 'First movement and game object managing/handling' (#36) from Spafi/game:main into Development
Reviewed-on: #36
2024-02-16 17:09:44 +00:00
SpagettiFisch
8f78002015 resorted the Scene class into a subclass of GameObjects
added the class Room to GameObjects
added a very simple start screen
WIP: disabled option button until option function is implemented

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-02-16 18:05:03 +01:00
SpagettiFisch
4e1674d6f3 added new classes to READ.ME
Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-02-16 18:03:05 +01:00
SpagettiFisch
2e66145dcc first movement (wasd) with character integrated
started a new class for scenes

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
2024-02-16 17:34:37 +01:00
7 changed files with 139 additions and 24 deletions

14
READ.ME
View file

@ -37,3 +37,17 @@ fonts = {
}
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

BIN
art/images/reddy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

BIN
art/images/start.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

View file

Before

Width:  |  Height:  |  Size: 644 B

After

Width:  |  Height:  |  Size: 644 B

View file

@ -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,13 +53,17 @@ 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:
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:
@ -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

55
main.py
View file

@ -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
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()

56
viecher.py Normal file
View file

@ -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)