def init(): global playing, tplay state.effects.append(thing.FirstConvergence(X=state.you.X, y=state.you.y)) sound.epicness = 2 sound.play("reveal") playing = False tplay = 0
def settarget(self): if self.progress > 1: sound.play("yes") if self.progress == 1: hud.show("Use arrow keys or WASD to move.") dialog.play("intro1") elif self.progress == 2: hud.clear() elif self.progress == 4: hud.show("Hold space (or enter, shift, or Z) and use arrows to teleport between ships.") dialog.play("intro2") elif self.progress == 5: hud.clear() elif self.progress == 6: dialog.play("intro3") elif self.progress == 10: dialog.play("intro4") if self.progress in (1, 2, 3, 5, 6, 8): dx, dy = self.tps[self.progress] state.target = thing.Target(X = dx / window.camera.y0, y = window.camera.y0 - dy) state.effects.append(state.target) elif self.progress in (4, 7, 9): state.target = None # better chance of getting something not obscured by the HUD if self.progress == 4: state.target = state.ships[-1] while state.target in (None, state.you): state.target = random.choice(state.ships) state.effects.append(thing.ShipTarget(parentid = state.target.thingid))
def settarget(self): if self.progress > 1: sound.play("yes") if self.progress == 1: hud.show("Use arrow keys or WASD to move.") dialog.play("intro1") elif self.progress == 2: hud.clear() elif self.progress == 4: hud.show("Hold space (or enter, shift, or Z) and use arrows to teleport between ships.") dialog.play("intro2") elif self.progress == 5: hud.clear() elif self.progress == 6: dialog.play("intro3") elif self.progress == 10: dialog.play("intro4") if self.progress in (1, 2, 3, 5, 6, 8): dx, dy = self.tps[self.progress] state.target = thing.Target(X=dx / window.camera.y0, y=window.camera.y0 - dy) state.effects.append(state.target) elif self.progress in (4, 7, 9): state.target = None # better chance of getting something not obscured by the HUD if self.progress == 4: state.target = state.ships[-1] while state.target in (None, state.you): state.target = random.choice(state.ships) state.effects.append(thing.ShipTarget(parentid=state.target.thingid))
def deploy(self): if self.deployed: sound.play("no") else: self.deployed = True self.significant = True sound.play("chirpup")
def init(): global playing, tplay state.effects.append(thing.FirstConvergence(X = state.you.X, y = state.you.y)) sound.epicness = 2 sound.play("reveal") playing = False tplay = 0
def regenerate(): target = thing.Skiff(X = state.mother.X, y = state.mother.y - 11, vx = 0) state.you = thing.SlowTeleport(X = state.you.X, y = state.you.y, targetid = target.thingid) state.ships.append(target) state.effects.append(state.you) sound.play("longteleport") control.clear() dialog.play("convo5")
def deploy(self): sound.play("warp") self.X += math.tau / 1.618 window.camera.X0 += math.tau / 1.618 self.X %= math.tau window.camera.X0 %= math.tau self.tflash = settings.twarpinvulnerability state.effects.append(WarpEffect(X = self.X, y = self.y))
def takedamage(self, dhp): if not self.vulnerable(): return self.hp -= dhp if self is state.you: sound.play("ouch") self.tflash = settings.thurtinvulnerability if self.hp <= 0: self.die()
def deploy(self): nvis0 = sum(obj.isvisible() for obj in state.goals + state.convergences) if self in state.beacons: state.beacons.remove(self) if self.deployed: state.beacons.append(self) nvis1 = sum(obj.isvisible() for obj in state.goals + state.convergences) if nvis1 > nvis0: sound.play("reveal")
def regenerate(): target = thing.Skiff(X=state.mother.X, y=state.mother.y - 11, vx=0) state.you = thing.SlowTeleport(X=state.you.X, y=state.you.y, targetid=target.thingid) state.ships.append(target) state.effects.append(state.you) sound.play("longteleport") control.clear() dialog.play("convo5")
def think(self, dt): if self.done or not self.available: return self.t += dt n = sum(beacon.y - state.Rcore < 20 for beacon in state.beacons) if n > self.progress: self.progress = n if n < settings.beaconsforfinale: hud.show("Detector placement: %d/%d" % (n, settings.beaconsforfinale), 5) sound.play("reveal") else: hud.show("Detector placement complete. Proceed through data horizon.", 6) self.done = True
def regenerate(): state.you = thing.Skiff(X=state.mother.X, y=state.mother.y - 11, vx=0) window.camera.X0 = state.you.X window.camera.y0 = state.you.y state.ships.append(state.you) clearfull() populatefull() sound.play("longteleport") control.clear() dialog.play("convo5") background.wash() background.drawwash() if settings.saveonemergency: state.save()
def regenerate(): state.you = thing.Skiff(X = state.mother.X, y = state.mother.y - 11, vx = 0) window.camera.X0 = state.you.X window.camera.y0 = state.you.y state.ships.append(state.you) clearfull() populatefull() sound.play("longteleport") control.clear() dialog.play("convo5") background.wash() background.drawwash() if settings.saveonemergency: state.save()
def deploy(self): sound.play("no")
def deploy(self): self.deployed = not self.deployed self.significant = self.deployed sound.play("chirpup" if self.deployed else "chirpdown")
def on_mouse_press(x, y, button, modifiers): current_scene = scene.get() # Left click if button == mouse.LEFT: # Menu clicks if current_scene is 'menu': # Music button if (x >= 40 and x <= 86 and y >= 13 and y <= 59) or (x >= 116 and x <= 294 and y >= 21 and y <= 50): sound.play('02') settings.toggleMusic() # Sound button if (x >= 404 and x <= 450 and y >= 13 and y <= 59) or (x >= 480 and x <= 790 and y >= 21 and y <= 50): sound.play('02') settings.toggleSound() # About button if x >= 932 and x <= 978 and y >= 13 and y <= 59 or menu.hasAbout() == True: sound.play('03') menu.toggleAbout() # Play button if x >= 40 and x <= 310 and y >= 497 and y <= 572: sound.play('01') levels.init() # Levels clicks elif current_scene is 'levels': # Back button if x >= 20 and x <= 204 and y >= 15 and y <= 57: sound.play('01') menu.init() # Fight (bacteria) button if x >= 142 and x <= 392 and y >= 199 and y <= 244: sound.play('04') game.init('bacteria') # Fight (virus) button if x >= 632 and x <= 882 and y >= 199 and y <= 244: sound.play('04') game.init('virus') # Help (bacteria) button if x >= 142 and x <= 392 and y >= 164 and y <= 198: sound.play('03') help.init('bacteria') # Help (virus) button if x >= 632 and x <= 882 and y >= 164 and y <= 198: sound.play('03') help.init('virus') # Difficulty (easy) button if x >= 452 and x <= 482 and y >= 15 and y <= 57: sound.play('02') settings.toggleDifficulty(1) # Difficulty (medium) button if x >= 497 and x <= 528 and y >= 15 and y <= 57: sound.play('02') settings.toggleDifficulty(2) # Difficulty (hard) button if x >= 542 and x <= 573 and y >= 15 and y <= 57: sound.play('02') settings.toggleDifficulty(3) # Help clicks elif current_scene is 'help': scene.set('levels') help.slide(1) # Game clicks elif current_scene is 'game': # End of game motion if game.state() is 'win' or game.state() is 'loose': # Quit button if x >= 260 and x <= 304 and y >= 124 and y <= 172: pyglet.app.exit() # Menu button elif x >= 324 and x <= 372 and y >= 124 and y <= 166: menu.init() # Retry button elif x >= 694 and x <= 742 and y >= 124 and y <= 172: game.init(mode.get()) # Paused game clicks elif game.paused() is True: # Quit button if x >= 341 and x <= 386 and y >= 227 and y <= 270: pyglet.app.exit() # Menu button elif x >= 405 and x <= 453 and y >= 227 and y <= 270: if game.pause() is False: menu.init() # Resume button elif x >= 647 and x <= 683 and y >= 227 and y <= 270: if game.pause() is False: cursor.disable() background.scene_speed('game') return True
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): 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.flowt += dt 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] 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"] control.clear() if kpressed["go"] and control: 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 += dvy state.you.think(0) # Clear out any controls that should be overridden for ship in state.ships: ship.think(dt) dx = y0 * ship.X dy = ship.y - y0 f = math.sqrt(dx ** 2 + dy ** 2) / 15 if f > 1: ship.X /= f ship.y = y0 + dy / f ship.vx = 0 ship.vy = 0 for effect in state.effects: effect.think(dt) state.effects = [e for e in state.effects if e.alive] window.camera.X0 = 0 window.camera.y0 = y0 window.camera.R = window.sy / 32
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): 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, 1) 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] 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"] control.clear() if kpressed["go"] and control: 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 += dvy state.you.think(0) # Clear out any controls that should be overridden for ship in state.ships: ship.think(dt) dx = y0 * ship.X dy = ship.y - y0 f = math.sqrt(dx**2 + dy**2) / 15 if f > 1: ship.X /= f ship.y = y0 + dy / f ship.vx = 0 ship.vy = 0 for effect in state.effects: effect.think(dt) state.effects = [e for e in state.effects if e.alive] window.camera.X0 = 0 window.camera.y0 = y0 window.camera.R = window.sy / 32