示例#1
0
 def explode(self, position):
     self.explosion = Sprite(self.node,
                             "assets/sprites/explosion/explosion_",
                             "png",
                             29,
                             2,
                             scale=(1, 1, 1),
                             fps=50)
     self.explosion.setPos(position[0], position[1] - 112, position[2] + 28)
     self.explosion.play()
示例#2
0
 def explode(self):
     print "EXPLODE"
     self.explosion = Sprite(
         parent=self.node,
         file_name="assets/sprites/blue_explosion/blue_explosion_",
         file_type="png",
         num_frames=13,
         int_padding=2,
         scale=(5, 5, 5))
     self.explosion.fps = 24
     self.explosion.setPos(8, 40, -2)
     self.explosion.play(loops=1)
     base.taskMgr.doMethodLater(0.5, self.showMatchNumber, 'match_show')
示例#3
0
    def explode_center(self):
        if not self.stack_screen.location_has_object("center_ramp",
                                                     mode="wtsa"):
            return False

        self.explosion = Sprite(self.node,
                                "assets/sprites/explosion/explosion_",
                                "png",
                                29,
                                2,
                                scale=(1, 1, 1),
                                fps=50)
        self.explosion.setPos(0.1, 8, 8.5)
        self.explosion.play()
        self.stack_screen.remove_bottom_model("center_ramp")
示例#4
0
    def explode_left(self):
        if not self.stack_screen.location_has_object("left_ramp", mode="wtsa"):
            return False

        self.explosion = Sprite(self.node,
                                "assets/sprites/explosion/explosion_",
                                "png",
                                29,
                                2,
                                scale=(1, 1, 1),
                                fps=50)
        self.explosion.setPos(-1.3, 10, 6.9)
        self.explosion.play()
        self.stack_screen.remove_bottom_model("left_ramp")
        return True
示例#5
0
    def stop_skillshot_motion(self):

        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))

        self.cubeRotation.pause()
        self.cubeMovement.pause()
        self.awardMovement.pause()
        base.taskMgr.remove('award_advance')
        self.cube.hide()
        self._awardText.hide()
        self.explosion.setPos(self.cube.getX() - 0.50, 40, self.cube.getZ())
        self.explosion.fps = 24
        self.explosion.play(loops=1)
        # -0.3550 is the threshold
        if self.cube.getZ() <= self.SKILLSHOT_THRESHOLD:

            base.screenManager.showModalMessage(
                message=self.awards[self.current_award],
                time=5.0,
                font="eurostile.ttf",
                scale=0.08,
                bg=(0, 0, 0, 1),
                fg=(0, 1, 1, 1),
                frame_color=(0, 1, 1, 1),
                blink_speed=0.015,
                blink_color=(0, 0, 0, 1),
                #l r t b
                frame_margin=(0.1, 0.25, 0, 0),
                animation='slide',
                start_location=(1.7, 0, 0.8),
                end_location=(1, 0, 0.8))
示例#6
0
 def explode_cube(self, stack):
     explosion = Sprite(
         parent=self.node,
         file_name="assets/sprites/blue_explosion/blue_explosion_",
         file_type="png",
         num_frames=13,
         int_padding=2,
         scale=(2, 2, 2),
         fps=25)
     explosion.setPos(self.stackpos[stack], 14, -1)
     explosion.play(loops=1)
