startscreen added

also some buttons added to be completed
button class initalized

Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
This commit is contained in:
SpagettiFisch 2024-02-13 10:21:42 +01:00
parent 418ae5ee7b
commit 51a287ba66
8 changed files with 43 additions and 9 deletions

BIN
art/exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

BIN
art/new_game.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

BIN
art/options.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

BIN
art/textbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

25
classes.py Normal file
View file

@ -0,0 +1,25 @@
import pygame
font = pygame.font.SysFont('Arial', 40)
class Button():
def __init__(self, x, y, width, height, buttonText='Button', onclickFunction=None, onePress=False):
self.x = x
self.y = y
self.width = width
self.height = height
self.onclickFunction = onclickFunction
self.onePress = onePress
self.alreadyPressed = False
self.fillColors = {
'normal': '#ffffff',
'hover': '#666666',
'pressed': '#333333',
}
self.buttonSurface = pygame.Surface((self.width, self.height))
self.buttonRect = pygame.Rect(self.x, self.y, self.width, self.height)
self.buttonSurf = font.render(buttonText, True, (20, 20, 20))
return self

View file

@ -1,7 +1,7 @@
{
"screen":
{
"res":[1120, 780],
"res":[1280, 720],
"fullscreen": false
}
}

17
main.py
View file

@ -10,8 +10,9 @@ def setUp(config):
else:
screen = pygame.display.set_mode(config["res"])
clock = pygame.time.Clock()
running = True
return screen, clock, running
with open('art/textbox.png', 'r') as tb:
box = pygame.image.load(tb)
return screen, clock, True, True, "start.png", box
def readConfig():
with open('config.json', 'r') as c:
@ -20,16 +21,24 @@ def readConfig():
def main():
config = readConfig()
screen, clock, running = setUp(config["screen"])
screen, clock, running, background, isblack, box = setUp(config["screen"])
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if not isblack:
with open(background, 'r') as i:
bg = pygame.image.load(i)
bg = pygame.transform.scale(bg, screen.get_size())
# fill the screen with a color to wipe away anything from last frame
screen.fill("purple")
screen.blit(bg, (0, 0))
# RENDER YOUR GAME HERE
else:
screen.fill('#000000')
# flip() the display to put your work on screen
pygame.display.flip()

BIN
test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 KiB