def __init__(self, experiment): self.logger = FileLogger() self.screen = pygame.display.get_surface() self.clock = pygame.time.Clock() self.experiment = experiment # self.level = Level() self.event_handler = EventHandler() self.keyboard_handler = Event() self.sprites_group = pygame.sprite.LayeredDirty() self.msgs = {} self.msgs["welcome"] = ImageMessage(str(0), "welcome.jpg") self.msgs["the_end"] = ImageMessage(str(0), "theEnd.jpg") for v in self.msgs.itervalues(): self.sprites_group.add(v, layer=MSG_lyr) self.trial = Trial(self.logger) self.block = Block(self.trial, self.msgs) self.exp_runner = ExpRunner(self.experiment, self.block, self.msgs, self.set_images)
def __init__(self, experiment): self.logger = FileLogger() self.screen = pygame.display.get_surface() self.clock = pygame.time.Clock() self.experiment = experiment self.event_handler = EventHandler() self.keyboard_handler = Event() self.sprites_group = pygame.sprite.LayeredDirty() self.background = {} self.background["pasive"] = pygame.sprite.DirtySprite() # self.background["pasive"].image = pygame.surface.Surface(Properties.SCREEN_RES) self.background["pasive"].image = pygame.surface.Surface( self.screen.get_size()) self.background["pasive"].image.fill([40, 40, 40]) self.background["pasive"].rect = self.background[ "pasive"].image.get_rect() self.sprites_group.add(self.background["pasive"], layer=BACKGR_lyr) # self.background["active"] = pygame.sprite.DirtySprite() # self.background["active"].image = pygame.surface.Surface(Properties.SCREEN_RES) # # self.background["active"].image = pygame.surface.Surface(self.screen.get_size()) # self.background["active"].image.fill([80,80,80]) # self.background["active"].rect = self.background["active"].image.get_rect() # self.sprites_group.add(self.background["active"], layer=BACKGR_lyr) # self.background["active"].visible = False self.feedback_ok = Feedback() self.feedback_no = Feedback(False) self.sprites_group.add(self.feedback_ok, layer=FEED_lyr) self.sprites_group.add(self.feedback_no, layer=FEED_lyr) self.msgs = {} self.boxes = {} self.instruction = Instruction() self.instruction.hide() self.sprites_group.add(self.instruction, layer=INST_lyr) self.msgs["done"] = ImageDone() for v in self.msgs.itervalues(): self.sprites_group.add(v, layer=BTN_lyr) for box_name, position in self.experiment["box_positions"].iteritems(): box = Box(box_name, json.loads(position), self.experiment["properties"]) self.sprites_group.add(box, layer=BOXES_lyr) self.boxes[box_name] = box self.tic_group = [] self.trial = Trial( self.logger, self.experiment["properties"], self.change_to_active_mode, None, { "ok": self.feedback_ok.show, "no": self.feedback_no.show, "off": (lambda: [self.feedback_ok.hide(), self.feedback_no.hide()]) }) self.exp_runner = ExpRunner(self.experiment, self.trial, self.boxes) self.exp_runner.end_test = self.terminar_juego self.exp_runner.instruction = self.instruction self.trial.handle_end = self.exp_runner.next_trial self.trial.set_boxes(self.boxes, self.suscribe_box_on, self.unsuscribe_box) self.boxes_on = [] self.msgs["done"].set_callback(self.trial.next_by_usr) self.change_to_active_mode(False)
def __init__(self, experiment_data): self.logger = FileLogger(SUBJECT_NAME) self.experiment_data = experiment_data SCREEN_RES = (int(experiment_data["screen_res"]["x"]), int(experiment_data["screen_res"]["y"])) self.screen = pygame.display.get_surface() self.clock = pygame.time.Clock() self.event_handler = EventHandler.EventHandler() self.keyboard_handler = Event.Event() self.sprites_group = pygame.sprite.LayeredDirty() # self.background = pygame.sprite.DirtySprite() self.background = ImageMessage("background.png", BACKGROUND_PROFILE) self.background.scale(SCREEN_RES[0], SCREEN_RES[1]) self.background.show() self.sprites_group.add(self.background, layer=BACKGR_lyr) self.msgs = {} self.msgs["welcome"] = ImageMessage("welcome.png", BACKGROUND_PROFILE) self.msgs["the_end"] = ImageMessage("theEnd.png", BACKGROUND_PROFILE) # self.msgs["background"] = ImageMessage("background.png") self.msgs["op"] = ImageMessage("operator.png", BACKGROUND_PROFILE) self.msgs["feed"] = ImageMessage("feedback.png", BACKGROUND_PROFILE) self.msgs["subj"] = ImageMessage("subject.png", BACKGROUND_PROFILE) self.msgs["end_block"] = ImageMessage("endBlock.png", BACKGROUND_PROFILE) for v in self.msgs.itervalues(): v.scale(SCREEN_RES[0], SCREEN_RES[1]) self.sprites_group.add(v, layer=MSG_lyr) self.feedback_ok = Feedback() self.feedback_no = Feedback(False) self.sprites_group.add(self.feedback_ok, layer=FEED_lyr) self.sprites_group.add(self.feedback_no, layer=FEED_lyr) # self.state = State.State() # st = self.state # self.trial = Trial(self.logger, self.show_messages, # None, # {"ok": self.feedback_ok.show, "no": self.feedback_no.show, # "off": (lambda: [self.feedback_ok.hide(), self.feedback_no.hide()])}, # self) # self.add_elements(experiment_data["trials"]["2"][1], 0) # self.add_elements(experiment_data["trials"]["2"][2], 2) self.btns = {} self.btns["left"] = ImageButton(0) self.btns["right"] = ImageButton(1) for v in self.btns.itervalues(): self.sprites_group.add(v, layer=ANSW_BTN_lyr) # self.btns["left"].set_callback(lambda: self.exp_runner.check_answer([ # c for i in xrange(len(self.palettes)) for c in self.palettes[i].get_selected() ])) self.trial = Trial(self.logger, self.change_to_active_mode) self.trial.feedback[1] = self.feedback_ok self.trial.feedback[0] = self.feedback_no self.block = Block(self.trial, self.msgs) # self.exp_runner = ExpRunner(self.experiment_data, self.add_elements, self.add_screenshot) self.exp_runner = ExpRunner(self.experiment_data, self.block, self.msgs, self.set_images) self.exp_runner.end_test = self.end_game self.btns["left"].set_callback(self.trial.usr_answer) self.btns["right"].set_callback(self.trial.usr_answer) # self.exp_runner.instruction = self.instruction # self.exp_runner.next() self.change_to_active_mode(False) # self.msgs["welcome"].show() self.clicked_sprite = None
def __init__(self, experiment): self.logger = FileLogger() self.experiment = experiment self.mode = EXPERIMENT_MODE SCREEN_RES = (int(experiment["screen_res"]["x"]), int(experiment["screen_res"]["y"])) self.properties = Properties.Properties(SCREEN_RES) self.screen = pygame.display.get_surface() self.clock = pygame.time.Clock() self.event_handler = EventHandler.EventHandler() self.keyboard_handler = Event.Event() self.sprites_group = pygame.sprite.LayeredDirty() # self.background = pygame.sprite.DirtySprite() self.background = ImageMessage("scale_fondo{}.png".format(BACKGROUND_PROFILE)) self.background.scale(SCREEN_RES[0], SCREEN_RES[1]) self.background.show() # self.background.image = pygame.surface.Surface(Properties.SCREEN_RES) # self.background.image.fill([240,240,240]) # self.background.rect = self.background.image.get_rect() self.sprites_group.add(self.background, layer=BACKGR_lyr) self.floor = pygame.sprite.DirtySprite() self.floor.image = pygame.surface.Surface((self.properties.SCREEN_RES[0], self.properties.floor_height)) self.floor.image.fill([0,200,0]) self.floor.rect = self.floor.image.get_rect() self.floor.rect.bottom = self.properties.SCREEN_RES[1] self.sprites_group.add(self.floor, layer=FLOOR_lyr) self.feedback_ok = Feedback() self.feedback_no = Feedback(False) self.sprites_group.add(self.feedback_ok, layer=FEED_lyr) self.sprites_group.add(self.feedback_no, layer=FEED_lyr) self.state = State.State() st = self.state self.trial = Trial(self.logger, self.show_messages, None, {"ok": self.feedback_ok.show, "no": self.feedback_no.show, "off": (lambda: [self.feedback_ok.hide(), self.feedback_no.hide()])}, self) self.sprites_group.add(StickSprite(st.sticks[1], self.properties), layer=STICK_lyr) self.sprites_group.add(StickSprite(st.sticks[2], self.properties), layer=STICK_lyr) self.sprites_group.add(StickSprite(st.sticks[3], self.properties), layer=STICK_lyr) self.sprites_group.add(DiskSprite(st.get_disk(State.B),st.get_disk_position(State.B), mode=DISKS_PROFILE, prop=self.properties), layer=DISKS_lyr) self.sprites_group.add(DiskSprite(st.get_disk(State.G),st.get_disk_position(State.G), mode=DISKS_PROFILE, prop=self.properties), layer=DISKS_lyr) self.sprites_group.add(DiskSprite(st.get_disk(State.R),st.get_disk_position(State.R), mode=DISKS_PROFILE, prop=self.properties), layer=DISKS_lyr) self.goal = Goal(DISKS_PROFILE, prop=self.properties) self.sprites_group.add(self.goal, layer=GOAL_lyr) self.instruction = Instruction(prop=self.properties) self.instruction.hide() self.sprites_group.add(self.instruction, layer=INST_lyr) self.msgs = {} self.msgs["done"] = ImageDone(prop=self.properties) self.msgs["done"].set_callback(self.trial.check_answer) for v in self.msgs.itervalues(): self.sprites_group.add(v, layer=CTRL_BTN_lyr) self.exp_runner = ExpRunner(self.experiment, self.trial) self.exp_runner.end_test = self.end_game self.exp_runner.instruction = self.instruction self.exp_runner.next() self.clicked_sprite = None if self.mode == FREE_MODE: for i in range(1,8+1): self.sprites_group.add(TextLevel(i,self.set_board_distance), layer=LEVEL_SEL_lyr) self.show_messages(False)