def rabbit_collide_with_hole(self, space, arbiter): gameworld = self.gameworld entities = gameworld.entities rabbit_id = arbiter.shapes[0].body.data hole_id = arbiter.shapes[1].body.data rabbit_entity = entities[rabbit_id] hole_entity = entities[hole_id] rabbit_position = rabbit_entity['cymunk-physics']['position'] hole_position = hole_entity['cymunk-physics']['position'] Clock.schedule_once(partial(gameworld.timed_remove_entity, rabbit_id)) if rabbit_id == self.targeted: self.targeted = None if self.rabbit == rabbit_id: self.rabbit = None time_offset = 10. gameworld.gamescreenmanager.main_screen.add_timer() Clock.schedule_once( gameworld.systems['levels_system'].clear_level, time_offset) elif rabbit_id in self.white_rabbits: self.white_rabbits.remove(rabbit_id) if self.rabbit == None and self.white_rabbits == []: sound_system = gameworld.systems['sound_system'] Clock.schedule_once( partial(sound_system.schedule_play, 'rabbit_victory')) return False
def collide_rabbit_with_hawk(self, space, arbiter): rabbit_id = arbiter.shapes[0].body.data if rabbit_id == self.targeted: sound_system = self.gameworld.systems['sound_system'] Clock.schedule_once( partial(self.gameworld.timed_remove_entity, self.targeted)) Clock.schedule_once( partial(sound_system.schedule_play, 'rabbit_on_ice')) self.dead_rabbits = True if self.rabbit == self.targeted: self.rabbit = None self.gameworld.parent.set_game_over() elif self.targeted in self.white_rabbits: self.white_rabbits.remove(self.targeted) self.targeted = None return False
def call_rabbit(self, rabbit_id): sound_system = self.gameworld.systems['sound_system'] Clock.schedule_once(partial(sound_system.schedule_play, 'rabbit')) rabbit = self.gameworld.entities[rabbit_id] black_rabbit = self.gameworld.entities[self.rabbit] black_rabbit_position = black_rabbit['cymunk-physics']['position'] white_rabbit_position = rabbit['cymunk-physics']['position'] XDistance = (white_rabbit_position[0]) - (black_rabbit_position[0]) YDistance = (white_rabbit_position[1]) - (black_rabbit_position[1]) self.apply_rabbit_force(rabbit, XDistance, YDistance)
def _on_enter(self): self.validate_cursor_pos() text = self.text[self._cursor_pos:] if text.strip() == '': self.prompt() return Clock.schedule_once(partial(self._run_cmd, text)) self.cmd_history.append(text) self.text = '' self.prompt()
def on_touch_down(self, touch): camera_pos = self.gameworld.systems['default_gameview'].camera_pos touch.x -= camera_pos[0] touch.y -= camera_pos[1] if self.gameworld.state == 'main' or 'main_editor': called_rabbit = self.touch_rabbit(touch) if not called_rabbit is None: if called_rabbit == self.rabbit: self.stop_rabbit(self.gameworld.entities[called_rabbit]) elif self.rabbit is not None: self.call_rabbit(called_rabbit) sound_system = self.gameworld.systems['sound_system'] Clock.schedule_once(partial(sound_system.schedule_play, 'white_rabbits'), .5) elif self.rabbit is not None: rabbit = self.gameworld.entities[self.rabbit] rabbit_position = rabbit['cymunk-physics']['position'] XDistance = (rabbit_position[0]) - touch.x YDistance = (rabbit_position[1]) - touch.y self.apply_rabbit_force(rabbit, XDistance, YDistance)
def update(self, dt): for entity_id in self.entity_ids: entities = self.gameworld.entities rabbit_entity = entities[entity_id] if (rabbit_entity['rabbit_system']['is_safe'] and rabbit_entity['rabbit_system']['visibility'] > 0): self.change_visibility(entity_id, -1) elif rabbit_entity['rabbit_system']['visibility'] <= 1000: self.change_visibility(entity_id, 2) if (rabbit_entity['rabbit_system']['visibility'] > 1000 and self.targeted is None): self.targeted = rabbit_entity['id'] sound_system = self.gameworld.systems['sound_system'] Clock.schedule_once( partial(sound_system.schedule_play, 'hawkcry')) if self.targeted is not None: if 'rabbit_system' in entities[self.targeted]: if entities[self.targeted][ 'rabbit_system']['visibility'] < 800: self.targeted = None self.update_visibility_widget(rabbit_entity)
def clear_rabbits(self): self.targeted = None self.white_rabbits = [] for entity_id in self.entity_ids: Clock.schedule_once( partial(self.gameworld.timed_remove_entity, entity_id))
def add_text(self, text, on_newline, *args): Clock.schedule_once( partial(self.text_display_label.add_text, text, on_newline))