示例#7
0
class MatchScreen(GameScreen):

    bonus_items = []
    anim_sequence = None

    def __init__(self, screen_manager):
        super(MatchScreen, self).__init__(screen_manager, "bonus_screen")

        self.anim_sequence = Sequence()
        #(-0.9812,0.70500)
        title = OnscreenText("Match",
                             1,
                             font=base.fontLoader.load('motorwerk.ttf'),
                             pos=(-1.2, 0.70),
                             fg=(1, 0, 0, 1),
                             align=TextNode.ALeft,
                             scale=.25,
                             mayChange=False,
                             parent=self.node2d)
        self.digits = OnscreenText("",
                                   1,
                                   font=base.fontLoader.load('motorwerk.ttf'),
                                   pos=(-1.2, 0.5),
                                   fg=(1, 0, 0, 1),
                                   align=TextNode.ALeft,
                                   scale=.15,
                                   mayChange=True,
                                   parent=self.node2d)

        self.match = OnscreenText("",
                                  1,
                                  font=base.fontLoader.load('motorwerk.ttf'),
                                  pos=(0.65, -0.8),
                                  fg=(1, 1, 1, 1),
                                  align=TextNode.ALeft,
                                  scale=.15,
                                  mayChange=True,
                                  parent=self.node2d)

        self.drop_idx = 0
        self.imgs = []

    def set_digits(self, digits):
        print "SET DIGITS " + str(digits)
        dtext = ""
        for d in digits:
            print "DIGITS " + str(d)
            dtext += str(d) + "\n"

        print "DTEXT " + dtext

        self.digits.setText(dtext)

        self.digits.show()

        #self.anim_sequence.append(LerpFunc(self.fade_text_in, fromData=0, toData=1.0, duration=0.4, blendType='easeIn', extraArgs=[name_text,(1,0,0,1)]))

    def fade_text_in(self, t, name_text, name_text_color):
        try:
            name_text.setFg((name_text_color[0], name_text_color[1],
                             name_text_color[2], t))
        except:
            pass

    def start_animation(self):
        #self.anim_sequence.start()
        pass

    def show(self):
        super(MatchScreen, self).show()
        self.start_animation()
        self.drop_idx = 0
        self.match.setText("")
        for img in self.imgs:
            img.destroy()

        self.imgs = []

    def hide(self):
        super(MatchScreen, self).hide()
        for img in self.imgs:
            img.destroy()

        self.imgs = []

    def drop(self):
        print "DROP IDX " + str(self.drop_idx)
        p = (-0.7 + (self.drop_idx * 0.3), 0, 1.4)
        p_end = (p[0], p[1], -1.5)
        img = OnscreenImage(image='assets/images/icecube.png',
                            pos=p,
                            parent=self.node2d,
                            scale=(0.1, 1, 0.1))
        self.imgs.append(img)

        LerpPosInterval(img, 0.7, pos=p_end, blendType='easeIn').start()

        self.drop_idx += 1

    def explode(self):
        print "EXPLODE"
        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))
        self.explosion.fps = 24
        self.explosion.setPos(8, 40, -2)
        self.explosion.play(loops=1)
        base.taskMgr.doMethodLater(0.5, self.showMatchNumber, 'match_show')

    def showMatchNumber(self, task):
        random_match = random.randint(0, 9)
        if random_match < 10:
            r = str(random_match) + "0"
        else:
            r = str(random_match)
        self.match.setText(r)
        return Task.done
