This commit is contained in:
Martin Dvořák 2026-05-31 23:12:55 +02:00
commit 008b4811a0
3 changed files with 80 additions and 18 deletions

View file

@ -2,5 +2,7 @@
The game for the Mini Jame Gam #55 made in pygame The game for the Mini Jame Gam #55 made in pygame
sorry made this in 8 hours and procrastinated 4 of them because of personal issues
# Credits for external resources # Credits for external resources
FONT: https://github.com/IdreesInc/Monocraft FONT: https://github.com/IdreesInc/Monocraft

View file

@ -9,8 +9,8 @@ holding_milk = False
zombie_hp = 20 zombie_hp = 20
milkactive = False milkactive = False
enemy_zombies = [ enemy_zombies = [
{"x": 200, "y": 200, "hp": 20, "dead": False, "dx": 1, "dy": 1, "timer": 0}, {"x": 200, "y": 200, "hp": 20, "dead": False, "dx": 1, "dy": 1, "timer": 0, "coll": pygame.Rect(200, 200, 56, 96), "friendly": False},
{"x": 400, "y": 300, "hp": 20, "dead": False, "dx": -1, "dy": 1, "timer": 0}, {"x": 400, "y": 300, "hp": 20, "dead": False, "dx": -1, "dy": 1, "timer": 0, "coll": pygame.Rect(400, 300, 56, 96), "friendly": False},
] ]
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 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
@ -229,12 +229,26 @@ def level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont,
zombie_hp_box_green = pygame.surface.Surface((zombie_hp*3, 10), pygame.SRCALPHA) zombie_hp_box_green = pygame.surface.Surface((zombie_hp*3, 10), pygame.SRCALPHA)
zombie_hp_box_green.fill((0,255,0)) zombie_hp_box_green.fill((0,255,0))
screen.blit(zombie_hp_box_green, (zombie_x, zombie_y-20)) screen.blit(zombie_hp_box_green, (zombie_x, zombie_y-20))
if random.randint(tick-300, tick+300) == tick and not milkactive: if random.randint(tick-200, tick+200) == tick and not milkactive:
milk_pos_x, milk_pos_y = random.randint(0, screen_width), random.randint(0, screen_height) milk_pos_x, milk_pos_y = random.randint(0, screen_width), random.randint(0, screen_height)
milkactive = True milkactive = True
for ez in enemy_zombies: for ez in enemy_zombies:
if not ez["dead"]: if ez["dead"]:
screen.blit(load_sprite(sheet, 34, 82, 12, 12, 96, 96), (ez["x"], ez["y"])) # dead sprite
# milk revive check
if milkactive and not holding_milk and not click:
milk_rect = pygame.Rect(milk_pos_x - 20, milk_pos_y - 50, 49, 74)
dead_rect = pygame.Rect(ez["x"], ez["y"], 96, 96)
if milk_rect.colliderect(dead_rect):
ez["dead"] = False
ez["hp"] = 20
ez["friendly"] = True
milkactive = False
enemy_zombies.append(
{"x": random.randint(0, screen_width), "y": random.randint(0, screen_height), "hp": 20,
"dead": False, "coll": pygame.Rect(400, 300, 56, 96), "friendly": False, "dx": 1, "dy": 1, "timer": 0})
else:
ez["timer"] += 1 ez["timer"] += 1
if ez["timer"] > 60: if ez["timer"] > 60:
ez["dx"] = random.choice([-2, -1, 1, 2]) ez["dx"] = random.choice([-2, -1, 1, 2])
@ -246,18 +260,39 @@ def level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont,
ez["y"] = max(0, min(ez["y"], screen_height - 96)) ez["y"] = max(0, min(ez["y"], screen_height - 96))
if ez["hp"] <= 0: if ez["hp"] <= 0:
ez["dead"] = True ez["dead"] = True
screen.blit(load_sprite(sheet, 46, 82, 7, 12, 56, 96), (ez["x"], ez["y"])) # enemy zombie if ez["friendly"]:
zombie1 screen.blit(load_sprite(sheet, 27, 82, 7, 12, 56, 96), (ez["x"], ez["y"])) # your zombie sprite
else: else:
screen.blit(load_sprite(sheet, 34, 82, 12, 12, 96, 96), (ez["x"], ez["y"])) # dead sprite screen.blit(load_sprite(sheet, 46, 82, 7, 12, 56, 96), (ez["x"], ez["y"])) # enemy sprite
# milk revive check ez["coll"] = pygame.Rect(ez["x"], ez["y"], 56, 96)
if milkactive and not holding_milk and not click: hp_red = pygame.Surface((60, 10), pygame.SRCALPHA)
milk_rect = pygame.Rect(milk_pos_x - 20, milk_pos_y - 50, 49, 74) hp_red.fill((255, 0, 0))
dead_rect = pygame.Rect(ez["x"], ez["y"], 96, 96) screen.blit(hp_red, (ez["x"], ez["y"] - 20))
if milk_rect.colliderect(dead_rect): if ez["hp"] > 0:
ez["dead"] = False hp_green = pygame.Surface((ez["hp"] * 3, 10), pygame.SRCALPHA)
ez["hp"] = 20 hp_green.fill((0, 255, 0))
milkactive = False screen.blit(hp_green, (ez["x"], ez["y"] - 20))
if ez["coll"].collidepoint(mouse.get_pos()) and random.randint(0,10) == 5 and click and not ez["friendly"]:
ez["hp"] -= 1
if len([ez for ez in enemy_zombies if not ez["dead"] and not ez["friendly"]]) < 2:
enemy_zombies.append(
{"x": random.randint(0, screen_width), "y": random.randint(0, screen_height), "hp": 20, "dead": False,
"coll": pygame.Rect(0, 0, 56, 96), "friendly": False, "dx": 1, "dy": 1, "timer": 0})
for i, a in enumerate(enemy_zombies):
if a["dead"]:
continue
for j, b in enumerate(enemy_zombies):
if b["dead"] or i == j or a["friendly"] == b["friendly"]:
continue
dist_x = b["x"] - a["x"]
dist_y = b["y"] - a["y"]
dist = (dist_x ** 2 + dist_y ** 2) ** 0.5
if dist < 200 and dist != 0:
a["x"] += int(dist_x / dist * 2)
a["y"] += int(dist_y / dist * 2)
if dist < 60 and random.randint(0, 10) == 0:
b["hp"] -= 1
break
screen.blit(load_sprite(sheet, 27, 82, 7, 12, 56, 96), (zombie_x, zombie_y)) # ZOMBIE screen.blit(load_sprite(sheet, 27, 82, 7, 12, 56, 96), (zombie_x, zombie_y)) # ZOMBIE
@ -273,4 +308,25 @@ def level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont,
milk_pos_x, milk_pos_y = msx, msy milk_pos_x, milk_pos_y = msx, msy
screen.blit(load_sprite(sheet, 20, 82, 7, 12, 49, 74), (milk_pos_x - 20, milk_pos_y - 50)) # MILK CARTON screen.blit(load_sprite(sheet, 20, 82, 7, 12, 49, 74), (milk_pos_x - 20, milk_pos_y - 50)) # MILK CARTON
if len(enemy_zombies) > 100:
level = 6
return level
def level6(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, smalltext): # function for level 6
thanks = smalltext.render("thank you for playing my game", True, (255, 255, 255))
thanks2 = smalltext.render("due to personal issues, I couldnt work on", True, (255, 255, 255))
thanks3 = smalltext.render("it the first 2 days, so I only made this in", True, (255, 255, 255))
thanks4 = smalltext.render("like 6 hours so im sorry if its a little", True, (255, 255, 255))
thanks5 = smalltext.render(" short and underwhelming,", True, (255, 255, 255))
thanks6 = smalltext.render("game fully opensource at:", True, (255, 255, 255))
thanks7 = smalltext.render("https://git.dvorakmortonxd.dev/", True, (255, 255, 255))
thanks8 = smalltext.render("dvorakmortonxd/revival-inc", True, (255,255,255))
screen.blit(thanks, (15,15))
screen.blit(thanks2, (15,40))
screen.blit(thanks3, (15,65))
screen.blit(thanks4, (15,90))
screen.blit(thanks5, (15,115))
screen.blit(thanks6, (15,140))
screen.blit(thanks7, (15,200))
screen.blit(thanks8, (15,225))
return level return level

