def update(self, dt): """Trigger all callbacks and updates times""" if self._int_value != 0: # Nonzero check is okay as JoyAxis already count the threshold self.non_zero_time += dt self.zero_time = 0 else: self.non_zero_time = 0 self.zero_time += dt if self._smooth <= 0: self._value = self._int_value else: dv = dt / self._smooth if self._int_value > 0: self._value += dv elif self._int_value < 0: self._value -= dv else: if self._value > 0: self._value -= dv else: self._value += dv if abs(self._value) <= dv: # To have hard zeros self._value = 0 self._value = clamp(self._value, -1, 1) self._callbacks(self)
def init_level(): newbg = bg.Background(x = resources.screen_width * 0.5, y = resources.screen_height * 0.5) #pipe_x = resources.screen_width * 2 - resources.PIPE_DISTANCE pipe_x = 140 * resources.START_TIME pipe_y = resources.screen_height * 0.6 for i in range(0, resources.PIPE_AMOUNT): pipe_y = util.clamp(pipe_y + random.choice([-40, -20, 20, 40]), 200, resources.screen_height - 88) newpipe = pipe.PipeManager(x = pipe_x, y = pipe_y) pipe_x += resources.PIPE_DISTANCE newplayer = player.Player(x = 89, y = 300) game_window.push_handlers(newplayer.keyHandler) #newplayer = player.Player(x = 49, y = 300) #game_window.push_handlers(newplayer.keyHandler) tile_x = resources.screen_width * 0.5 - 336 for i in range(0, resources.TILE_AMOUNT): newtile = tile.Tile(x = tile_x, y = 56) tile_x += newtile.image.width newguimanager = gui.GUIManager(x = 0, y = 0) resources.GameManager.game_state = 'GAMEPLAY_STATE'
def update(self, dt): if self.aim is None: self.aim = self.find_aim() self.t = 0 self.initial_vel = vec3(self.velocity) if self.aim is None: return super().update(dt) if self.aim.position.z > self.position.z: self.aim = None return super().update(dt) self.t = clamp(self.t + dt * 5, 0, 1) vel = self.speed * normalize(self.aim.position - self.position) self.velocity = vel * self.t + self.initial_vel * (1 - self.t) return super().update(dt)
def value(self): return clamp(self._value + self._axis_value, -1, 1)