示例#8
0
class SanAngelesScreen(GameScreen):
    def __init__(self, screen_manager):
        super(SanAngelesScreen, self).__init__(screen_manager, "wtsa_screen")

        self.stack_screen = self.screen_manager.getScreen("stack")

        self.instructions = OnscreenImage(image='assets/images/wtsa.png',
                                          pos=(0, 0, 0),
                                          parent=self.node2d,
                                          scale=(0.8, 0.8, 0.8))
        self.instructions.setTransparency(TransparencyAttrib.MAlpha)

    def show_instructions(self):
        self.instructions.show()

    def hide_instructions(self):
        self.instructions.hide()

    def show(self):

        # Call our base class show method now so it can render anything it wants
        super(SanAngelesScreen, self).show()

    def hide(self):
        """
        Called when the screen manager wants to remove this screen from the display.
        
        We have no choice but to obey when this method is called. So hide our background.
        
        Our models will be hidden automatically as the 3d nodes are removed from the render tree
        """
        super(SanAngelesScreen, self).hide()

    def mode_started(self):
        self.clear_stacks()
        self.stack_screen.place_model(model_name="burger.bam",
                                      scale=(0.4, 0.4, 0.4),
                                      pos="right_ramp",
                                      rotate=True,
                                      rotspeed=4,
                                      mode="wtsa")

        self.stack_screen.place_model(model_name="scanner.egg",
                                      scale=(0.6, 0.6, 0.6),
                                      pos="left_ramp",
                                      rotate=True,
                                      rotspeed=4,
                                      mode="wtsa")

        self.stack_screen.place_model(model_name="shell.bam",
                                      scale=(0.4, 0.4, 0.4),
                                      pos="left_ramp",
                                      rotate=True,
                                      rotspeed=3,
                                      mode="wtsa")

        self.stack_screen.place_model(model_name="bonus_x.bam",
                                      scale=(0.7, 0.7, 0.7),
                                      pos="right_ramp",
                                      rotate=True,
                                      rotspeed=3,
                                      mode="wtsa")

        self.stack_screen.place_model(model_name="burger.bam",
                                      scale=(0.4, 0.4, 0.4),
                                      pos="center_ramp",
                                      rotate=True,
                                      rotspeed=2,
                                      p=10,
                                      mode="wtsa")

        self.screen_manager.showScreen("stack")

    def explode(self, position):
        self.explosion = Sprite(self.node,
                                "assets/sprites/explosion/explosion_",
                                "png",
                                29,
                                2,
                                scale=(1, 1, 1),
                                fps=50)
        self.explosion.setPos(position[0], position[1] - 112, position[2] + 28)
        self.explosion.play()

    def explode_right(self):
        if not self.stack_screen.location_has_object("right_ramp",
                                                     mode="wtsa"):
            return False

        self.explosion = Sprite(self.node,
                                "assets/sprites/explosion/explosion_",
                                "png",
                                29,
                                2,
                                scale=(1, 1, 1),
                                fps=50)
        self.explosion.setPos(2.8, 10, 8.2)
        self.explosion.play()
        self.stack_screen.remove_bottom_model("right_ramp")
        return True

    def explode_left(self):
        if not self.stack_screen.location_has_object("left_ramp", mode="wtsa"):
            return False

        self.explosion = Sprite(self.node,
                                "assets/sprites/explosion/explosion_",
                                "png",
                                29,
                                2,
                                scale=(1, 1, 1),
                                fps=50)
        self.explosion.setPos(-1.3, 10, 6.9)
        self.explosion.play()
        self.stack_screen.remove_bottom_model("left_ramp")
        return True

    def explode_center(self):
        if not self.stack_screen.location_has_object("center_ramp",
                                                     mode="wtsa"):
            return False

        self.explosion = Sprite(self.node,
                                "assets/sprites/explosion/explosion_",
                                "png",
                                29,
                                2,
                                scale=(1, 1, 1),
                                fps=50)
        self.explosion.setPos(0.1, 8, 8.5)
        self.explosion.play()
        self.stack_screen.remove_bottom_model("center_ramp")

    def generate_new_barrel(self):
        self.stack_screen.place_model(model_name="barrel.bam",
                                      scale=(0.2, 0.2, 0.2),
                                      pos="center_ramp",
                                      rotate=True,
                                      rotspeed=2,
                                      p=10,
                                      mode="wtsa")

    def get_last_removed_model(self, location):
        return self.stack_screen.last_removed_model[location]

    def clear_last_removed_model(self, location):
        self.stack_screen.last_removed_model[location] = ""
