def tick(self): if self.ok: return True max_secs = 2.0 gl = get_game_loop() now = gl.now() b = now >= self.start_time + max_secs if b: self.ok = True if self.ok: return True t = (now - self.start_time) / max_secs assert t >= 0.0 assert t <= 1.0 # t is [0..1] r = t * math.pi c = math.cos(r) dx2 = self.dx / 2.0 dy2 = self.dy / 2.0 cx = self.origcx + dx2 - c * dx2 cy = self.origcy + dy2 - c * dy2 self.view.recenter_view(cx, cy) return b
def remove_myself(self): """ Equivalent to killing the object. It, or its children, can no longer be used. Its actions are stopped immediately. """ # BUG also go through children if self._displaylist_number != -1: print "Deleting display list", self._displaylist_number glDeleteLists(self._displaylist_number, 1) self._displaylist_number = -1 if self._layer: self._layer.remove_object(self) if self.parent: self.parent.remove_child(self) if len(self._keyboard_shortcuts) != 0: g = gameloop.get_game_loop() km = g.get_keyboardmanager() # Need a copy here for k, func in list(self._keyboard_shortcuts): km.remove_keyboard_shortcut(self, k, func) assert len(self._keyboard_shortcuts) == 0 self.remove_all_actions()
def add_action(self, action, wait_for = None): """ Add @action and start it, unless @wait_for specifies some other action. """ assert action is not None gl = gameloop.get_game_loop() gl._actionmanager.add_action(self, action, wait_for)
def _setup_logic (self): self._timer = Timer () self._tasks = task.TaskGroup () self._game_loop = get_game_loop () self._event_loop = EventLoop ('screenshot', self._tf_window, self._game_loop, None) self._event_loop.signal_event.add (self.on_sfml_event) self._tasks.add (task.repeat (task.run (self._event_loop.loop_once)))
def _setup_logic(self): self._timer = Timer() self._tasks = task.TaskGroup() self._game_loop = get_game_loop() self._event_loop = EventLoop('screenshot', self._tf_window, self._game_loop, None) self._event_loop.signal_event.add(self.on_sfml_event) self._tasks.add(task.repeat(task.run(self._event_loop.loop_once)))
def focus_on(self, x, y): ncx, ncy = self.get_center_when_looking_at(x, y) cntr = self.view.view.GetCenter() self.origcx = cntr[0] self.origcy = cntr[1] self.destx = ncx self.desty = ncy self.dx = self.destx - self.origcx self.dy = self.desty - self.origcy self.start_time = get_game_loop().now() self.ok = False
def tick(self): w = self.view.content_width h = self.view.content_height hs = self.view.view.GetHalfSize() sw = hs[0] sh = hs[1] a = sw / 2.0 b = sh / 2.0 gl = get_game_loop() now = gl.now() dt = now - self.start_time t = dt * 0.1 cx = w / 2.0 + a * math.cos(t) - b * math.sin(t) cy = h / 2.0 + a * math.cos(t) + b * math.sin(t) self.view.recenter_view(cx, cy)
def remove_all_actions_of_type(self, type): gl = gameloop.get_game_loop() gl._actionmanager.remove_actions(self, lambda x: isinstance(x, type))
def remove_all_actions(self): gl = gameloop.get_game_loop() gl._actionmanager.remove_all_actions(self)
def get_active_actions(self): gl = gameloop.get_game_loop() return gl._actionmanager.get_active_actions(self)
def start(self): gl = get_game_loop() now = gl.now() self.start_time = now