def step(self, packet: GameTickPacket, drone: Drone, index: int): if drone.position[2] < 25: drone.since_jumped = 0.0 # Go forward drone.controls.throttle = 1.0 if abs( drone.velocity[1]) < 500 else 0.01 # If near half-line if abs(drone.position[1]) < 200: drone.controls.jump = True else: drone.since_jumped += self.dt height = 50 + drone.since_jumped * 150 angle = 1.0 + drone.since_jumped * 1.2 if index % 2 == 0: angle += math.pi rot = rotation(angle) v = vec3(dot(rot, vec2(1, 0))) drone.hover.target = v * self.radius drone.hover.target[2] = height drone.hover.up = normalize(drone.position) drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): # Get centre of small circle. direction_angle = (math.pi / 4) + ((math.pi / 2) * (index // 16)) centre = vec3(dot(rotation(direction_angle), vec2( 1, 0))) * self.big_radius centre[2] = self.height # Angle for the small circle. # Wraps nicely around the small circle. t = self.time_since_start + 2.5 if t > 2 * math.pi: t = 2 * math.pi angle = (t / 16) * (index % 16 - 8) angle += (2 * math.pi / 4) * (index // 16) + (math.pi / 4) target = vec3(dot(rotation(angle), vec2(self.small_radius, 0))) target += centre # Hover controls. drone.hover.up = normalize(drone.position - centre) drone.hover.target = target drone.hover.step(self.dt) drone.controls = drone.hover.controls # If any bot got lost, now they have a chance to recover. if drone.on_ground: drone.controls.jump = True else: drone.controls.jump = False
def step(self, packet: GameTickPacket, drone: Drone, index: int): up = normalize(drone.position) drone.aerial_turn.target = look_at(vec3(0, 0, 1), up) drone.aerial_turn.step(self.dt) drone.controls = drone.aerial_turn.controls drone.controls.boost = angle_between(vec3(0, 0, 1), drone.forward()) < 0.5 drone.controls.jump = True
def step(self, packet: GameTickPacket, drone: Drone, index: int): self.finished = (100 + self.big_radius - self.time_since_start * self.speed) <= 0 # Get centre of small circle. direction_angle = (math.pi / 4) + ((math.pi / 2) * (index // 16)) centre = vec3(dot(rotation(direction_angle), vec2(1, 0))) # Crossing action. centre *= (self.big_radius - self.time_since_start * self.speed) centre[2] = self.height # Angle for the small circle. angle = (2 * math.pi / 16) * (index % 16) angle += (2 * math.pi / 4) * (index // 16 - 1) angle += self.time_since_start * self.spin target = vec3(dot(rotation(angle), vec2(self.small_radius, 0))) target += centre # Different heights. target[2] += (index // 16 - 2) * self.height_diff # Hover controls. drone.hover.up = normalize(drone.position - centre) drone.hover.target = target drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): drone.hover.up = normalize(drone.position) clockwise_rotation = axis_to_rotation(vec3(0, 0, 0.5)) position_on_circle = normalize(xy(drone.position)) * 2000 drone.hover.target = dot(clockwise_rotation, position_on_circle) drone.hover.target[2] = 1000 drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): delay = index * self.clone_delay for movement in self.movements: if movement.start + delay < self.time_since_start < movement.end + delay: drone.controls = movement.controls if index == packet.num_cars - 1: self.finished = self.time_since_start > delay + self.movements[ -1].end
def step(self, packet: GameTickPacket, drone: Drone, index: int): radius = 1050 + 150 * self.time_since_start angle = math.pi + self.time_since_start * (math.pi / 5) angle += (2 * math.pi / 64) * index target = vec3(dot(rotation(angle), vec2(radius, 0))) target[2] = self.height drone.hover.up = normalize(-1 * xy(drone.position)) drone.hover.target = target drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): drone.hover.up = normalize(drone.position) rotation = axis_to_rotation(vec3(0, 0, self.spin * (-1)**(index // 16))) position_on_circle = normalize(xy(drone.position)) * ( self.radius + self.radius_increase * self.time_since_start) drone.hover.target = dot(rotation, position_on_circle) drone.hover.target[ 2] = self.height + self.height_increase * self.time_since_start drone.hover.target[2] += (index // 16 - 2) * ( self.height_diff + self.height_diff_increase * self.time_since_start) drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): for i, layer in enumerate(self.layers): if index in layer: drone.hover.up = normalize(drone.position) clockwise_rotation = axis_to_rotation(vec3(0, 0, 0.3)) position_on_circle = normalize(xy( drone.position)) * self.radii[i] drone.hover.target = dot(clockwise_rotation, position_on_circle) drone.hover.target[2] = self.heights[i] break drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): # Just ask me in discord about this. layer = (2 * (index // 16) + (index % 2) - 3.5) / 4 height = self.height + layer * self.radius radius = math.sqrt(1 - layer**2) * self.radius spin = 0 if self.time_since_start < 3.0 else 0.5 drone.hover.up = normalize(drone.position) rotation = axis_to_rotation(vec3(0, 0, spin)) position_on_circle = normalize(xy(drone.position)) * radius drone.hover.target = dot(rotation, position_on_circle) drone.hover.target[2] = height drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): # you have access to these class attributes self.time # the current game time self.start_time # game time when this step started self.time_since_start # for how long this step has been running self.dt # time since last frame self.finished = False # set to True if you want to finish this step early # lets make the drones fly up with the Aerial mechanic drone.aerial.target = drone.position + vec3(0, 0, 500) drone.aerial.up = normalize(drone.position) # aerial.up is where the car should orient its roof when flying drone.aerial.arrival_time = self.time + 0.5 # some time in the near future so it flies fast drone.aerial.step(self.dt) drone.controls = drone.aerial.controls drone.controls.jump = True # you can modify the controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): angle = (2 * math.pi / 64) * index target = vec3(dot(rotation(angle), vec2(self.radius, 0))) target[2] = self.height # Hover controls drone.hover.target = target drone.hover.up = normalize(drone.position) drone.hover.step(self.dt) drone.controls = drone.hover.controls # If any bot got lost, now they have a chance to recover. if drone.on_ground: drone.controls.jump = True else: drone.controls.jump = False
def step(self, packet: GameTickPacket, drone: Drone, index: int): if self.time_since_start > self.unwind_start_time: f = self.max_frequency - (self.time_since_start - self.unwind_start_time) else: f = self.max_frequency z = (index - 31.5) / 32 # For 64 bots :^) x = math.sqrt(1 - z**2) * math.cos(z * f) y = math.sqrt(1 - z**2) * math.sin(z * f) target = vec3(x, y, z) * self.radius target[2] += self.height drone.hover.up = normalize(drone.position) drone.hover.target = target drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): # Calculate shift direction. direction_angle = (math.pi / 4) + ((math.pi / 2) * (index // 16)) direction = vec3(dot(rotation(direction_angle), vec2(1, 0))) # Shift in one direction. angle = (2 * math.pi / 64) * index target = vec3(dot(rotation(angle), vec2(self.start_radius, 0))) target += direction * (self.end_radius - self.start_radius) * ( self.time_since_start / self.duration) target[2] = self.height target = (target + drone.position) / 2 # Hover controls. drone.hover.up = normalize(drone.position) drone.hover.target = target drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): if drone.start_pos is None: drone.start_pos = drone.position # spin = (index % 16 - 8) * 0.01 # Unwind helix. # rotation = axis_to_rotation(vec3(0, 0, spin)) # position_on_circle = normalize(xy(drone.position)) * self.start_radius # drone.hover.target = dot(rotation, position_on_circle) # drone.hover.target[2] = drone.start_pos[2] # drone.hover.step(self.dt) # drone.controls = drone.hover.controls current_radius = norm(vec2(drone.position)) desired_angle = (2 * math.pi / 64) * index current_angle = math.atan2(drone.position[1], drone.position[0]) if current_angle < 0.0: current_angle += 2 * math.pi # only positive angles # Expand radius. if current_radius < self.radius - 150: direction_angle = (math.pi / 4) + ((math.pi / 2) * (index // 16)) direction = vec3(dot(rotation(direction_angle), vec2(1, 0))) target = drone.position + direction * 200 target[2] = drone.start_pos[2] # Get to correct angle. elif abs(desired_angle - current_angle) > 0.05: target = vec3(dot(rotation(desired_angle), vec2(self.radius, 0))) target[2] = drone.start_pos[2] # Get to correct height. else: target = vec3(dot(rotation(desired_angle), vec2(self.radius, 0))) target[2] = self.height drone.hover.up = normalize(drone.position) drone.hover.target = target drone.hover.step(self.dt) drone.controls = drone.hover.controls
def step(self, packet: GameTickPacket, drone: Drone, index: int): if drone.since_jumped is None: # Control throttle start and jump. if self.time_since_start > self.delay * (index % 16): # Speed controller. drone.controls.throttle = 1.0 if max(abs( drone.velocity[0]), abs(drone.velocity[1])) < 500 else 0.03 # If near half-line if norm(vec3(0, 0, 0) - drone.position) < 700: drone.since_jumped = 0.0 drone.controls.jump = True # Create helix after jump. else: # Increment timer. drone.since_jumped += self.dt # HEIGHT if drone.since_jumped < 11: height = 150 + drone.since_jumped * 150 # speed of rise elif drone.since_jumped < 20: height = 1800 - (drone.since_jumped - 11) * 150 else: height = 450 + (drone.since_jumped - 16) * 30 height = min(height, 600) # RADIUS if drone.since_jumped < 11: radius = 500 elif drone.since_jumped < 15: radius = 500 - (drone.since_jumped - 10) * 50 elif drone.since_jumped < 17: radius = 300 elif drone.since_jumped < 20: radius = 300 + (drone.since_jumped - 17) * 100 else: radius = 400 + drone.since_jumped**3 / 10 radius = min(radius, 2000) # ANGLE if drone.since_jumped < 11: angle = drone.since_jumped * 0.4 # rotation speed elif drone.since_jumped < 20: angle = (11 * 0.4) + (drone.since_jumped - 11) * 0.6 else: angle = (11 * 0.4) + (9 * 0.6) + (drone.since_jumped - 20) * 0.3 # Offset angle. angle += (index // 16) * (math.pi / 2) # Set hover target and controller. rot = rotation(angle) v = vec3(dot(rot, vec2(1, 0))) drone.hover.target = v * radius drone.hover.target[2] = height drone.hover.up = normalize(drone.position) drone.hover.step(self.dt) drone.controls = drone.hover.controls if drone.since_jumped < 0.05: drone.controls.jump = True drone.controls.boost = False
def step(self, packet: GameTickPacket, drone: Drone, index: int): if drone.start_pos is None: drone.start_pos = drone.position drone.sort_phase = 1 # Finish if all have been sorted. if index == 0: # Initially set finished to True. self.finished = True if drone.sort_phase != 3: # Will be set to False if any is not in phase 3. self.finished = False # It's my time! if self.time_since_start > 0.5 + index * self.delay: desired_angle = (2 * math.pi / 64) * index # current_radius = norm(vec2(drone.position)) current_angle = math.atan2(drone.position[1], drone.position[0]) if current_angle < 0.0: current_angle += 2 * math.pi # only positive angles # Rotate to correct angle. if drone.sort_phase == 1: # if index in range(64)[::8]: print(index, current_angle, desired_angle) if abs(current_angle - desired_angle) < 0.1: drone.sort_phase = 2 target = dot(rotation(current_angle + 0.4), vec2(self.radius - 400, 0)) target = vec3(target) target[2] = self.height + (180 * index // 16) # Height and final corrections. elif drone.sort_phase == 2: target = vec3( dot(rotation(desired_angle), vec2(self.radius, 0))) target[2] = self.height if norm(drone.position - target) < 200: drone.sort_phase = 3 target[2] = (4 * drone.position[2] + self.height) / 5 elif drone.sort_phase == 3: target = vec3( dot(rotation(desired_angle), vec2(self.radius, 0))) target[2] = self.height else: # Stay in place. target = drone.start_pos # Hover controls drone.hover.target = target drone.hover.up = normalize(drone.position) drone.hover.step(self.dt) drone.controls = drone.hover.controls # If any bot got lost, now they have a chance to recover. if drone.on_ground: drone.controls.jump = True else: drone.controls.jump = False