early main menu

This commit is contained in:
Martin Dvořák 2026-05-31 17:08:04 +02:00
commit 76695db6e6
6 changed files with 35 additions and 12 deletions

BIN
Monocraft.ttf Normal file

Binary file not shown.

View file

@ -1,3 +1,6 @@
# Revival Inc. # Revival Inc.
The game for the Mini Jame Gam #55 made in pygame The game for the Mini Jame Gam #55 made in pygame
# Credits for external resources
FONT: https://github.com/IdreesInc/Monocraft

View file

@ -1,10 +1,24 @@
import pygame
from render import load_sprite # this makes it so our function for rendering sprites from sprites.png is available in here from render import load_sprite # this makes it so our function for rendering sprites from sprites.png is available in here
def level1(screen, sheet, lastclickpos, basicfont, mouse, click, level): # the function for our first level, ignore the unused variables here, you can use them when you edit it def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level): # the function for our first level, ignore the unused variables here, you can use them when you edit it
screen.blit(load_sprite(sheet, 0, 0, 26, 8, 210, 60), (200, 200)) # this renders a button I made in the sprites.png, its purely for visual purposes so it doesnt matter where you click rn screen.blit(load_sprite(sheet, 0, 0, 48, 36, screen_width, screen_height), (0, 0)) # this renders a button I made in the sprites.png, its purely for visual purposes so it doesnt matter where you click rn
if click: # this checks if you clicked, when you clicked it does the following stuff under mainmenu_text = big_text.render("Revival Inc.", True, (0, 0, 0))
level = 2 # sets the level to 2 playb_collision = pygame.Rect(250, 250, 253, 110)
print("yo") # prints out "yo" for debugging purposes, otherwise completely unnecessary exitb_collision = pygame.Rect(250, 400, 253, 110)
if playb_collision.collidepoint(mouse.get_pos()):
screen.blit(load_sprite(sheet, 24, 36, 23, 10, 253, 110), (250, 250))
if click:
level = 2
else:
screen.blit(load_sprite(sheet, 0, 36, 23, 10, 253, 110), (250, 250))
if exitb_collision.collidepoint(mouse.get_pos()):
screen.blit(load_sprite(sheet, 24, 36, 23, 10, 253, 110), (250, 400))
if click:
level = 0
else:
screen.blit(load_sprite(sheet, 0, 36, 23, 10, 253, 110), (250, 400))
screen.blit(mainmenu_text, (195, 35))
return level # this returns the change we made to the level so that it updates in main.py return level # this returns the change we made to the level so that it updates in main.py
def level2(screen, sheet, lastclickpos, basicfont, mouse, click, level): # function for level 2 def level2(screen, sheet, lastclickpos, basicfont, mouse, click, level): # function for level 2
print("ur done") # prints out "ur done" print("ur done") # prints out "ur done"

18
main.py
View file

@ -5,13 +5,15 @@ window_fps = 60 # the frames per second, this decides how fast the main loop ru
def main(fps=window_fps): # the main function def main(fps=window_fps): # the main function
pygame.init() # initalizes pygame pygame.init() # initalizes pygame
screen_width = 800 # the screen width screen_width = 768 # the screen width
screen_height = 500 # the screen height screen_height = 576 # the screen height
title = "Example Title" # the title of the window obviously # for sprites 48x36
title = "Revival Inc." # the title of the window obviously
lastclickpos = [0, 0] # last position that was clicked, this changes every time you click somewhere on the game window lastclickpos = [0, 0] # last position that was clicked, this changes every time you click somewhere on the game window
screen = pygame.display.set_mode((screen_width, screen_height)) # this initalizes the display with the screen_width and screen_height variables screen = pygame.display.set_mode((screen_width, screen_height)) # this initalizes the display with the screen_width and screen_height variables
pygame.display.set_caption(title) # this actually sets the title of the window from the title variable pygame.display.set_caption(title) # this actually sets the title of the window from the title variable
basicfont = pygame.font.SysFont(None, 30) # this sets a basic font for now, we can change this to anything later on basicfont = pygame.font.SysFont(None, 50) # this sets a basic font for now, we can change this to anything later onvariable
bigtext = pygame.font.Font('Monocraft.ttf', 50)
clock = pygame.time.Clock() # this is used to control the fps of the game if you scroll down the code a bit clock = pygame.time.Clock() # this is used to control the fps of the game if you scroll down the code a bit
click = False # variable I use to check if u clicked with the mouse when calling level function from levels. click = False # variable I use to check if u clicked with the mouse when calling level function from levels.
sheet = pygame.image.load("sprites.png") # the sprite sheet which we then use to load specific sprites from sheet = pygame.image.load("sprites.png") # the sprite sheet which we then use to load specific sprites from
@ -31,8 +33,12 @@ def main(fps=window_fps): # the main function
lastclickpos = pygame.mouse.get_pos() # sets the variable to the position you last clicked lastclickpos = pygame.mouse.get_pos() # sets the variable to the position you last clicked
if event.type == pygame.MOUSEBUTTONUP: # what happens when you release a mouse button if event.type == pygame.MOUSEBUTTONUP: # what happens when you release a mouse button
click = False # sets the click variable to False so level function in levels.py can see again click = False # sets the click variable to False so level function in levels.py can see again
if level == 1: # what happens when the level variable is equal to 1
level = levels.level1(screen, sheet, lastclickpos, basicfont, pygame.mouse, click, level) # runs the level1 function from levels.py if level == 0:
running = False
elif level == 1: # what happens when the level variable is equal to 1
level = levels.level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigtext, level) # runs the level1 function from levels.py
# THE REASON WE CALL IT LIKE THIS INSTEAD OF NORMALLY IS SO WE CAN CHANGE THE LEVEL VARIABLE # THE REASON WE CALL IT LIKE THIS INSTEAD OF NORMALLY IS SO WE CAN CHANGE THE LEVEL VARIABLE

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After

Binary file not shown.