示例#9
0
    def __init__(self, screen_manager):
        super(SkillShotScreen, self).__init__(screen_manager,
                                              "skillshot_screen")

        # Load our trunk model
        self.cube = base.loader.loadModel("assets/models/powerup.egg")
        # Set its position to:
        # X: -0.4 (just to the left of h-center)
        # Y: 40 (way far back away from the viewer)
        # Z: 0 (vertically center)
        self.cube.setPos(11, 40, 0)
        # Set the scaling size of the trunk
        self.cube.setScale(0.05, 0.05, 0.05)

        if base.displayFlipped:
            self.cube.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))

        # Insert the trunk into this screen's rendering tree
        self.cube.reparentTo(self.node)
        """
        # Set up a splotlight to project onto the trunk
        self.dlight = Spotlight('my dlight')
        # Associate the spotlight to the rendering system
        self.dlnp = render.attachNewNode(self.dlight)
        # Set this trunk's light explicitly so it only takes light from this light
        self.cube.setLight(self.dlnp)
        self.dlnp.lookAt(self.cube)
        
        plight = PointLight('plight')
        plight.setColor(VBase4(1, 1, 1, 1))
        self.plnp = render.attachNewNode(plight)
        self.plnp.setPos(11, 35, 12)
        """

        self.dlight = DirectionalLight('dlight')
        self.dlight.setColor(VBase4(1, 1, 1, 1))
        self.dlnp = render.attachNewNode(self.dlight)
        self.dlnp.setHpr(0, -60, 0)
        self.dlnp.lookAt(self.cube)

        self.obj = DirectObject()

        self.movement_speed = 0.7
        """
        self.explosion = Sprite(
                                parent=self.node, 
                                file_name="assets/sprites/explosion/explosion_", 
                                file_type="png", 
                                num_frames=29, 
                                int_padding=2,
                                scale=(5,5,5))
        """

        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))
        #0.6 - high
        #-0.4 - low
        self._awardText = OnscreenText(
            "RANDOM AWARD",
            1,
            font=base.fontLoader.load('digital.ttf'),
            fg=((0.0 / 255.0), (255.0 / 255.0), (255.0 / 255.0), 1),
            pos=(1, -0.4),
            align=TextNode.ACenter,
            scale=.1,
            mayChange=True,
            parent=self.node2d)

        self.cubeRotation = self.cube.hprInterval(1.2, Vec3(360, 0, 0))
        # Set up a sequence to perform the animation in, pause and out... "sequentially"
        self.cubeMovement = Sequence(
            # Lerp stands for "linearly interpolate", so we move from one position to the other with
            # an 'easeOut' blend so it comes to a nice slow stop at the end instead of an abrupt finish
            LerpPosInterval(self.cube,
                            self.movement_speed,
                            pos=(13, 40, 11),
                            startPos=(13, 40, 0),
                            blendType='easeOut'),
            # Animate back to our home position (off screen) with an ease in so it starts moving gradually
            LerpPosInterval(self.cube,
                            self.movement_speed,
                            pos=(13, 40, 0),
                            blendType='easeIn'))
        self.awardMovement = Sequence(
            LerpFunc(self._updateAwardTextPosition,
                     fromData=-0.4,
                     toData=0.6,
                     duration=self.movement_speed,
                     blendType='easeOut',
                     extraArgs=[],
                     name=None),
            LerpFunc(self._updateAwardTextPosition,
                     fromData=0.6,
                     toData=-0.4,
                     duration=self.movement_speed,
                     blendType='easeIn',
                     extraArgs=[],
                     name=None))
