generated from dvorakmortonxd/pygame-template
332 lines
No EOL
17 KiB
Python
332 lines
No EOL
17 KiB
Python
import pygame, random
|
|
from render import load_sprite # this makes it so our function for rendering sprites from sprites.png is available in here
|
|
|
|
milk_pos_x, milk_pos_y = 274, 342
|
|
zombie_dx, zombie_dy = 1, 1
|
|
zombie_x, zombie_y = 645, 214
|
|
zombie_timer = 0
|
|
holding_milk = False
|
|
zombie_hp = 20
|
|
milkactive = False
|
|
enemy_zombies = [
|
|
{"x": 200, "y": 200, "hp": 20, "dead": False, "dx": 1, "dy": 1, "timer": 0, "coll": None, "friendly": False},
|
|
{"x": 400, "y": 300, "hp": 20, "dead": False, "dx": -1, "dy": 1, "timer": 0, "coll": None, "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
|
|
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, 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
|
|
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 2201 <= tick <= 2500:
|
|
if tick < 2326:
|
|
dialog = smalltext.render("try dragging the milk to him", True, (0+(tick-2201)*2, 0+(tick-2201)*2, 0+(tick-2201)*2))
|
|
else:
|
|
dialog = smalltext.render("try dragging the milk to him", 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 >= 2501:
|
|
level = 2.5
|
|
return level # returns the current level set
|
|
def level3(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, smalltext): # function for level 3
|
|
global milk_pos_x, milk_pos_y, holding_milk
|
|
milk_collision = pygame.Rect(milk_pos_x-20, milk_pos_y-50, 49, 74)
|
|
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
|
|
zombie_collision = pygame.Rect(645,214,96,96)
|
|
msx, msy = pygame.mouse.get_pos()
|
|
if milk_collision.collidepoint(mouse.get_pos()):
|
|
if click:
|
|
holding_milk = True
|
|
if not click:
|
|
holding_milk = False
|
|
if holding_milk:
|
|
milk_pos_x, milk_pos_y = msx, msy
|
|
if zombie_collision.collidepoint(milk_pos_x, milk_pos_y):
|
|
level = 4
|
|
screen.blit(load_sprite(sheet, 20, 82, 7, 12, 49, 74), (milk_pos_x-20, milk_pos_y-50)) # MILK CARTON
|
|
dialog_square = pygame.surface.Surface((700, 68), pygame.SRCALPHA)
|
|
dialog_square.fill((0, 0, 0))
|
|
return level
|
|
def level4(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, smalltext): # function for level 4
|
|
global zombie_x, zombie_y, zombie_timer, zombie_dx, zombie_dy
|
|
screen.blit(load_sprite(sheet, 0, 46, 48, 36, screen_width, screen_height), (0, 0))
|
|
zombie_timer += 1
|
|
if zombie_timer > 60: # change direction every ~1 sec
|
|
zombie_dx = random.choice([-2, -1, 1, 2])
|
|
zombie_dy = random.choice([-2, -1, 1, 2])
|
|
zombie_timer = 0
|
|
zombie_x += zombie_dx
|
|
zombie_y += zombie_dy
|
|
zombie_x = max(0, min(zombie_x, screen_width - 96))
|
|
zombie_y = max(0, min(zombie_y, screen_height - 96))
|
|
screen.blit(load_sprite(sheet, 27, 82, 7, 12, 56, 96), (zombie_x, zombie_y)) # ZOMBIE
|
|
dialog_square = pygame.surface.Surface((700, 68), pygame.SRCALPHA)
|
|
dialog_square.fill((0, 0, 0))
|
|
|
|
# dialogs here
|
|
|
|
if 60 <= tick <= 270:
|
|
if tick < 186:
|
|
dialog = basicfont.render("see????", True, (0+tick*2-120, 0+tick*2-120, 0+tick*2-120))
|
|
else:
|
|
dialog = basicfont.render("see????", 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 271 <= tick <= 500:
|
|
if tick < 390:
|
|
dialog = smalltext.render("the milk brought him back!", True, (0+(tick-271)*2, 0+(tick-271)*2, 0+(tick-271)*2))
|
|
else:
|
|
dialog = smalltext.render("the milk brought him back!", 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 501 <= tick <= 750:
|
|
if tick < 626:
|
|
dialog = smalltext.render("I mean sure hes a little dumb", True, (0+(tick-501)*2, 0+(tick-501)*2, 0+(tick-501)*2))
|
|
else:
|
|
dialog = smalltext.render("I mean sure hes a little dumb", 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("but hes ressurected!!!", True, (0+(tick-751)*2, 0+(tick-751)*2, 0+(tick-751)*2))
|
|
else:
|
|
dialog = smalltext.render("but hes ressurected!!!", 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 <= 1250:
|
|
if tick < 1126:
|
|
dialog = smalltext.render("now you know the basics", True, (0+(tick-1001)*2, 0+(tick-1001)*2, 0+(tick-1001)*2))
|
|
else:
|
|
dialog = smalltext.render("now you know the basics", 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 1251 <= tick <= 1500:
|
|
if tick < 1376:
|
|
dialog = smalltext.render("so go on!", True, (0+(tick-1251)*2, 0+(tick-1251)*2, 0+(tick-1251)*2))
|
|
else:
|
|
dialog = smalltext.render("so go on!", 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 > 1500:
|
|
level = 4.5
|
|
return level
|
|
def level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont, mouse, click, big_text, level, tick, smalltext): # function for level 5
|
|
global zombie_x, zombie_y, zombie_timer, zombie_dx, zombie_dy, zombie_hp, milkactive, milk_pos_x, milk_pos_y, holding_milk
|
|
screen.blit(load_sprite(sheet, 49, 46, 48, 36, screen_width, screen_height), (0, 0))
|
|
zombie_timer += 1
|
|
if zombie_timer > 60: # change direction every ~1 sec
|
|
zombie_dx = random.choice([-2, -1, 1, 2])
|
|
zombie_dy = random.choice([-2, -1, 1, 2])
|
|
zombie_timer = 0
|
|
zombie_x += zombie_dx
|
|
zombie_y += zombie_dy
|
|
zombie_x = max(0, min(zombie_x, screen_width - 96))
|
|
zombie_y = max(0, min(zombie_y, screen_height - 96))
|
|
if tick <= 200:
|
|
dialog = smalltext.render("click enemies to damage them", True, (255, 255, 255))
|
|
screen.blit(dialog, (50, 50))
|
|
elif 800 >= tick >= 200:
|
|
dialog = smalltext.render("drag milk to dead enemies to", True, (255, 255, 255))
|
|
dialog2 = smalltext.render("make them your own minions", True, (255, 255, 255))
|
|
screen.blit(dialog, (50, 50))
|
|
screen.blit(dialog2, (50, 75))
|
|
zombie_hp_box_red = pygame.surface.Surface((60, 10), pygame.SRCALPHA)
|
|
zombie_hp_box_red.fill((255,0,0))
|
|
screen.blit(zombie_hp_box_red, (zombie_x, zombie_y-20))
|
|
if zombie_hp > 0: # AVOIDING ERRORS AT ALL COSTS
|
|
zombie_hp_box_green = pygame.surface.Surface((zombie_hp*3, 10), pygame.SRCALPHA)
|
|
zombie_hp_box_green.fill((0,255,0))
|
|
screen.blit(zombie_hp_box_green, (zombie_x, zombie_y-20))
|
|
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)
|
|
milkactive = True
|
|
|
|
for ez in enemy_zombies:
|
|
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
|
|
if ez["timer"] > 60:
|
|
ez["dx"] = random.choice([-2, -1, 1, 2])
|
|
ez["dy"] = random.choice([-2, -1, 1, 2])
|
|
ez["timer"] = 0
|
|
ez["x"] += ez["dx"]
|
|
ez["y"] += ez["dy"]
|
|
ez["x"] = max(0, min(ez["x"], screen_width - 96))
|
|
ez["y"] = max(0, min(ez["y"], screen_height - 96))
|
|
if ez["hp"] <= 0:
|
|
ez["dead"] = True
|
|
if ez["friendly"]:
|
|
screen.blit(load_sprite(sheet, 27, 82, 7, 12, 56, 96), (ez["x"], ez["y"])) # your zombie sprite
|
|
else:
|
|
screen.blit(load_sprite(sheet, 46, 82, 7, 12, 56, 96), (ez["x"], ez["y"])) # enemy sprite
|
|
ez["coll"] = pygame.Rect(ez["x"], ez["y"], 56, 96)
|
|
hp_red = pygame.Surface((60, 10), pygame.SRCALPHA)
|
|
hp_red.fill((255, 0, 0))
|
|
screen.blit(hp_red, (ez["x"], ez["y"] - 20))
|
|
if ez["hp"] > 0:
|
|
hp_green = pygame.Surface((ez["hp"] * 3, 10), pygame.SRCALPHA)
|
|
hp_green.fill((0, 255, 0))
|
|
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
|
|
|
|
if milkactive:
|
|
milk_collision = pygame.Rect(milk_pos_x - 20, milk_pos_y - 50, 49, 74)
|
|
msx, msy = pygame.mouse.get_pos()
|
|
if milk_collision.collidepoint(mouse.get_pos()):
|
|
if click:
|
|
holding_milk = True
|
|
if not click:
|
|
holding_milk = False
|
|
if holding_milk:
|
|
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
|
|
|
|
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 |