View file

@ -30,7 +30,7 @@ def main(fps=window_fps): # the main function
if event.key == pygame.K_ESCAPE: # what happens when you press escape if event.key == pygame.K_ESCAPE: # what happens when you press escape
running = False # poof running = False # poof
if event.key == pygame.K_k: if event.key == pygame.K_k:
level = 4.5 level = 6
if event.type == pygame.MOUSEBUTTONDOWN: # what happens when you press down a mouse button if event.type == pygame.MOUSEBUTTONDOWN: # what happens when you press down a mouse button
click = True # sets the click variable to True so level function in levels.py can see click = True # sets the click variable to True so level function in levels.py can see
print(pygame.mouse.get_pos()) # prints out where the mouse is during the click for debugging purposes print(pygame.mouse.get_pos()) # prints out where the mouse is during the click for debugging purposes
@ -61,8 +61,12 @@ def main(fps=window_fps): # the main function
elif level == 5: elif level == 5:
tick += 1 tick += 1
level = levels.level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigtext, level, tick, smalltext) # runs the level5 function from levels.py level = levels.level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigtext, level, tick, smalltext) # runs the level5 function from levels.py
elif level == 6:
tick += 1
level = levels.level6(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, pygame.mouse, click, bigtext, level, tick, smalltext) # runs the level5 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 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 if level != 6:
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 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 clock.tick(fps) # this makes sure the game loop runs at the fps we set it to before
pygame.quit() #this quits our game when the game loop somehow ends, for example by pressing escape or the X button on the window pygame.quit() #this quits our game when the game loop somehow ends, for example by pressing escape or the X button on the window