示例#10
0
class SkillShotScreen(GameScreen):

    awards = [
        "QUICK FREEZE", "ADVANCE BONUS X", "5000 POINTS", "SPOT MTL",
        "QUICK FREEZE", "500,000 POINTS", "LIGHT CLAW"
    ]

    current_side = 1
    current_award = 0
    cube = None
    _awardText = None
    cubeMovement = None
    cubeRotation = None
    awardMovement = None
    SKILLSHOT_THRESHOLD = 2.34726002216

    def __init__(self, screen_manager):
        super(SkillShotScreen, self).__init__(screen_manager,
                                              "skillshot_screen")

        # Load our trunk model
        self.cube = base.loader.loadModel("assets/models/powerup.egg")
        # Set its position to:
        # X: -0.4 (just to the left of h-center)
        # Y: 40 (way far back away from the viewer)
        # Z: 0 (vertically center)
        self.cube.setPos(11, 40, 0)
        # Set the scaling size of the trunk
        self.cube.setScale(0.05, 0.05, 0.05)

        if base.displayFlipped:
            self.cube.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))

        # Insert the trunk into this screen's rendering tree
        self.cube.reparentTo(self.node)
        """
        # Set up a splotlight to project onto the trunk
        self.dlight = Spotlight('my dlight')
        # Associate the spotlight to the rendering system
        self.dlnp = render.attachNewNode(self.dlight)
        # Set this trunk's light explicitly so it only takes light from this light
        self.cube.setLight(self.dlnp)
        self.dlnp.lookAt(self.cube)
        
        plight = PointLight('plight')
        plight.setColor(VBase4(1, 1, 1, 1))
        self.plnp = render.attachNewNode(plight)
        self.plnp.setPos(11, 35, 12)
        """

        self.dlight = DirectionalLight('dlight')
        self.dlight.setColor(VBase4(1, 1, 1, 1))
        self.dlnp = render.attachNewNode(self.dlight)
        self.dlnp.setHpr(0, -60, 0)
        self.dlnp.lookAt(self.cube)

        self.obj = DirectObject()

        self.movement_speed = 0.7
        """
        self.explosion = Sprite(
                                parent=self.node, 
                                file_name="assets/sprites/explosion/explosion_", 
                                file_type="png", 
                                num_frames=29, 
                                int_padding=2,
                                scale=(5,5,5))
        """

        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))
        #0.6 - high
        #-0.4 - low
        self._awardText = OnscreenText(
            "RANDOM AWARD",
            1,
            font=base.fontLoader.load('digital.ttf'),
            fg=((0.0 / 255.0), (255.0 / 255.0), (255.0 / 255.0), 1),
            pos=(1, -0.4),
            align=TextNode.ACenter,
            scale=.1,
            mayChange=True,
            parent=self.node2d)

        self.cubeRotation = self.cube.hprInterval(1.2, Vec3(360, 0, 0))
        # Set up a sequence to perform the animation in, pause and out... "sequentially"
        self.cubeMovement = Sequence(
            # Lerp stands for "linearly interpolate", so we move from one position to the other with
            # an 'easeOut' blend so it comes to a nice slow stop at the end instead of an abrupt finish
            LerpPosInterval(self.cube,
                            self.movement_speed,
                            pos=(13, 40, 11),
                            startPos=(13, 40, 0),
                            blendType='easeOut'),
            # Animate back to our home position (off screen) with an ease in so it starts moving gradually
            LerpPosInterval(self.cube,
                            self.movement_speed,
                            pos=(13, 40, 0),
                            blendType='easeIn'))
        self.awardMovement = Sequence(
            LerpFunc(self._updateAwardTextPosition,
                     fromData=-0.4,
                     toData=0.6,
                     duration=self.movement_speed,
                     blendType='easeOut',
                     extraArgs=[],
                     name=None),
            LerpFunc(self._updateAwardTextPosition,
                     fromData=0.6,
                     toData=-0.4,
                     duration=self.movement_speed,
                     blendType='easeIn',
                     extraArgs=[],
                     name=None))

    def _updateAwardTextPosition(self, t):
        self._awardText.setPos(1, t)

    def show(self):
        """
        Overridden method that is invoked when the screen is shown.
        
        We use this to orient our camera and spotlights to the appropriate place. We do this because
        not every screen has its own camera. I suppose we could do that in the future the same way that
        each screen has its own 2d and 3d nodes.
        """

        # Set the camera a bit up in the air (vertically, not moving forward. Just straight up)
        base.camera.setZ(9.6)
        # Set the pitch negatively a bit so we can look down upon the trunk
        base.camera.setP(-5)

        # Call our base class show method now so it can render anything it wants
        super(SkillShotScreen, self).show()

        # Fire off the sequence
        self.cubeMovement.loop()
        self.cubeRotation.loop()
        self.awardMovement.loop()
        base.taskMgr.doMethodLater(0.1, self._advanceAward, 'award_advance')

        self.cube.setLight(self.dlnp)
        random.shuffle(self.awards)
        self.obj.ignoreAll()
        self.obj.acceptOnce("skillshot_hit", self.stop_skillshot_motion)
        self.cube.show()
        self._awardText.show()

    def stop_skillshot_motion(self):

        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))

        self.cubeRotation.pause()
        self.cubeMovement.pause()
        self.awardMovement.pause()
        base.taskMgr.remove('award_advance')
        self.cube.hide()
        self._awardText.hide()
        self.explosion.setPos(self.cube.getX() - 0.50, 40, self.cube.getZ())
        self.explosion.fps = 24
        self.explosion.play(loops=1)
        # -0.3550 is the threshold
        if self.cube.getZ() <= self.SKILLSHOT_THRESHOLD:

            base.screenManager.showModalMessage(
                message=self.awards[self.current_award],
                time=5.0,
                font="eurostile.ttf",
                scale=0.08,
                bg=(0, 0, 0, 1),
                fg=(0, 1, 1, 1),
                frame_color=(0, 1, 1, 1),
                blink_speed=0.015,
                blink_color=(0, 0, 0, 1),
                #l r t b
                frame_margin=(0.1, 0.25, 0, 0),
                animation='slide',
                start_location=(1.7, 0, 0.8),
                end_location=(1, 0, 0.8))

    def is_skillshot_hit(self):
        if self.cube.getZ() <= self.SKILLSHOT_THRESHOLD:
            return self.awards[self.current_award]
        else:
            return False

    def _advanceAward(self, task):
        self.current_award = (self.current_award + 1) % len(self.awards)
        self._awardText.setText(self.awards[self.current_award])
        return task.again

    def hide(self):
        """
        Called when the screen manager wants to remove this screen from the display.
        
        We have no choice but to obey when this method is called. So hide our background.
        
        Our models will be hidden automatically as the 3d nodes are removed from the render tree
        """
        super(SkillShotScreen, self).hide()

        if self.cube != None: self.cube.clearLight(self.dlnp)
        if self.cubeMovement: self.cubeMovement.finish()
        if self.cubeRotation: self.cubeRotation.finish()
        if self.awardMovement: self.awardMovement.finish()
        base.taskMgr.remove('award_advance')
        if self._awardText != None: self._awardText.hide()
