Skip to content

Commit

Permalink
Pudgies die of old age and childbirth, deathtoll recorded in HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
ngraham20 committed May 8, 2018
1 parent df5de45 commit e37abe1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion virtupet/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion virtupet/.idea/virtupet.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 22 additions & 11 deletions virtupet/Pudgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ def __init__(self, parents=None, load_file=None):
if parents is not None:
alpha = parents[0]
beta = parents[1]
self.dna = Pudgi.generate_dna_from(alpha, beta)

handler = JSONHandler()
handler.load_file("./data/pudgies/" + alpha + ".json")
alpha_json = handler.get_data()
handler.load_file("./data/pudgies/" + beta + ".json")
beta_json = handler.get_data()

self.dna = Pudgi.generate_dna_from(alpha_json, beta_json)
Pudgi.mutate_dna_strand(self.dna.get_strand())
self.parents = parents
self.parents = [alpha_json["name"], beta_json["name"]]
else:
self.dna = DNA()
self.dna.gen_rand()
Expand All @@ -59,8 +66,9 @@ def __init__(self, parents=None, load_file=None):
self.handler.close()

# ------- general data -------
self.known_decisions = []
self.known_decisions = self.json_object["known_decisions"]
self.age = self.json_object["age"]
self.lifespan = random.randint(540, 660) # approximately 10 minute irl lifespan

# TODO move this so it only happens upon creation of new Pudgi. Load pudgi should grab json attributes
self.splice_dna()
Expand Down Expand Up @@ -90,14 +98,17 @@ def __init__(self, parents=None, load_file=None):

@staticmethod
def generate_dna_from(alpha, beta):
handler = JSONHandler()
handler.load_file("./data/pudgies/" + alpha + ".json")
alpha_json = handler.get_data()
handler.load_file("./data/pudgies/" + beta + ".json")
beta_json = handler.get_data()

alpha_dna = DNA(alpha_json["dna"])
beta_dna = DNA(beta_json["dna"])
# handler = JSONHandler()
# handler.load_file("./data/pudgies/" + alpha + ".json")
# alpha_json = handler.get_data()
# handler.load_file("./data/pudgies/" + beta + ".json")
# beta_json = handler.get_data()
#
# alpha_dna = DNA(alpha_json["dna"])
# beta_dna = DNA(beta_json["dna"])

alpha_dna = DNA(alpha["dna"])
beta_dna = DNA(beta["dna"])

strand = DNA.combine_dna(alpha_dna, beta_dna)
return DNA(strand)
Expand Down
2 changes: 2 additions & 0 deletions virtupet/data/pudgies/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
1
],
"color": null,
"age": 0,
"lifespan": null,
"personality": null,
"parents": [null, null],
"happiness": 3.0,
Expand Down
29 changes: 20 additions & 9 deletions virtupet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ def main():
# agent.stop()

for pudgi in active_agent_list:
#if not pudgi.sleeping:
# if movement[pudgi.name]["time"] <= 0:
# movement[pudgi.name]["time"] = random.randint(30, 90)
# movement[pudgi.name]["direction"] = random.choice(["L", "R", ""])
#else: # pudgi is sleeping
# movement[pudgi.name]["direction"] = "S"

if pudgi.age >= pudgi.lifespan:
active_agent_list.remove(pudgi)
active_sprite_list.remove(pudgi)
death_count += 1

print("---------------------------------------------")
print("<<<---" + pudgi.name + " died of old age--->>>")
print("Death Count: " + str(death_count))
print("---------------------------------------------")
if pudgi.sleeping:
movement[pudgi.name]["direction"] = "S"
pudgi.direction = "S"
Expand All @@ -141,12 +143,18 @@ def main():
time_clock.update_time()
clockSurface = font.render(time_clock.time_stamp(), True, constants.BLACK, constants.WHITE)
clockRect = clockSurface.get_rect()
clockRect.centerx = screen.get_rect().centerx
clockRect.x = screen.get_rect().centerx - 120
clockRect.y = 2
clockBorder = pygame.draw.rect(screen, constants.BLACK, (clockRect.x - 2, clockRect.y - 2, clockRect.width + 4, clockRect.height + 4))
screen.blit(clockSurface, clockRect)

screen.blit(clockSurface, clockRect)
deathCountSurface = font.render("Deaths: " + str(death_count), True, constants.BLACK, constants.WHITE)
deathCountRect = deathCountSurface.get_rect()
deathCountRect.x = clockRect.x + 120
deathCountRect.y = 2
deathCountBorder = pygame.draw.rect(screen, constants.BLACK,
(deathCountRect.x - 2, deathCountRect.y - 2, deathCountRect.width + 4, deathCountRect.height + 4))
screen.blit(deathCountSurface, deathCountRect)

game_clock.tick(30)

Expand All @@ -156,7 +164,10 @@ def main():
active_agent_list.remove(pudgi)
active_sprite_list.remove(pudgi)
death_count += 1
print("---------------------------------------------")
print("<<<---" + pudgi.name + " died in childbirth--->>>")
print("Death Count: " + str(death_count))
print("---------------------------------------------")
if int(time_clock.get_minutes()) % 15 == 0:
pudgi.make_decision()

Expand Down

0 comments on commit e37abe1

Please sign in to comment.