def think(self, dt): if self.done or not self.available: return self.t += dt inmapper = isinstance(state.you, thing.Mapper) showingmap = inmapper and state.you.deployed if self.progress == 0: self.progress = 1 payloads = [ thing.Payload(pos = pos) for pos in state.worlddata["payloads"][:3] ] state.objs.extend(payloads) state.goals.extend(payloads) self.goals = [p.thingid for p in payloads] if self.progress == 1 and self.t > 2: dialog.play("start1") if self.progress == 1 and self.t > 3 and dialog.tquiet and not inmapper: mappers = [ship for ship in state.ships if isinstance(ship, thing.Mapper)] nearestid = min(mappers, key = lambda obj: window.distance(obj, state.you)).thingid if mappers else None if not self.mappertargetid or thing.get(self.mappertargetid).parentid != nearestid: if self.mappertargetid: thing.get(self.mappertargetid).die() if nearestid: mappertarget = thing.ShipTarget(parentid = nearestid) state.effects.append(mappertarget) self.mappertargetid = mappertarget.thingid if self.progress > 1 and self.mappertargetid: if thing.get(self.mappertargetid): thing.get(self.mappertargetid).die() self.mappertargetid = None if self.progress == 1 and inmapper: self.progress = 2 dialog.play("start2") if self.progress == 2 and showingmap: self.progress = 3 if self.progress == 3 and not showingmap and dialog.tquiet > 5: dialog.play("start3") if self.progress >= 1: if any(window.distance(thing.get(goal), state.you) < 20 for goal in self.goals): dialog.play("convo3") self.progress = 4 if self.progress >= 4: nvisible = sum(thing.get(goal).isvisible() for goal in self.goals) if self.progress == 4 and nvisible >= 1: dialog.play("convo4") self.progress = 5 if self.progress == 5 and nvisible >= 2: dialog.play("convo7") self.progress = 6 if self.progress == 6 and nvisible == 3: dialog.play("convo8") self.progress = 7 self.done = True quests["Act2"].setup() if not self.distressed and state.you.y < 270: dialog.play("distress")
def think(self, dt): if self.done or not self.available: return self.t += dt inmapper = isinstance(state.you, thing.Mapper) showingmap = inmapper and state.you.deployed if self.progress == 0: self.progress = 1 payloads = [thing.Payload(pos=pos) for pos in state.worlddata["payloads"][:3]] state.objs.extend(payloads) state.goals.extend(payloads) self.goals = [p.thingid for p in payloads] if self.progress == 1 and self.t > 2: dialog.play("start1") if self.progress == 1 and self.t > 3 and dialog.tquiet and not inmapper: mappers = [ship for ship in state.ships if isinstance(ship, thing.Mapper)] nearestid = min(mappers, key=lambda obj: window.distance(obj, state.you)).thingid if mappers else None if not self.mappertargetid or thing.get(self.mappertargetid).parentid != nearestid: if self.mappertargetid: thing.get(self.mappertargetid).die() if nearestid: mappertarget = thing.ShipTarget(parentid=nearestid) state.effects.append(mappertarget) self.mappertargetid = mappertarget.thingid if self.progress > 1 and self.mappertargetid: if thing.get(self.mappertargetid): thing.get(self.mappertargetid).die() self.mappertargetid = None if self.progress == 1 and inmapper: self.progress = 2 dialog.play("start2") if self.progress == 2 and showingmap: self.progress = 3 if self.progress == 3 and not showingmap and dialog.tquiet > 5: dialog.play("start3") if self.progress >= 1: if any(window.distance(thing.get(goal), state.you) < 20 for goal in self.goals): dialog.play("convo3") self.progress = 4 if self.progress >= 4: nvisible = sum(thing.get(goal).isvisible() for goal in self.goals) if self.progress == 4 and nvisible >= 1: dialog.play("convo4") self.progress = 5 if self.progress == 5 and nvisible >= 2: dialog.play("convo7") self.progress = 6 if self.progress == 6 and nvisible == 3: dialog.play("convo8") self.progress = 7 self.done = True quests["Act2"].setup() if not self.distressed and state.you.y < 270: dialog.play("distress")
def think(self, dt): if self.done or not self.available: return self.t += dt if self.progress == 0 and self.t > 1: self.progress += 1 self.settarget() state.effects.append(state.target) if self.progress in (1, 2, 3, 5, 6, 8): if window.distance(state.you, state.target) < 1: hud.hide("Hold space (or enter, shift, or Z) and use arrows to teleport between ships.") state.target.die() self.progress += 1 self.settarget() elif self.progress in (4, 7, 9): if state.target is state.you: self.progress += 1 self.settarget() if self.progress == 10: if not dialog.queue and not dialog.currentline: from src.scenes import title scene.current = title scene.toinit = title self.done = True
def think(self, dt): if self.done or not self.available: return self.t += dt if self.progress == 0 and self.t > 1: dialog.play("convo2") self.progress = 1 payloads = [ thing.Payload(pos = pos) for pos in state.worlddata["payloads"][:3] ] state.objs.extend(payloads) state.goals.extend(payloads) self.goals = [p.thingid for p in payloads] if self.progress == 1: if any(window.distance(thing.get(goal), state.you) < 20 for goal in self.goals): dialog.play("convo3") self.progress = 2 if self.progress >= 2: nvisible = sum(thing.get(goal).isvisible() for goal in self.goals) if self.progress == 2 and nvisible >= 1: dialog.play("convo4") self.progress = 3 if self.progress == 3 and nvisible >= 2: dialog.play("convo7") self.progress = 4 if self.progress == 4 and nvisible == 3: dialog.play("convo8") self.progress = 5 self.done = True quests["Act2"].setup() if not self.distressed and state.you.y < 270: dialog.play("distress")
def retarget(): target = None d2 = 4 * settings.rqteleport**2 X, y = control["qtarget"] for ship in state.ships: if window.distance(ship, state.you) > settings.rqteleport: continue dx = math.Xmod(ship.X - X) * (ship.y + y) / 2 dy = ship.y - y if dx**2 + dy**2 < d2: target = ship d2 = dx**2 + dy**2 if target: control["cursor"] = target
def retarget(): target = None d2 = 4 * settings.rqteleport ** 2 X, y = control["qtarget"] for ship in state.ships: if window.distance(ship, state.you) > settings.rqteleport: continue dx = math.Xmod(ship.X - X) * (ship.y + y) / 2 dy = ship.y - y if dx ** 2 + dy ** 2 < d2: target = ship d2 = dx ** 2 + dy ** 2 if target: control["cursor"] = target
def buildnetwork(): from src import thing, window del network[:] nobjs = [mother.thingid] + [ship.thingid for ship in ships if ship.rnetwork()] if len(nobjs) < 2: return ds = {} for id0 in nobjs: for id1 in nobjs: if id0 >= id1: continue thing0, thing1 = thing.get(id0), thing.get(id1) rmax = max(thing0.rnetwork(), thing1.rnetwork()) d = window.distance(thing0, thing1) if d <= rmax: ds[(id0, id1)] = d # TODO: remove triangles for id0, id1 in ds: network.append((thing.get(id0), thing.get(id1)))
def buildnetwork(): from src import thing, window del network[:] nobjs = [mother.thingid ] + [ship.thingid for ship in ships if ship.rnetwork()] if len(nobjs) < 2: return ds = {} for id0 in nobjs: for id1 in nobjs: if id0 >= id1: continue thing0, thing1 = thing.get(id0), thing.get(id1) rmax = max(thing0.rnetwork(), thing1.rnetwork()) d = window.distance(thing0, thing1) if d <= rmax: ds[(id0, id1)] = d # TODO: remove triangles for id0, id1 in ds: network.append((thing.get(id0), thing.get(id1)))
def isvisible(self): for obj in state.beacons: if window.distance(obj, self) < self.rdetect: return True return False
def think(dt, events, kpressed): global todraw kx = kpressed["right"] - kpressed["left"] ky = kpressed["up"] - kpressed["down"] dt0 = dt if kpressed["go"] and control: dt *= 0.3 hud.think(dt0) quest.think(dt) dialog.think(dt0) background.think(dt) sound.epicness = 2 - (state.you.y - 100) / 160 sound.think(dt) oldX, oldy = state.you.X, state.you.y if 1e10 * random.random() < dt: state.ships.append( thing.Skiff(X=random.uniform(0, math.tau), y=state.R, vx=random.uniform(-6, 6))) state.ships.append( thing.Beacon(X=random.uniform(0, math.tau), y=state.R, vx=random.uniform(-6, 6))) nbubble = int(dt * 30) + (random.random() < dt * 30 % 1) for _ in range(nbubble): X = random.gauss(state.you.X, 30 / state.you.y) y = random.gauss(state.you.y, 30) if y < state.R - 10: state.effects.append(thing.Bubble(X=X, y=y)) if sum(isinstance(effect, thing.BubbleChain) for effect in state.effects) < 10: for c in state.convergences: N = math.clamp((100 / window.distance(state.you, c))**2, 0.05, 1) nbubble = int(dt * N) + (random.random() < dt * N % 1) for _ in range(nbubble): X = random.gauss(state.you.X, 30 / state.you.y) y = random.gauss(state.you.y, 30) if state.Rcore < y < state.R - 20: state.effects.append( thing.BubbleChain(X=X, y=y, X0=c.X, y0=c.y)) for event in events: if event.type == KEYDOWN and event.key == "go": control.clear() control["cursor"] = state.you control["queue"] = {} control["qtarget"] = [state.you.X, state.you.y] control["t0"] = 0.001 * pygame.time.get_ticks() if event.type == KEYDOWN and event.key == "abort": if not state.you.significant: state.you.die() regenerate() if event.type == KEYUP: if not state.quickteleport and "queue" in control and event.key in ( "up", "left", "right", "down"): control["queue"][event.key] = 0 if event.type == KEYUP and event.key == "go" and "cursor" in control: if control["cursor"] is not state.you: state.effects.append( thing.Teleport(X=state.you.X, y=state.you.y, targetid=control["cursor"].thingid)) sound.play("teleport") state.you = control["cursor"] elif 0.001 * pygame.time.get_ticks( ) - control["t0"] < settings.tactivate: state.you.deploy() control.clear() if kpressed["go"] and control: if any(kpressed[x] for x in ("left", "right", "up", "down")): control["t0"] = -1000 if state.quickteleport: control["qtarget"][ 0] += kx * dt0 * settings.vqteleport / control["qtarget"][1] control["qtarget"][1] += ky * dt0 * settings.vqteleport dx = math.Xmod(control["qtarget"][0] - state.you.X) * state.you.y dy = control["qtarget"][1] - state.you.y f = math.sqrt(dx**2 + dy**2) / settings.rqteleport if f > 1: dx /= f dy /= f control["qtarget"] = [ state.you.X + dx / state.you.y, state.you.y + dy ] retarget() else: q = control["queue"] for key in q: q[key] += dt0 if q[key] >= settings.jumpcombotime: dx = ("right" in q) - ("left" in q) dy = ("up" in q) - ("down" in q) jump(dx, dy) q.clear() break else: dvx = kx * dt * 20 dvy = ky * dt * 20 state.you.vx += dvx state.you.vy = min(state.you.vy + dvy, 0) todraw = [] scollide = [] hcollide = [] state.you.think(0) # Clear out any controls that should be overridden for convergence in state.convergences: if window.camera.near(convergence): convergence.think(dt) todraw.append(convergence) repopulating = (dt + state.you.t % 1) // 1 if repopulating: nships = [] for ship in state.ships: if not window.camera.on( ship) and ship is not state.you and not ship.significant: continue ship.think(dt) if ship.alive: nships.append(ship) todraw.append(ship) else: ship.die() state.ships = nships repopulateslice() else: nships = [] for ship in state.ships: if not window.camera.near(ship): nships.append(ship) continue ship.think(dt) if ship.alive: nships.append(ship) if window.camera.on(ship): todraw.append(ship) else: ship.die() state.ships = nships if not state.you.alive: regenerate() nobjs = [] for obj in state.objs: if not window.camera.on(obj): nobjs.append(obj) continue obj.think(dt) if obj.alive: nobjs.append(obj) todraw.append(obj) else: obj.die() state.obj = nobjs for hazard in state.hazards: if not window.camera.near(hazard): continue hazard.think(dt) todraw.append(hazard) if window.camera.on(hazard): hcollide.append(hazard) state.obj = nobjs # for filament in state.filaments: # filament.think(dt) neffects = [] for effect in state.effects: effect.think(dt) if effect.alive: todraw.append(effect) neffects.append(effect) else: effect.die() state.effects = neffects scollide = [state.you] for s in scollide: if not s.vulnerable(): continue for h in hcollide: if window.distance(h, s) < h.hazardsize: s.takedamage(h.dhp) if window.dbycoord((oldX, oldy), (state.you.X, state.you.y)) > settings.rqteleport + 10: clearfull() populatefull() if state.quickteleport and "qtarget" in control: X, y = control["qtarget"] dX = math.Xmod(X - state.you.X) dy = y - state.you.y window.camera.X0 = state.you.X + dX * 0.5 window.camera.y0 = state.you.y + dy * 0.5 window.camera.setlimits() else: window.camera.follow(state.you) window.camera.think(dt)
def think(dt, events, kpressed): global todraw kx = kpressed["right"] - kpressed["left"] ky = kpressed["up"] - kpressed["down"] dt0 = dt if kpressed["go"] and control: dt *= 0.3 hud.think(dt0) quest.think(dt) dialog.think(dt0) background.think(dt) sound.epicness = 2 - (state.you.y - 100) / 160 sound.think(dt) oldX, oldy = state.you.X, state.you.y if 1e10 * random.random() < dt: state.ships.append(thing.Skiff( X = random.uniform(0, math.tau), y = state.R, vx = random.uniform(-6, 6) )) state.ships.append(thing.Beacon( X = random.uniform(0, math.tau), y = state.R, vx = random.uniform(-6, 6) )) nbubble = int(dt * 30) + (random.random() < dt * 30 % 1) for _ in range(nbubble): X = random.gauss(state.you.X, 30 / state.you.y) y = random.gauss(state.you.y, 30) if y < state.R - 10: state.effects.append(thing.Bubble(X = X, y = y)) if sum(isinstance(effect, thing.BubbleChain) for effect in state.effects) < 10: for c in state.convergences: N = math.clamp((100 / window.distance(state.you, c)) ** 2, 0.05, 1) nbubble = int(dt * N) + (random.random() < dt * N % 1) for _ in range(nbubble): X = random.gauss(state.you.X, 30 / state.you.y) y = random.gauss(state.you.y, 30) if state.Rcore < y < state.R - 20: state.effects.append(thing.BubbleChain(X = X, y = y, X0 = c.X, y0 = c.y)) for event in events: if event.type == KEYDOWN and event.key == "go": control.clear() control["cursor"] = state.you control["queue"] = {} control["qtarget"] = [state.you.X, state.you.y] control["t0"] = 0.001 * pygame.time.get_ticks() if event.type == KEYDOWN and event.key == "abort": if not state.you.significant: state.you.die() regenerate() if event.type == KEYUP: if not state.quickteleport and "queue" in control and event.key in ("up", "left", "right", "down"): control["queue"][event.key] = 0 if event.type == KEYUP and event.key == "go" and "cursor" in control: if control["cursor"] is not state.you: state.effects.append( thing.Teleport(X = state.you.X, y = state.you.y, targetid = control["cursor"].thingid) ) sound.play("teleport") state.you = control["cursor"] elif 0.001 * pygame.time.get_ticks() - control["t0"] < settings.tactivate: state.you.deploy() control.clear() if kpressed["go"] and control: if any(kpressed[x] for x in ("left", "right", "up", "down")): control["t0"] = -1000 if state.quickteleport: control["qtarget"][0] += kx * dt0 * settings.vqteleport / control["qtarget"][1] control["qtarget"][1] += ky * dt0 * settings.vqteleport dx = math.Xmod(control["qtarget"][0] - state.you.X) * state.you.y dy = control["qtarget"][1] - state.you.y f = math.sqrt(dx ** 2 + dy ** 2) / settings.rqteleport if f > 1: dx /= f dy /= f control["qtarget"] = [state.you.X + dx / state.you.y, state.you.y + dy] retarget() else: q = control["queue"] for key in q: q[key] += dt0 if q[key] >= settings.jumpcombotime: dx = ("right" in q) - ("left" in q) dy = ("up" in q) - ("down" in q) jump(dx, dy) q.clear() break else: dvx = kx * dt * 20 dvy = ky * dt * 20 state.you.vx += dvx state.you.vy = min(state.you.vy + dvy, 0) todraw = [] scollide = [] hcollide = [] state.you.think(0) # Clear out any controls that should be overridden for convergence in state.convergences: if window.camera.near(convergence): convergence.think(dt) todraw.append(convergence) repopulating = (dt + state.you.t % 1) // 1 if repopulating: nships = [] for ship in state.ships: if not window.camera.on(ship) and ship is not state.you and not ship.significant: continue ship.think(dt) if ship.alive: nships.append(ship) todraw.append(ship) else: ship.die() state.ships = nships repopulateslice() else: nships = [] for ship in state.ships: if not window.camera.near(ship): nships.append(ship) continue ship.think(dt) if ship.alive: nships.append(ship) if window.camera.on(ship): todraw.append(ship) else: ship.die() state.ships = nships if not state.you.alive: regenerate() nobjs = [] for obj in state.objs: if not window.camera.on(obj): nobjs.append(obj) continue obj.think(dt) if obj.alive: nobjs.append(obj) todraw.append(obj) else: obj.die() state.obj = nobjs for hazard in state.hazards: if not window.camera.near(hazard): continue hazard.think(dt) todraw.append(hazard) if window.camera.on(hazard): hcollide.append(hazard) state.obj = nobjs # for filament in state.filaments: # filament.think(dt) neffects = [] for effect in state.effects: effect.think(dt) if effect.alive: todraw.append(effect) neffects.append(effect) else: effect.die() state.effects = neffects scollide = [state.you] for s in scollide: if not s.vulnerable(): continue for h in hcollide: if window.distance(h, s) < h.hazardsize: s.takedamage(h.dhp) if window.dbycoord((oldX, oldy), (state.you.X, state.you.y)) > settings.rqteleport + 10: clearfull() populatefull() if state.quickteleport and "qtarget" in control: X, y = control["qtarget"] dX = math.Xmod(X - state.you.X) dy = y - state.you.y window.camera.X0 = state.you.X + dX * 0.5 window.camera.y0 = state.you.y + dy * 0.5 window.camera.setlimits() else: window.camera.follow(state.you) window.camera.think(dt)