示例#11
0
    def __init__(self, screen_manager):
        '''
        Constructor
        '''
        super(BlocksScreen, self).__init__(screen_manager, "blocks_screen")

        self.cubes = []
        self.stackpos = (-1.5, 0, 2)

        dlight = DirectionalLight('my dlight')
        self.dlnp = render.attachNewNode(dlight)

        self.fill_stack(0)
        self.fill_stack(1)
        self.fill_stack(2)

        arc = base.loader.loadModel("assets/models/arc.bam")
        arc.setPos(-1.1, 6, -1.5)
        arc.setScale(0.1, 0.1, 0.1)
        arc.setH(120)
        arc.reparentTo(self.node)
        arc.setLight(self.dlnp)

        self.wizard = base.loader.loadModel("assets/models/wizard.bam")
        self.wizard.setPos(-1.9, 6, 0)
        self.wizard.setScale(0.015, 0.015, 0.015)
        self.wizard.setH(20)
        self.wizard.reparentTo(self.node)
        self.wizard.setLight(self.dlnp)

        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))

        self.sparkle = Sprite(
            parent=self.node,
            file_name="assets/sprites/purple_sparkle/purple_sparkle_",
            file_type="png",
            num_frames=17,
            int_padding=2,
            fps=25,
            scale=(1.2, 1.2, 1.2))

        self.wizard_w = OnscreenImage(
            parent=self.node2d,  # Parented to our 2d node renderer
            image="assets/images/wizard_w.png",  # File name specified
            pos=(-0.5, 0, 0.4),  # z: -2 is off screen at the bottom
            scale=(0.4, 1, 0.25)
        )  # Scale it down a bit horizontally and vertically to make it look right

        self.wizard_wi = OnscreenImage(
            parent=self.node2d,  # Parented to our 2d node renderer
            image="assets/images/wizard_wi.png",  # File name specified
            pos=(-0.5, 0, 0.4),  # z: -2 is off screen at the bottom
            scale=(0.4, 1, 0.25)
        )  # Scale it down a bit horizontally and vertically to make it look right

        self.wizard_w.setTransparency(TransparencyAttrib.MAlpha)
        self.wizard_wi.setTransparency(TransparencyAttrib.MAlpha)

        self.wizard_wi.hide()
        self.wizard_w.hide()

        if base.displayFlipped:
            self.wizard.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
            arc.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
