generated from dvorakmortonxd/pygame-template
finished
This commit is contained in:
parent
eb506f7a16
commit
008b4811a0
3 changed files with 80 additions and 18 deletions
88
levels.py
88
levels.py
|
|
@ -9,8 +9,8 @@ holding_milk = False
|
|||
zombie_hp = 20
|
||||
milkactive = False
|
||||
enemy_zombies = [
|
||||
{"x": 200, "y": 200, "hp": 20, "dead": False, "dx": 1, "dy": 1, "timer": 0},
|
||||
{"x": 400, "y": 300, "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, "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
|
||||
|
|
@ -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.fill((0,255,0))
|
||||
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)
|
||||
milkactive = True
|
||||
|
||||
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
|
||||
if ez["timer"] > 60:
|
||||
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))
|
||||
if ez["hp"] <= 0:
|
||||
ez["dead"] = True
|
||||
screen.blit(load_sprite(sheet, 46, 82, 7, 12, 56, 96), (ez["x"], ez["y"])) # enemy zombie
|
||||
zombie1
|
||||
else:
|
||||
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
|
||||
milkactive = False
|
||||
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
|
||||
|
||||
|
|
@ -273,4 +308,25 @@ def level5(screen, sheet, screen_width, screen_height, lastclickpos, basicfont,
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue