diff --git a/virtupet/Pudgi.py b/virtupet/Pudgi.py index 18aeef2..79cc785 100644 --- a/virtupet/Pudgi.py +++ b/virtupet/Pudgi.py @@ -45,20 +45,20 @@ def __init__(self, parents=None, load_file=None): self.handler.load_file(constants.DEFAULT_PUDGI) self.json_object = self.handler.get_data() - self.happiness = self.json_object["happiness"] self.uid = hex(random.randint(0, 100000)) - self.handler.close() + self.handler.load_file("./data/names.json") + names = self.handler.get_data() + self.name = random.choice(names) - self.handler.load_file("./data/names.json") - names = self.handler.get_data() - self.name = random.choice(names) + self.handler.close() # ------- general data ------- self.known_decisions = [] self.known_decisions = self.json_object["known_decisions"] + # TODO move this so it only happens upon creation of new Pudgi. Load pudgi should grab json attributes self.splice_dna() # ------- animation variables ------- @@ -303,6 +303,7 @@ def export_to_json(self): self.json_object["personality"] = self.personality self.json_object["known_decisions"] = self.known_decisions self.json_object["parents"] = self.parents + self.json_object["dna"] = self.dna.get_strand() self.handler.save_as("./data/pudgies/" + self.uid + ".json", self.json_object) diff --git a/virtupet/clock.py b/virtupet/clock.py index 9b046ff..7af5ac5 100644 --- a/virtupet/clock.py +++ b/virtupet/clock.py @@ -1,6 +1,7 @@ # this file will have the functions to deal with the accumulation of time data and the printing of a timestamp import time +import datetime class Clock: @@ -15,10 +16,20 @@ def elapsed_time(self): def time_stamp(self): stamp = "" - hours = "%02d" % ((int((self.elapsed_time()))/60),) - minutes = "%02d" % (int((self.elapsed_time())),) - - return hours + ":" + minutes + # hours = "%02d" % ((int((self.elapsed_time()))/ 60),) + # minutes = "%02d" % (int((self.elapsed_time()))% 60,) + # hours = "%02d" % ((int((time.time())) / 60),) + # minutes = "%02d" % ((int((time.time())) % 60),) + time = datetime.datetime.now() + hours = "%02d" % (time.minute % 24,) + minutes = "%02d" % (time.second,) + + if int(hours) == 00: + return str(12) + ":" + minutes + "am" + elif int(hours) == 13: + return str(12) + ":" + minutes + "pm" + else: + return str(int(hours) % 12) + ":" + minutes + "pm" def update_time(self): self.cur_time = int(self.elapsed_time()) diff --git a/virtupet/data/pudgies/0x8653.json b/virtupet/data/pudgies/0x8653.json new file mode 100644 index 0000000..054ce93 --- /dev/null +++ b/virtupet/data/pudgies/0x8653.json @@ -0,0 +1,148 @@ +{ + "uid": "0x8653", + "name": "Madalynn", + "dna": [ + 0, + 1, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 0, + 1, + 1, + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + 1, + 1, + 0, + 1, + 0, + 1, + 0, + 0, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 0, + 1, + 0, + 0, + 1, + 1, + 1, + 0, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 1, + 0, + 1, + 1, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 1, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 1, + 1, + 1, + 0, + 1, + 0, + 1, + 0, + 0, + 0, + 1, + 1 + ], + "color": "Purple", + "personality": "ISTP", + "parents": [ + null, + null + ], + "happiness": 0.5, + "known_decisions": [] +} \ No newline at end of file diff --git a/virtupet/main.py b/virtupet/main.py index 27a9c0e..3a16da8 100644 --- a/virtupet/main.py +++ b/virtupet/main.py @@ -5,30 +5,29 @@ import pygame import constants import environments -from file_handler import JSONHandler from clock import Clock from pudgi import Pudgi def main(): - handler = JSONHandler() - handler.load_file(constants.DEFAULT_PUDGI) - json_object = handler.get_data() - time_clock = Clock() # ----------- pygame objects ----------- pygame.init() + pygame.font.init() + + font = pygame.font.SysFont('Comic Sans MS', 30) + size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT] screen = pygame.display.set_mode(size) - pygame.display.set_caption(json_object["name"]) + pygame.display.set_caption("Pudgi Simulation") parents = ["0x9c08", "0x11e66"] # agent = Pudgi(parents) - # agent = Pudgi(None, "./data/pudgies/0x9c08.json") - agent = Pudgi() + agent = Pudgi(None, "./data/pudgies/0x8653.json") + # agent = Pudgi() env_list = [environments.EnvironmentHouse(agent)] current_env_no = 0 @@ -56,10 +55,6 @@ def main(): # --------------Main While loop--------------- while not done: - if time_clock.elapsed_time() > time_clock.cur_time: - time_clock.update_time() - print(time_clock.time_stamp()) - for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop @@ -85,9 +80,17 @@ def main(): current_env.draw(screen) active_sprite_list.draw(screen) - clock.tick(30) + 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.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) - # print(clock.get_fps()) + clock.tick(30) pygame.display.flip()