示例#12
0
class BlocksScreen(GameScreen):
    '''
    ROW COMBINATIONS
    
    
    1 -*-*-*-
       * * *
       * * *
       
    2  * * *
       - - -
       * * *
    
    3  * * *
       * * *
       - - -
       
    4  - * *
       * - *
       * * -
    
    5  * * -
       * - *
       - * *
       
    6  | * *
       | * *
       | * *
       
    7  * | *
       * | *
       * | *
       
    8  * * |
       * * |
       * * |
    
    
    '''
    def __init__(self, screen_manager):
        '''
        Constructor
        '''
        super(BlocksScreen, self).__init__(screen_manager, "blocks_screen")

        self.cubes = []
        self.stackpos = (-1.5, 0, 2)

        dlight = DirectionalLight('my dlight')
        self.dlnp = render.attachNewNode(dlight)

        self.fill_stack(0)
        self.fill_stack(1)
        self.fill_stack(2)

        arc = base.loader.loadModel("assets/models/arc.bam")
        arc.setPos(-1.1, 6, -1.5)
        arc.setScale(0.1, 0.1, 0.1)
        arc.setH(120)
        arc.reparentTo(self.node)
        arc.setLight(self.dlnp)

        self.wizard = base.loader.loadModel("assets/models/wizard.bam")
        self.wizard.setPos(-1.9, 6, 0)
        self.wizard.setScale(0.015, 0.015, 0.015)
        self.wizard.setH(20)
        self.wizard.reparentTo(self.node)
        self.wizard.setLight(self.dlnp)

        self.explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(5, 5, 5))

        self.sparkle = Sprite(
            parent=self.node,
            file_name="assets/sprites/purple_sparkle/purple_sparkle_",
            file_type="png",
            num_frames=17,
            int_padding=2,
            fps=25,
            scale=(1.2, 1.2, 1.2))

        self.wizard_w = OnscreenImage(
            parent=self.node2d,  # Parented to our 2d node renderer
            image="assets/images/wizard_w.png",  # File name specified
            pos=(-0.5, 0, 0.4),  # z: -2 is off screen at the bottom
            scale=(0.4, 1, 0.25)
        )  # Scale it down a bit horizontally and vertically to make it look right

        self.wizard_wi = OnscreenImage(
            parent=self.node2d,  # Parented to our 2d node renderer
            image="assets/images/wizard_wi.png",  # File name specified
            pos=(-0.5, 0, 0.4),  # z: -2 is off screen at the bottom
            scale=(0.4, 1, 0.25)
        )  # Scale it down a bit horizontally and vertically to make it look right

        self.wizard_w.setTransparency(TransparencyAttrib.MAlpha)
        self.wizard_wi.setTransparency(TransparencyAttrib.MAlpha)

        self.wizard_wi.hide()
        self.wizard_w.hide()

        if base.displayFlipped:
            self.wizard.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))
            arc.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))

    def show(self):
        super(BlocksScreen, self).show()
        self.sparkle.setPos(-3.6, 20, -4.1)
        self.sparkle.play(loops=-1)

    def fill_stack(self, stack=1):
        colors = ("block_blue.bam", "block_red.bam", "purple.bam",
                  "powerup.egg")
        for i in range(3):

            color = random.choice(colors)
            cube = base.loader.loadModel("assets/models/" + color)
            zpos = i * (0.8)
            zpos = zpos - 1
            cube.setPos(self.stackpos[stack], 15, zpos)
            cube.setScale(0.02, 0.02, 0.02)
            #cube.stack = stack
            #cube.slot = i

            cubeEntry = {}
            cubeEntry['stack'] = stack
            cubeEntry['slot'] = i + 1
            cubeEntry['model'] = cube

            if color == "block_blue.bam":
                cubeEntry['color'] = "blue"
            elif color == "block_red.bam":
                cubeEntry['color'] = "red"
            elif color == "purple.bam":
                cubeEntry['color'] = "purple"
            else:
                cubeEntry['color'] = "bright_blue"

            #myInterval4 = cube.hprInterval( 1, Vec3(360,-10,0) ).loop()

            cube.setP(10)
            cube.setH(10)

            cube.reparentTo(self.node)

            self.cubes.append(cubeEntry)

            cube.setLight(self.dlnp)

            if base.displayFlipped:
                cube.setAttrib(
                    CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))

    def get_cube_color(self, stack, slot):
        for cube in self.cubes:
            if cube['stack'] == stack and cube['slot'] == slot:
                return cube['color']

        return None

    def get_cube_model(self, stack, slot):
        for cube in self.cubes:
            if cube['stack'] == stack and cube['slot'] == slot:
                return cube['model']

        return None

    def explode_cube(self, stack):
        explosion = Sprite(
            parent=self.node,
            file_name="assets/sprites/blue_explosion/blue_explosion_",
            file_type="png",
            num_frames=13,
            int_padding=2,
            scale=(2, 2, 2),
            fps=25)
        explosion.setPos(self.stackpos[stack], 14, -1)
        explosion.play(loops=1)

    def remove_cube(self, stack, slot=1):
        cubeToRemove = None
        for cube in self.cubes:
            if cube['stack'] == stack and cube['slot'] == slot:
                cubeToRemove = cube
                break

        if cubeToRemove != None:
            cubeToRemove['model'].removeNode()
            self.cubes.remove(cubeToRemove)

    def add_cube(self, stack):
        colors = ("block_blue.bam", "block_red.bam", "purple.bam",
                  "powerup.egg")

        color = random.choice(colors)
        cube = base.loader.loadModel("assets/models/" + color)
        zpos = 2 * (0.8)
        zpos = zpos - 1
        cube.setPos(self.stackpos[stack], 15, 2)
        cube.setScale(0.02, 0.02, 0.02)
        #cube.stack = stack
        #cube.slot = i

        cubeEntry = {}
        cubeEntry['stack'] = stack
        cubeEntry['slot'] = 3
        cubeEntry['model'] = cube

        if color == "block_blue.bam":
            cubeEntry['color'] = "blue"
        elif color == "block_red.bam":
            cubeEntry['color'] = "red"
        elif color == "purple.bam":
            cubeEntry['color'] = "purple"
        else:
            cubeEntry['color'] = "bright_blue"

        #myInterval4 = cube.hprInterval( 1, Vec3(360,-10,0) ).loop()

        cube.setP(10)
        cube.setH(10)

        cube.reparentTo(self.node)

        self.cubes.append(cubeEntry)

        cube.setLight(self.dlnp)

        if base.displayFlipped:
            cube.setAttrib(
                CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise))

        LerpPosInterval(cube,
                        duration=0.6,
                        pos=(self.stackpos[stack], 15, zpos),
                        blendType='easeIn').start()

    def move_cubes_down(self, stack):
        for cube in self.cubes:
            if cube['stack'] == stack and cube['slot'] != 1:

                cube['slot'] -= 1

                zpos = (cube['slot'] - 1) * (0.8)
                zpos = zpos - 1
                #cube['model'].setPos(self.stackpos[stack],15,zpos)
                LerpPosInterval(cube['model'],
                                duration=0.6,
                                pos=(self.stackpos[stack], 15, zpos),
                                blendType='easeIn').start()

    def toggle_blink_section(self, section):
        if section == 1:
            for stack in range(3):
                cube3 = self.get_cube_model(3, stack)
                cube2 = self.get_cube_model(2, stack)
                cube1 = self.get_cube_model(1, stack)

                if cube3.isHidden():
                    cube1.show()
                    cube2.show()
                    cube3.show()
                else:
                    cube1.hide()
                    cube2.hide()
                    cube3.hide()

    def turn_wizard(self, degree=20):
        self.wizard.hprInterval(1, Vec3(degree, 0, 0)).start()

    def hide_wizard_text(self):
        self.wizard_w.hide()
        self.wizard_wi.hide()

    def toggle_wi(self, toggle):
        self.wizard_w.show()
        if toggle:
            self.wizard_wi.hide()
        else:
            self.wizard_wi.show()