def announce_level(self, num, name): text = OnscreenText(text='LEVEL ' + str(num), font=self.font, parent=base.aspect2d, pos=(0, 0.3), scale=0.1, fg=(1, 1, 1, 1)) text.set_transparency(1) text.set_color_scale((1, 1, 1, 0)) Sequence( Wait(1.0), text.colorScaleInterval(1.0, (1, 1, 1, 1)), Wait(2.0), text.colorScaleInterval(1.0, (1, 1, 1, 0)), Func(text.destroy), ).start() subtext = OnscreenText(text=name.upper(), font=self.font, parent=base.aspect2d, pos=(0, 0.1), scale=0.08, fg=(1, 1, 1, 1)) subtext.set_transparency(1) subtext.set_color_scale((1, 1, 1, 0)) Sequence( Wait(2.0), subtext.colorScaleInterval(1.0, (1, 1, 1, 1)), Wait(2.0), subtext.colorScaleInterval(1.0, (1, 1, 1, 0)), Func(subtext.destroy), ).start()
def announce_game_over(self): text = OnscreenText(text='GAME OVER', font=self.font, parent=base.aspect2d, pos=(0, 0.3), scale=0.1, fg=(1, 1, 1, 1)) text.set_transparency(1) text.set_color_scale((1, 1, 1, 0)) Sequence( text.colorScaleInterval(1.0, (1, 1, 1, 1)), Wait(2.0), text.colorScaleInterval(1.75, (1, 0, 0, 0)), Func(text.destroy), ).start()
async def get_hit(self, bullet_type=None): if not self.root: return self.hp -= 1 if self.hp < 0: # Score gain flies off. scale = math.sqrt(self.score_gain) / 25.0 base.add_score(self.score_gain) text = OnscreenText(str(self.score_gain), font=base.gui.font, parent=base.render, scale=scale, fg=(1, 1, 1, 1)) text.set_light_off(True) text.set_z(10) text.set_pos(self.root.get_pos()) text.set_depth_test(False) dir = base.player.root.get_x() - self.root.get_x() if dir == 0: dir = choice((-1, 1)) if dir < 5: dir *= 5 / abs(dir) text.posInterval( 1.0, self.root.get_pos() + (-dir, base.player.speed.y * 0.6, 0)).start() text.scaleInterval(1.0, scale * 2).start() text.set_transparency(1) Sequence(Wait(0.25), text.colorScaleInterval(0.75, (1, 0, 0, 0))).start() self.die() else: self.root.set_color_scale((1, 0, 0, 1)) await WaitInterval(0.1) if self.root: self.root.clear_color_scale()