def on_create_floating_number(self, ev: CreateFloatingNumber, signal): T = Text(str(ev.number), ev.position, color=ev.color, layer=500) ev.scene.add(T) T.scene = ev.scene T.setup() tween(T, 'position', ev.position + ppb.Vector(0, -1), 0.5) tween(T, 'opacity', 0, 0.5) delay(0.5, lambda: T.remove(ev.scene))
def on_button_pressed(self, ev: ButtonPressed, signal): clicked = super().on_button_pressed(ev, signal) if clicked: # TODO: This is pretty cludging and won't always match the visual clouds self.cloud_radius = 0.5 self.cloud_id = int(get_time() * 1000) tweening.tween(self, "cloud_radius", C.SMOOSHROOM_CLOUD_RADIUS_MAX, C.SMOOSHROOM_CLOUD_RADIUS_TIME, easing='quad_out')
def on_viking_attack(self, ev, signal): super().on_viking_attack(ev, signal) if ev.target is self: self.smooshed = True self.cloud += C.SMOOSHROOM_TOXIN_DMG_RATE self.toxins -= C.SMOOSHROOM_TOXIN_DMG_RATE self.cloud_radius = 0.5 self.cloud_id = int(get_time() * 1000) tweening.tween(self, "cloud_radius", C.SMOOSHROOM_CLOUD_RADIUS_MAX, C.SMOOSHROOM_CLOUD_RADIUS_TIME, easing='quad_out') delay(0.25, lambda: setattr(self, 'smooshed', False))
def on_update(self, ev, signal): t = perf_counter() r = 0.25 if self.smooshed else 1.0 if not self.exhausted and self.last_shot + r <= t and self.toxins > C.PODDACIM_POD_RATE: self.last_shot = t vikings = [v for v in ev.scene.get(tag='viking') if v.hp > 0] vikings.sort( key=lambda viking: (viking.position - self.position).length) if vikings: dist = (vikings[0].position - self.position).length if dist < C.PODDACIM_ATK_RADIUS: pod = PoddacimPod(position=self.position) tweening.tween(pod, 'position', vikings[0].position, C.PODDACIM_POD_SPEED) ev.scene.add(pod) self.toxins = max( 0.0, round(self.toxins - C.PODDACIM_POD_RATE, 2)) # TODO: Change meter updates to references signal(MeterUpdate(self, 'toxins', self.toxins)) # When toxins hit 0, Poddacim becomes exhausted if self.toxins == 0.0: self.exhausted = True def _(): vikings[0].on_mushroom_attack( MushroomAttack(None, vikings[0], C.PODDACIM_POD_DMG, scene=ev.scene), signal) ev.scene.remove(pod) delay(C.PODDACIM_POD_SPEED, _) # If the mushroom isn't being smooshed, increase toxin accumulator # and reset the cloud accumulator. if self.toxins < 1.0 and not self.smooshed or self.exhausted: self.toxins = min( 1.0, self.toxins + ev.time_delta * C.PODDACIM_TOXIN_CHARGE) # When toxins are full, no longer exhausted if self.toxins == 1.0: self.exhausted = False # TODO: Change meter updates to references signal( MeterUpdate(self, 'toxins', self.toxins, flash=self.exhausted))
def open_menu(self): tween(self.bg, 'size', 8.0, 1.0, easing='bounce_out') for opt in self.opt_texts: tween(opt, 'size', 2.0, 1.0, easing='bounce_out') tween(self.txt_title, 'size', 2.0, 1.0, easing='bounce_out') self.menu_active = True
def close_menu(self): tween(self.bg, 'size', 0.0, 1.0, easing='bounce_out') for opt in self.opt_texts: tween(opt, 'size', 0.0, 0.5, easing='quad_in') tween(self.txt_title, 'size', 0.0, 0.5, easing='quad_in') self.menu_active = False
def enter_state(self, scene, signal): self.parts['base'].image = ppb.Image("resources/viking/dead_bg.png") for s in self.sprites: tweening.tween(s, 'rotation', 90, 0.5) tweening.tween(s, 'opacity', 0, 5.0) tweening.tween(self, 'position', self.position + ppb.Vector(-0.5, -0.25), 0.5) self.parts['corpse'].opacity = 255 signal(VikingDeath(self))
def on_emit_cloud(self, ev, signal): r = 360 / self.STEPS for i in range(self.STEPS): w = random.randrange(-r//2, r//2) heading = ppb.Vector(C.SMOOSHROOM_CLOUD_RADIUS_MAX, 0).rotate(w + r * i) cloud = Cloud(heading=heading, position=ev.position, cloud_id=ev.cloud_id) cloud.size = 0.0 ev.scene.add(cloud) tweening.tween(cloud, "position", ev.position + heading, 1.0, easing='quint_out') tweening.tween(cloud, "size", 1.0, 1.0, easing='quad_out') tweening.tween(cloud, "opacity", 0.0, 1.0, easing='linear') delay(1.0, lambda cloud=cloud: ev.scene.remove(cloud))