made a huge progress on how the game is gonna go (in code, basically level2 finished)

This commit is contained in:
Martin Dvořák 2026-05-31 17:55:23 +02:00
commit b867506b56
4 changed files with 81 additions and 9 deletions

View file

@ -1,25 +1,96 @@
import pygame
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, 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
def level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick): # 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, 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
mainmenu_text = big_text.render("Revival Inc.", True, (0, 0, 0))
playb_collision = pygame.Rect(250, 250, 253, 110)
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))
play_text = basicfont.render("Play", True, (255,255,255))
if click:
level = 2
else:
screen.blit(load_sprite(sheet, 0, 36, 23, 10, 253, 110), (250, 250))
play_text = basicfont.render("Play", True, (0,0,0))
screen.blit(play_text, (300, 260))
if exitb_collision.collidepoint(mouse.get_pos()):
screen.blit(load_sprite(sheet, 24, 36, 23, 10, 253, 110), (250, 400))
exit_text = basicfont.render("Exit", True, (255,255,255))
if click:
level = 0
else:
screen.blit(load_sprite(sheet, 0, 36, 23, 10, 253, 110), (250, 400))
exit_text = basicfont.render("Exit", True, (0,0,0))
screen.blit(exit_text, (300, 410))
screen.blit(mainmenu_text, (195, 35))
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
print("ur done") # prints out "ur done"
def level2(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, smalltext): # function for level 2
screen.blit(load_sprite(sheet, 0, 46, 48, 36, screen_width, screen_height), (0,0))
screen.blit(load_sprite(sheet, 8, 82, 12, 12, 96, 96) , (645, 214)) # ZOMBIE
screen.blit(load_sprite(sheet, 20, 82, 7, 12, 49,74), (274, 342)) # MILK CARTON
print(tick)
dialog_square = pygame.surface.Surface((700, 68), pygame.SRCALPHA)
dialog_square.fill((0, 0, 0))
if 60 <= tick <= 400:
if tick < 186:
dialog = basicfont.render("Hey...", True, (0+tick*2-120, 0+tick*2-120, 0+tick*2-120))
else:
dialog = basicfont.render("Hey...", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif 401 <= tick <= 750:
if tick < 525:
dialog = smalltext.render("ur probably wondering where u are.", True, (0+(tick-401)*2, 0+(tick-401)*2, 0+(tick-401)*2))
else:
dialog = smalltext.render("ur probably wondering where u are.", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif 751 <= tick <= 1000:
if tick < 876:
dialog = smalltext.render("you are inside the dungeons.", True, (0+(tick-751)*2, 0+(tick-751)*2, 0+(tick-751)*2))
else:
dialog = smalltext.render("you are inside the dungeons.", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif 1001 <= tick <= 1300:
if tick < 1126:
dialog = smalltext.render("see that milk?", True, (0+(tick-1001)*2, 0+(tick-1001)*2, 0+(tick-1001)*2))
else:
dialog = smalltext.render("see that milk?", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif 1301 <= tick <= 1600:
if tick < 1426:
dialog = smalltext.render("no its not for drinking", True, (0+(tick-1301)*2, 0+(tick-1301)*2, 0+(tick-1301)*2))
else:
dialog = smalltext.render("no its not for drinking", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif 1601 <= tick <= 1900:
if tick < 1626:
dialog = smalltext.render("see that dead zombie?", True, (0+(tick-1601)*2, 0+(tick-1601)*2, 0+(tick-1601)*2))
else:
dialog = smalltext.render("see that dead zombie?", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif 1901 <= tick <= 2200:
if tick < 2026:
dialog = smalltext.render("well guess what", True, (0+(tick-1901)*2, 0+(tick-1901)*2, 0+(tick-1901)*2))
else:
dialog = smalltext.render("well guess what", True, (255, 255, 255))
dialog_square.blit(load_sprite(sheet, 0, 82, 8, 8, 48, 48), (15, 10))
dialog_square.blit(dialog, (78, 15))
screen.blit(dialog_square, (34, 500))
elif tick <= 2201:
level = 3
return level # returns the current level set

13
main.py
View file

@ -7,12 +7,14 @@ def main(fps=window_fps): # the main function
pygame.init() # initalizes pygame
screen_width = 768 # the screen width
screen_height = 576 # the screen height
tick = 0
# 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
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
basicfont = pygame.font.SysFont(None, 50) # this sets a basic font for now, we can change this to anything later onvariable
smalltext = pygame.font.Font('Monocraft.ttf', 25)
basicfont = pygame.font.Font('Monocraft.ttf', 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
click = False # variable I use to check if u clicked with the mouse when calling level function from levels.
@ -33,18 +35,17 @@ def main(fps=window_fps): # the main function
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
click = False # sets the click variable to False so level function in levels.py can see again
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
level = levels.level1(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigtext, level, tick) # 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
elif level == 2: # what happens when the level variable is equal to 2 ofc
level = levels.level2(screen, sheet, lastclickpos, basicfont, pygame.mouse, click, level) # runs the level2 function from levels.py
fps_text = basicfont.render(str(int(clock.get_fps())), True, (0, 255, 0)) # defines a thing that renders your fps in the top left corner
tick += 1
level = levels.level2(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigtext, level, tick, smalltext) # runs the level2 function from levels.py
fps_text = smalltext.render(str(int(clock.get_fps())), True, (0, 255, 0)) # defines a thing that renders your fps in the top left corner
screen.blit(fps_text, (5, 5)) # this actually renders "ftp_text" on the screen at the position (5, 5) which is the top left corner
pygame.display.flip() # this updates the display so it displays all the new stuff we added
clock.tick(fps) # this makes sure the game loop runs at the fps we set it to before

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Before After
Before After

Binary file not shown.