Exemple #1
0
class Game:
    """Game Instance, contains the menus, world, etc."""
    def __init__(self, game):
        self.state = None
        self.world = None
        ##self.cfont = loader.loadFont('Coalition_v2.ttf')
        self.add_menu()
        

        
    def start_game(self):
        self.remove_menu()
        self.world = game.World()
    
    def exit_game(self):
        self.remove_menu()
        sys.exit()
        
    def add_menu(self):
        self.bg = OnscreenImage(image = "textures/Title_Screen_Final.png", pos=(0,0,0), scale=(1.35,1,1))
        self.start_button = DirectButton(text = "START", scale = .12, text_fg = ((0,0,0,1)), command = self.start_game, pos=(0, 0, 0.4))
        self.exit_button = DirectButton(text = ("EXIT"), scale = 0.12, command = self.exit_game, pos=(0, 0, 0))
        self.bar = DirectWaitBar(text = "", value = 0, range = 10000, pos = (0,-.9,-.9), relief = DGG.SUNKEN, borderWidth = (.01,.01), barColor = (0,180,0,1))
        self.bar.setSz(0.5)
            
    def remove_menu(self):
        if self.start_button:
            self.bar.finish(9000) 
            self.start_button.removeNode()
        if self.bar:
            self.bar.removeNode()
        if self.bg:
            self.bg.removeNode()
        if self.exit_button:
            self.exit_button.removeNode()
class Shockley:
    def __init__(self, preload=False):
        self.sceneRoot = None
        self.preload = preload

    def load(self):
        self.sceneRoot = NodePath('Shockley')
        base.setBackgroundColor(0, 0, 0, 1)

        self.title = OnscreenText(text='Shockley ', pos=(0.6, 0.15, 0.0), scale=(0.15), fg=(1, 1, 1, 1), font=ToontownGlobals.getSignFont(), align=TextNode.ACenter)
        self.description = OnscreenText(text='Lead Developer\nNetwork Technician\nGame Systems Engineer', pos=(0.25, 0.05, 0.0), scale=(0.06), fg=(1, 1, 1, 1), font=ToontownGlobals.getMinnieFont(), align=TextNode.ALeft)
        self.image = OnscreenImage(image='phase_4/maps/news/11-17-13_garden.jpg', pos=(-0.5, 0.0, 0.0), scale=(0.5, 0.30, 0.30))

        self.elements = [self.title, self.description, self.image]
        for node in self.elements:
            node.setTransparency(1)
            if self.preload:
                node.setColorScale(1, 1, 1, 0)

    def makeInterval(self):
        return Sequence(
            ParentInterval(self.sceneRoot, render),
            # This fades in during the election's WrapUp state to prevent jittering when loading this first scene.
            Wait(3),
            Func(doFade, 'out', self.elements),
            Wait(0.5),
            ParentInterval(self.sceneRoot, hidden)
            )

    def unload(self):
        self.sceneRoot.removeNode()
        self.title.removeNode()
        self.description.removeNode()
        self.image.removeNode()
Exemple #3
0
class ButtonViewer:
    def __init__(self, bpm, z_pos = -0.7):
        self.BTN_SPACE_PER_BEAT = 0.2
        self.BTN_SIZE = 64.0
        self.BTN_SIZE = 64.0
        self.BTN_SCALE = (self.BTN_SIZE/base.win.getXSize(), 1 ,self.BTN_SIZE/base.win.getYSize())
        
        self.z_pos = z_pos
        self.delay_per_beat = beat_delay(bpm)
        
        self.tex_buttons = {}
        for b, i in zip(["A", "B", "C", "D"],["down", "right", "left", "up"]):
            self.tex_buttons[b] = loader.loadTexture("image/wii_%s.png" % i)
    
        #~ else:
            #~ for b, i in zip(["A", "B", "C", "D"],["cross", "circle", "square", "triangle"]):
                #~ self.tex_buttons[b] = loader.loadTexture("image/b_%s.png" % i)
        
        ## Button marker
        self.button_marker = OnscreenImage(image="image/b_marker.png",pos=(0, 2, self.z_pos), scale=self.BTN_SCALE, parent=render2d)
        self.button_marker.setTransparency(TransparencyAttrib.MAlpha)
        
        self.button_node = render2d.attachNewNode("Button Root Node")
        self.initial_x = self.button_node.getX()
        
        self.next_button = 0
        
    def append_button(self, button, beat):
        btn_image = OnscreenImage(image=self.tex_buttons[button], pos=(-beat*self.BTN_SPACE_PER_BEAT, 0, self.z_pos), scale=self.BTN_SCALE, parent=render2d)
        btn_image.setTransparency(TransparencyAttrib.MAlpha)        
        btn_image.reparentTo(self.button_node)
    
    def update(self, time):
        self.button_node.setX(self.initial_x + time2pos(time, self.delay_per_beat, self.BTN_SPACE_PER_BEAT))
        
    def button_hit(self):
        pass
        #~ button = self.button_node.getChild(self.next_button)
        #~ button.setAlphaScale(.0)
        
        #~ self.next_button += 1
        #~ button = self.button_node.getChild(self.next_button )
        #~ pos = render2d.getRelativePoint(self.button_node, button.getPos())
    
        #~ button.reparentTo(render2d)
        #~ button.setPos(pos)
        
        #~ LerpFunc(button.setAlphaScale, duration=0.2, fromData=1, toData=0, blendType='easeOut').start()
        
    def button_miss(self):
        pass
        #self.next_button += 1
        
    def __del__(self):
        self.button_node.removeNode()
        self.button_marker.removeNode()
Exemple #4
0
class Shockley:
    def __init__(self, preload=False):
        self.sceneRoot = None
        self.preload = preload

    def load(self):
        self.sceneRoot = NodePath('Shockley')
        base.setBackgroundColor(0, 0, 0, 1)

        self.title = OnscreenText(text='Shockley ',
                                  pos=(0.6, 0.15, 0.0),
                                  scale=(0.15),
                                  fg=(1, 1, 1, 1),
                                  font=ToontownGlobals.getSignFont(),
                                  align=TextNode.ACenter)
        self.description = OnscreenText(
            text='Lead Developer\nNetwork Technician\nGame Systems Engineer',
            pos=(0.25, 0.05, 0.0),
            scale=(0.06),
            fg=(1, 1, 1, 1),
            font=ToontownGlobals.getMinnieFont(),
            align=TextNode.ALeft)
        self.image = OnscreenImage(
            image='phase_4/maps/news/11-17-13_garden.jpg',
            pos=(-0.5, 0.0, 0.0),
            scale=(0.5, 0.30, 0.30))

        self.elements = [self.title, self.description, self.image]
        for node in self.elements:
            node.setTransparency(1)
            if self.preload:
                node.setColorScale(1, 1, 1, 0)

    def makeInterval(self):
        return Sequence(
            ParentInterval(self.sceneRoot, render),
            # This fades in during the election's WrapUp state to prevent jittering when loading this first scene.
            Wait(3),
            Func(doFade, 'out', self.elements),
            Wait(0.5),
            ParentInterval(self.sceneRoot, hidden))

    def unload(self):
        self.sceneRoot.removeNode()
        self.title.removeNode()
        self.description.removeNode()
        self.image.removeNode()
Exemple #5
0
class HUDBottomRight(DirectObject):
    
    def __init__(self):
        self.node = base.a2dBottomRight.attachNewNode('hudBottomRight')#GUIOrder.ORDER[GUIOrder.HUD])
        self.node.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.ammoIcon = OnscreenImage(image = 'Assets/Images/HUD/HUDBottomRight.png', scale = 512.0 / 1024, pos = (-0.5, 0, 0.5))
        self.ammoIcon.setTransparency(TransparencyAttrib.MAlpha)
        self.ammoIcon.reparentTo(self.node)
        
        self.ammoTextClip = OnscreenText(text = '30', pos = (-0.35, 0.09), scale = 0.12, fg = (1, 1, 1, 1), shadow = (0, 0, 0, 1), mayChange = True, align=TextNode.ARight, font = Globals.FONT_SAF)
        self.ammoTextClip.reparentTo(self.node)
        self.ammoTextClip.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.ammoTextLeft = OnscreenText(text = '90', pos = (-0.23, 0.05), scale = 0.07, fg = (1, 1, 1, 1), shadow = (0, 0, 0, 1), mayChange = True, align=TextNode.ARight, font = Globals.FONT_SAF)
        self.ammoTextLeft.reparentTo(self.node)
        self.ammoTextLeft.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.accept(AmmoChangeEvent.EventName, self.OnAmmoChangeEvent)
        self.accept(SelectedItemChangeEvent.EventName, self.OnSelectedItemChangeEvent)
        
    def OnAmmoChangeEvent(self, event):
        item = event.GetItem()
        if(item and item.GetCurrentClipAmmo() == ''):
            self.ChangeAmmoText('', '')
        else:
            self.ChangeAmmoText(str(item.GetCurrentClipAmmo()), str(item.GetTotalRemainingAmmo()))
            
    def ChangeAmmoText(self, clip, total):
        self.ammoTextClip.setText(clip)
        self.ammoTextLeft.setText(total)
        
    def OnSelectedItemChangeEvent(self, event):
        if(event.GetItemStack() and event.GetItemStack().GetItem()):
            self.OnAmmoChangeEvent(AmmoChangeEvent(None, event.GetItemStack().GetItem()))
        else:
            self.ChangeAmmoText('', '')
        
    def Destroy(self):
        self.ignoreAll()
        self.ammoIcon.removeNode()
        self.ammoTextClip.removeNode()
        self.ammoTextLeft.removeNode()
        self.node.removeNode()
Exemple #6
0
class HitMarker(DirectObject):
    
    def __init__(self):
        self.node = aspect2d.attachNewNode('hitmarker')#GUIOrder.ORDER[GUIOrder.HUD])
        self.node.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.indicator = OnscreenImage(image = 'Assets/Images/HUD/HitMarker.png', scale = 64.0 / 1024)
        self.indicator.setTransparency(TransparencyAttrib.MAlpha)
        self.indicator.reparentTo(self.node)
        
        self.alphaSeq = Sequence(Wait(0.2),
                                 LerpColorInterval(self.node, 0.2, Vec4(1, 1, 1, 0), Vec4(1, 1, 1, 1)),
                                 Func(self.Hide))
        
        self.node.hide()
        
        self.accept(PlayerHitEvent.EventName, self.OnPlayerHitEvent)
        
    def Hide(self):
        self.node.hide()
        
    def Show(self):
        self.node.show()
        self.node.setColor(Vec4(1, 1, 1, 1))
        
    def OnPlayerHitEvent(self, event):
        if(event.GetAttacker().GetPlayerState().GetValue(PlayerState.PID) == Globals.MY_PID):
            self.Show()
            self.alphaSeq.start(startT = 0)      
        
    def Destroy(self):
        self.alphaSeq.finish()
        self.ignoreAll()
        self.indicator.removeNode()
        self.node.removeNode()
        
        
        
Exemple #7
0
class HUDBottomLeft(DirectObject):
    
    def __init__(self):
        self.node = base.a2dBottomLeft.attachNewNode('hudhealth')#GUIOrder.ORDER[GUIOrder.HUD])
        self.node.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.health = OnscreenImage(image = 'Assets/Images/HUD/HUDBottomLeft.png', scale = 512.0 / 1024, pos = (0.5, 0, 0.5))
        self.health.setTransparency(TransparencyAttrib.MAlpha)
        self.health.reparentTo(self.node)
        
        self.healthText = OnscreenText(text = '100', pos = (0.2, 0.07), scale = 0.12, fg = (1, 1, 1, 1), shadow = (0, 0, 0, 1), mayChange = True, font = Globals.FONT_SAF, align=TextNode.ALeft)
        self.healthText.reparentTo(self.node)
        self.healthText.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.healthColorSeq = Sequence(LerpColorScaleInterval(self.node, 0.25, Globals.COLOR_RED),
                                       LerpColorScaleInterval(self.node, 0.25, Globals.COLOR_WHITE))
        
        self.dieingColorSeq = Sequence(LerpColorScaleInterval(self.node, 1, Globals.COLOR_RED),
                                       LerpColorScaleInterval(self.node, 1, Globals.COLOR_WHITE))
        
        self.accept(PlayerHealthEvent.EventName, self.OnPlayerHealthEvent)
        
    def OnPlayerHealthEvent(self, event):
        health = event.GetHealth()
        self.healthText.setText(str(health))
        if(health < 16):
            #self.node.setColor(Globals.COLOR_RED)
            self.dieingColorSeq.loop()
        elif(health == 100):
            self.dieingColorSeq.finish()
        else:
            self.healthColorSeq.start()        
        
    def Destroy(self):
        self.ignoreAll()
        self.health.removeNode()
        self.healthText.removeNode()
        self.node.removeNode()
class Credits:
    def __init__(self, name, description, image, side = 'left', number = 1, name2 = None, description2 = None, image2 = None, special = None):
        self.sceneRoot = None
        self.twoSlides = None
        self.toonName = name
        self.toonDescription = description
        self.toonImage = image
        self.side = side
        self.special = special # For special types of slides, like the final one
        if number > 1:
            self.toon2Name = name2
            self.toon2Description = description2
            self.toon2Image = image2
            self.twoSlides = True

    def load(self):
        self.sceneRoot = NodePath(self.toonName.replace(' ', '').replace('',''))
        base.setBackgroundColor(0, 0, 0, 1)

        if self.twoSlides:
            if self.side == 'left':
                # Left Top
                titlePos = (0.1, 0.5, 0.0)
                descriptionPos = (0.2, 0.4, 0.0)
                imagePos = (-0.55, 0.0, 0.4)
                textAlignment = TextNode.ALeft
                # Right Bottom
                title2Pos = (-0.1, -0.35, 0.0)
                description2Pos = (-0.1, -0.45, 0.0)
                image2Pos = (0.55, 0.0, -0.4)
                text2Alignment = TextNode.ARight
            else:
                # Right Top
                titlePos = (-0.1, 0.5, 0.0)
                descriptionPos = (-0.1, 0.4, 0.0)
                imagePos = (0.55, 0.0, 0.4)
                textAlignment = TextNode.ARight
                # Left Bottom
                title2Pos = (0.1, -0.35, 0.0)
                description2Pos = (0.25, -0.45, 0.0)
                image2Pos = (-0.55, 0.0, -0.4)
                text2Alignment = TextNode.ALeft
        elif self.side == 'left':
            # Left Middle
            titlePos = (0.1, 0.15, 0.0)
            descriptionPos = (0.2, 0.05, 0.0)
            imagePos = (-0.5, 0.0, 0.0)
            textAlignment = TextNode.ALeft
        else: 
            # Right Middle
            titlePos = (-0.1, 0.1, 0.0)
            descriptionPos = (-0.11, 0.0, 0.0)
            imagePos = (0.5, 0.0, 0.0)
            textAlignment = TextNode.ARight

        self.title = OnscreenText(text=self.toonName, pos=titlePos, scale=(0.15), fg=(1, 1, 1, 1), font=ToontownGlobals.getSignFont(), align=textAlignment)
        self.description = OnscreenText(text=self.toonDescription, pos=descriptionPos, scale=(0.06), fg=(1, 1, 1, 1), font=ToontownGlobals.getMinnieFont(), align=textAlignment)
        self.image = OnscreenImage(image='phase_4/maps/news/%s' % self.toonImage, pos=imagePos, scale=(0.5, 0.30, 0.30))
        self.elements = [self.title, self.description, self.image]

        if self.twoSlides:
            self.title2 = OnscreenText(text=self.toon2Name, pos=title2Pos, scale=(0.15), fg=(1, 1, 1, 1), font=ToontownGlobals.getSignFont(), align=text2Alignment)
            self.description2 = OnscreenText(text=self.toon2Description, pos=description2Pos, scale=(0.06), fg=(1, 1, 1, 1), font=ToontownGlobals.getMinnieFont(), align=text2Alignment)
            self.image2 = OnscreenImage(image='phase_4/maps/news/%s' % self.toon2Image, pos=image2Pos, scale=(0.5, 0.30, 0.30))
            self.elements.extend([self.title2, self.description2, self.image2])

        for node in self.elements:
            node.setTransparency(1)
            node.setColorScale(1, 1, 1, 0)

    def makeInterval(self):
        if self.special == 'final':
            # Hide the last slide, rather than fade out
            return Sequence(
                ParentInterval(self.sceneRoot, render),
                Func(doFade, 'in', self.elements),
                Wait(3),
                Func(doFade, 'hide', self.elements),
                ParentInterval(self.sceneRoot, hidden)
                )
        else:
            # Just a normal slide
            return Sequence(
                ParentInterval(self.sceneRoot, render),
                Func(doFade, 'in', self.elements),
                Wait(3.5),
                Func(doFade, 'out', self.elements),
                Wait(0.5),
                ParentInterval(self.sceneRoot, hidden)
                )

    def unload(self):
        self.sceneRoot.removeNode()
        self.title.removeNode()
        self.description.removeNode()
        self.image.removeNode()
        self.elements = None
        self.toonName = None
        self.toonDescription = None
        self.toonImage = None
        self.side = None
Exemple #9
0
class GUI(object):
    __selected = None
    __gameEngine = None
    __gameState = None
    __base = None
    __screenImage = None
    __titleImage = None
    __newGameImage = None
    __selectedImage = None
    __quitImage = None
    __screenImagePath = "textures/back.jpg"
    __titleImagePath = "textures/title.png"
    __newGameImagePath = "textures/newgame.png"
    __quitImagePath = "textures/quit.png"
    __selectedImagePath = "textures/selected.png"
    __gameOverText = None
    __backToMenuText = None
    __tryAgainText = None

    def __init__(self, gameEngine, base, gameState):
        self.__gameEngine = gameEngine
        self.__base = base
        self.__gameState = gameState
        self.__selected = EnumMenuOptions.NEW_GAME

    def showMenu(self):
        self.__screenImage = OnscreenImage(parent=self.__base.render2d, image=self.__screenImagePath, pos=(0,0,0))
        self.preserveImageAspect(self.__screenImage)

        self.__selectedImage = OnscreenImage(parent=self.__base.render2d, image=self.__selectedImagePath)
        self.__selectedImage.setTransparency(TransparencyAttrib.MAlpha)
        self.preserveImageAspect(self.__selectedImage)

        self.__titleImage = OnscreenImage(parent=self.__base.render2d, image=self.__titleImagePath)
        self.__titleImage.setTransparency(TransparencyAttrib.MAlpha)
        self.__titleImage.setPos(0,0,0.5)
        self.preserveImageAspect(self.__titleImage)

        self.__newGameImage = OnscreenImage(parent=self.__base.render2d, image=self.__newGameImagePath)
        self.__newGameImage.setTransparency(TransparencyAttrib.MAlpha)
        self.__newGameImage.setPos(0,0,0.0)
        self.preserveImageAspect(self.__newGameImage)

        self.__quitImage = OnscreenImage(parent=self.__base.render2d, image=self.__quitImagePath)
        self.__quitImage.setTransparency(TransparencyAttrib.MAlpha)
        self.__quitImage.setPos(0,0,-0.2)
        self.preserveImageAspect(self.__quitImage)

        self.changeSelected(EnumMenuOptions.NEW_GAME)

    def hideMenu(self):
        self.__screenImage.removeNode()
        self.__titleImage.removeNode()
        self.__newGameImage.removeNode()
        self.__quitImage.removeNode()
        self.__selectedImage.removeNode()

    def hideGameOver(self):
        if self.__gameOverText != None:
            self.__gameOverText.removeNode()
        if self.__tryAgainText != None:
            self.__tryAgainText.removeNode()
        if self.__backToMenuText != None:
            self.__backToMenuText.removeNode()

    def update (self, elapsedTime):
        is_down = self.__base.mouseWatcherNode.is_button_down
        if  (is_down(KeyboardButton.up()) and (self.__selected > 0)):
            self.changeSelected(self.__selected - 1)
        elif (is_down(KeyboardButton.down()) and (self.__selected < 1)):
            self.changeSelected(self.__selected + 1)
        elif is_down(KeyboardButton.enter()):
            self.runSelectedOption()
        pass

    def runSelectedOption(self):
        if self.__selected == EnumMenuOptions.NEW_GAME:
            self.hideMenu()
            self.__gameState.setGameState(EnumGameStates.PLAY)
        elif self.__selected == EnumMenuOptions.QUIT:
            self.__gameState.setGameState(EnumGameStates.EXITING)

    def backToMenu(self):
        self.hideGameOver()
        self.__gameState.setGameState(EnumGameStates.MENU)

    def preserveImageAspect(self, image):
        image.setScale(float(image.getTexture().getXSize())/self.__base.win.getXSize(), 1, float(image.getTexture().getYSize())/self.__base.win.getYSize())

    def changeSelected(self, menuOption):
        if self.__gameState.getGameState() == EnumGameStates.MENU:
            if menuOption == EnumMenuOptions.NEW_GAME:
                self.__selectedImage.setPos(self.__newGameImage.getPos())
            elif menuOption == EnumMenuOptions.QUIT:
                self.__selectedImage.setPos(self.__quitImage.getPos())
            self.__selected = menuOption
        else:
            pass

    def showGameOver(self):
        self.__gameOverText =  OnscreenText(text = 'GAME OVER',
                                            pos = (0.0, 0.4),
                                            scale = 0.1,
                                            parent = self.__base.render2d,
                                            fg = (1,0,0,1),
                                            shadow = (0,0,0,1))
        self.__tryAgainText =  OnscreenText(text = '"R" - try this level again',
                                            pos = (0.0, 0.2),
                                            scale = 0.07,
                                            parent = self.__base.render2d,
                                            fg = (1,0,0,1),
                                            shadow = (0,0,0,1))
        self.__backToMenuText =  OnscreenText(text = '"Esc" - back to menu',
                                            pos = (0.0, 0.0),
                                            scale = 0.07,
                                            parent = self.__base.render2d,
                                            fg = (1,0,0,1),
                                            shadow = (0,0,0,1))
Exemple #10
0
class EnemyFireIndicator(DirectObject):
    
    def __init__(self):
        self.node = aspect2d.attachNewNode('hudhealth')#GUIOrder.ORDER[GUIOrder.HUD])
        self.node.setBin('fixed', GUIOrder.ORDER[GUIOrder.HUD])
        
        self.lastAttacker = None
        
        self.indicator = OnscreenImage(image = 'Assets/Images/HUD/EnemyFireIndicator.png')
        self.indicator.setTransparency(TransparencyAttrib.MAlpha)
        self.indicator.reparentTo(self.node)
        
        self.alphaSeq = Sequence(Wait(0.75),
                                 LerpColorInterval(self.node, 0.75, Vec4(1, 1, 1, 0), Vec4(1, 1, 1, 1)),
                                 Func(self.Hide))
        
        self.node.hide()
        
        self.accept(PlayerHitEvent.EventName, self.OnPlayerHitEvent)
        
    def Hide(self):
        self.node.hide()
        self.lastAttacker = None
        
    def Show(self):
        self.node.show()
        self.node.setColor(Vec4(1, 1, 1, 1))
        
    def Update(self):
        if(self.lastAttacker):
            self.node.setR(self.GetTheta(self.me, self.lastAttacker))
            
    def GetTheta(self, victim, attacker):
        victimLookingDir = victim.GetPlayerState().GetValue(PlayerState.LOOKING_DIRECTION)
        victimLookingDir.setZ(0)
        victimLookingDir.normalize()
        victimLookingDir = Vec3(victimLookingDir)
        
        attackerToVictimVector = victim.GetPos() - attacker.GetPos()
        attackerToVictimVector.setZ(0)
        attackerToVictimVector.normalize()
        attackerToVictimVector = Vec3(attackerToVictimVector)
        
        return attackerToVictimVector.signedAngleDeg(victimLookingDir, Globals.UP_VECTOR)
        
    def OnPlayerHitEvent(self, event):
        victim = event.GetVictim()
        attacker = event.GetAttacker()
        
        if(victim and victim.GetPlayerState().GetValue(PlayerState.PID) == Globals.MY_PID):
            self.me = victim
            self.lastAttacker = attacker
            
            theta = self.GetTheta(victim, attacker)
            
            self.node.setR(theta)
            self.Show()
            self.alphaSeq.start(startT = 0)
        
    def Destroy(self):
        self.alphaSeq.finish()
        self.ignoreAll()
        self.indicator.removeNode()
        self.node.removeNode()
        
        
        
Exemple #11
0
class ImagePresenter(MessagePresenter):
    """
    A display that can present images with a fixed (or optionally randomly chosen) position,
    size and other display properties (e.g. coloring).   
    
    See also MessagePresenter for usage information.
    """
    def __init__(
            self,
            pos=(-0.25,
                 0.5),  # position of the image center in the aspect2d viewport
            # may also be a callable object (e.g.a draw from a random number generator)
        scale=0.2,  # scaling of the image; may also be callable
            rotation=(
                0, 0, 0
            ),  # yaw, pitch, roll -- the most relevant is the roll coordinate; may also be callable
            color=(1, 1, 1, 1),  # (r,g,b,a) image color
            renderviewport=None,  # the parent viewport if desired
            image='blank.tga',  # the initial image to present
            *args,
            **kwargs):
        """Construct a new ImagePresenter."""
        MessagePresenter.__init__(self, *args, **kwargs)
        self.pos = pos
        self.scale = scale
        self.rotation = rotation
        self.color = color
        self.renderviewport = renderviewport

        # set up the text panel...
        #if not (type(self.pos) is List or type(self.pos) is tuple):
        #pos = self.pos()
        #if callable(self.scale):
        #scale = self.scale()
        #if callable(self.rotation):
        #rotation = self.rotation()
        #if callable(self.color):
        #color = self.color()
        self.icon = OnscreenImage(
            image=image,
            pos=(pos[0], 0, pos[1]),
            scale=scale,
            hpr=rotation,
            color=((0, 0, 0, 0) if image == "blank.tga" else self.color),
            parent=self.renderviewport)
        self.icon.setTransparency(TransparencyAttrib.MAlpha)

    def _present(self, message):
        self.icon.setImage(message.strip())
        self.icon.setTransparency(TransparencyAttrib.MAlpha)
        # select remaining properties randomly, if applicable
        # if callable(self.pos):
        #    p = self.pos()
        #    self.icon.setPos(p[0],p[1],p[2])
        # if callable(self.scale):
        #    self.icon.setScale(self.scale())
        # if callable(self.rotation):
        #    rot = self.rotation()
        #    self.icon.setHpr(rot[0],rot[1],rot[2])
        col = self.color  #() if callable(self.color) else self.color
        self.icon.setColor(col[0], col[1], col[2], col[3])
        self.marker(222)

    def _unpresent(self):
        try:
            self.marker(223)
            self.icon.setColor(0, 0, 0, 0)
        except:
            pass

    def destroy(self):
        self.icon.removeNode()

    def precache(self, message):
        loader.loadTexture(message)
Exemple #12
0
class ButtonViewer:
    def __init__(self, bpm, z_pos=-0.7):
        self.BTN_SPACE_PER_BEAT = 0.2
        self.BTN_SIZE = 64.0
        self.BTN_SIZE = 64.0
        self.BTN_SCALE = (self.BTN_SIZE / base.win.getXSize(), 1,
                          self.BTN_SIZE / base.win.getYSize())

        self.z_pos = z_pos
        self.delay_per_beat = beat_delay(bpm)

        self.tex_buttons = {}
        for b, i in zip(["A", "B", "C", "D"], ["down", "right", "left", "up"]):
            self.tex_buttons[b] = loader.loadTexture("image/wii_%s.png" % i)

        #~ else:
        #~ for b, i in zip(["A", "B", "C", "D"],["cross", "circle", "square", "triangle"]):
        #~ self.tex_buttons[b] = loader.loadTexture("image/b_%s.png" % i)

        ## Button marker
        self.button_marker = OnscreenImage(image="image/b_marker.png",
                                           pos=(0, 2, self.z_pos),
                                           scale=self.BTN_SCALE,
                                           parent=render2d)
        self.button_marker.setTransparency(TransparencyAttrib.MAlpha)

        self.button_node = render2d.attachNewNode("Button Root Node")
        self.initial_x = self.button_node.getX()

        self.next_button = 0

    def append_button(self, button, beat):
        btn_image = OnscreenImage(image=self.tex_buttons[button],
                                  pos=(-beat * self.BTN_SPACE_PER_BEAT, 0,
                                       self.z_pos),
                                  scale=self.BTN_SCALE,
                                  parent=render2d)
        btn_image.setTransparency(TransparencyAttrib.MAlpha)
        btn_image.reparentTo(self.button_node)

    def update(self, time):
        self.button_node.setX(
            self.initial_x +
            time2pos(time, self.delay_per_beat, self.BTN_SPACE_PER_BEAT))

    def button_hit(self):
        pass
        #~ button = self.button_node.getChild(self.next_button)
        #~ button.setAlphaScale(.0)

        #~ self.next_button += 1
        #~ button = self.button_node.getChild(self.next_button )
        #~ pos = render2d.getRelativePoint(self.button_node, button.getPos())

        #~ button.reparentTo(render2d)
        #~ button.setPos(pos)

        #~ LerpFunc(button.setAlphaScale, duration=0.2, fromData=1, toData=0, blendType='easeOut').start()

    def button_miss(self):
        pass
        #self.next_button += 1

    def __del__(self):
        self.button_node.removeNode()
        self.button_marker.removeNode()
Exemple #13
0
class Minimap:
	def __init__(self, path='/models', scale = 0.0, posX = -0.9, posZ = -0.65, mapimageName = None):
		taskMgr.add(self.step,"MinimapTask")
		self.path = path
		self.posX = posX
		self.posZ = posZ
		b = 500
		pos = Vec3(self.posX,0,self.posZ)#Aspect2D coordinates for the location of the center of the minimap. 
		if mapimageName is None: mapimageName = '%s/battlemap.png' % self.path#mapimage is the image to place in the minimap
		
		self.scale = scale  #this value is the number of pixels wide the map will be.
		ratio = b/self.scale
		self.dotScale = (ratio) * b
		self.dotSize = 0.005 / ratio
		self.map = aspect2d.attachNewNode('Map')
		mapimage = self.getMapImage(mapimageName)
		
		props = base.win.getProperties( )
		self.Height = float(props.getYSize())
		self.Hscale = (1/self.Height)
		
		self.map.setScale(self.Hscale)  #Sets scale to the screen resolution.
		self.map.setPos(pos) #this is the location on aspect2d for the minimap. 
		self.dots = []
		self.dots.append([])
		self.targets = []
		self.targets.append([])
		self.teamImage = []  #a list of paths to the image that each team will use. 
		self.setNumTeams(9)
		self.mapimage = OnscreenImage(image = mapimage, scale = self.scale, parent = self.map)
		self.mousePosition = OnscreenImage(image = self.path + 'select3.png', scale = self.dotSize*10, pos = (0,0,0), parent = aspect2d)
		self.totaltargets = 0
	
	def destroy(self):
		"""Remove Minimap from game"""
		for team in range(len(self.dots)): #will cycle through each team
			for i in range(len(self.dots[team])): #will cycle through each member of the team
				dot = self.dots[team][i]
				dot.removeNode()
		self.mousePosition.removeNode()
		self.mapimage.removeNode()
		self.map.removeNode()
	
	def getMapImage(self, mapimageName):
		texImage=PNMImage() 
		texImage.read(Filename(mapimageName)) 
		tex=Texture()
		tex.load(texImage)
		return tex
	
	def setTargets(self, targets, team):
		for i in range(len(targets)):
			self.targets[team].append(targets[i])
		
		for i in range(len(self.targets[team])):
			self.dots[team].append(OnscreenImage(image = self.teamImage[team], scale = self.dotSize, pos = (0,0,0), parent = aspect2d))
		
	def setBezel(self, image = None, scale = None):
		
		if image is None: image = '%s/bezel.png' % self.path
		if scale is None: scale = 1
		
		self.bezel = OnscreenImage(image = image, scale = self.scale * scale, parent = self.map)
		self.bezel.setTransparency(TransparencyAttrib.MAlpha)
		
	def setScale(self, scale):
		self.scale = scale
		
	def setPos(self,num): #must be a Vec3
		self.pos = num
				
	def appendTarget(self, target = None, team = None): #target must be a nodepath, team must be an integer
		if target is not None:
			self.targets[team].append(target)
			x = len(self.targets[team])
			self.dots[team].append(OnscreenImage(image = self.teamImage[team], scale = self.dotSize, pos = (0,0,0), parent = aspect2d))
			
	def setNumTeams(self, num):  #Num must be an integer. Sets the number of different groups for the map to track. Each group may be tracked using a different graphic   
		newTargets = []
		for x in range(num):
			newTargets.append([])
			self.dots.append([])
			self.teamImage.append('%s/dot%d.png' % (self.path, x))
		self.targets = newTargets
		
	def removeTarget(self, target = None, team = None):
		for i in range(len(self.targets[team])):
			if self.targets[team][i] == target: #This means the object in question is the object to be removed
				self.dots[team][i].stash()
				
	def step(self, task):
		try:
			for team in range(len(self.targets)): #will cycle through each team
				for i in range(len(self.targets[team])): #will cycle through each member of the team
					target = self.targets[team][i]
					if target.isEmpty() == False:
						x = (target.getX()/self.dotScale) + self.posX
						z = (target.getZ()/self.dotScale) + self.posZ
						self.dots[team][i].setX(x)
						self.dots[team][i].setZ(z)
			
			self.mousePosition.setX((camera.getX()/self.dotScale + self.posX))
			self.mousePosition.setZ((camera.getZ()/self.dotScale + self.posZ))
						
			return Task.cont
		except:
			pass
Exemple #14
0
class Credits:
    def __init__(self,
                 name,
                 description,
                 image,
                 side='left',
                 number=1,
                 name2=None,
                 description2=None,
                 image2=None,
                 special=None):
        self.sceneRoot = None
        self.twoSlides = None
        self.toonName = name
        self.toonDescription = description
        self.toonImage = image
        self.side = side
        self.special = special  # For special types of slides, like the final one
        if number > 1:
            self.toon2Name = name2
            self.toon2Description = description2
            self.toon2Image = image2
            self.twoSlides = True

    def load(self):
        self.sceneRoot = NodePath(
            self.toonName.replace(' ', '').replace('', ''))
        base.setBackgroundColor(0, 0, 0, 1)

        if self.twoSlides:
            if self.side == 'left':
                # Left Top
                titlePos = (0.1, 0.5, 0.0)
                descriptionPos = (0.2, 0.4, 0.0)
                imagePos = (-0.55, 0.0, 0.4)
                textAlignment = TextNode.ALeft
                # Right Bottom
                title2Pos = (-0.1, -0.35, 0.0)
                description2Pos = (-0.1, -0.45, 0.0)
                image2Pos = (0.55, 0.0, -0.4)
                text2Alignment = TextNode.ARight
            else:
                # Right Top
                titlePos = (-0.1, 0.5, 0.0)
                descriptionPos = (-0.1, 0.4, 0.0)
                imagePos = (0.55, 0.0, 0.4)
                textAlignment = TextNode.ARight
                # Left Bottom
                title2Pos = (0.1, -0.35, 0.0)
                description2Pos = (0.25, -0.45, 0.0)
                image2Pos = (-0.55, 0.0, -0.4)
                text2Alignment = TextNode.ALeft
        elif self.side == 'left':
            # Left Middle
            titlePos = (0.1, 0.15, 0.0)
            descriptionPos = (0.2, 0.05, 0.0)
            imagePos = (-0.5, 0.0, 0.0)
            textAlignment = TextNode.ALeft
        else:
            # Right Middle
            titlePos = (-0.1, 0.1, 0.0)
            descriptionPos = (-0.11, 0.0, 0.0)
            imagePos = (0.5, 0.0, 0.0)
            textAlignment = TextNode.ARight

        self.title = OnscreenText(text=self.toonName,
                                  pos=titlePos,
                                  scale=(0.15),
                                  fg=(1, 1, 1, 1),
                                  font=ToontownGlobals.getSignFont(),
                                  align=textAlignment)
        self.description = OnscreenText(text=self.toonDescription,
                                        pos=descriptionPos,
                                        scale=(0.06),
                                        fg=(1, 1, 1, 1),
                                        font=ToontownGlobals.getMinnieFont(),
                                        align=textAlignment)
        self.image = OnscreenImage(image='phase_4/maps/news/%s' %
                                   self.toonImage,
                                   pos=imagePos,
                                   scale=(0.5, 0.30, 0.30))
        self.elements = [self.title, self.description, self.image]

        if self.twoSlides:
            self.title2 = OnscreenText(text=self.toon2Name,
                                       pos=title2Pos,
                                       scale=(0.15),
                                       fg=(1, 1, 1, 1),
                                       font=ToontownGlobals.getSignFont(),
                                       align=text2Alignment)
            self.description2 = OnscreenText(
                text=self.toon2Description,
                pos=description2Pos,
                scale=(0.06),
                fg=(1, 1, 1, 1),
                font=ToontownGlobals.getMinnieFont(),
                align=text2Alignment)
            self.image2 = OnscreenImage(image='phase_4/maps/news/%s' %
                                        self.toon2Image,
                                        pos=image2Pos,
                                        scale=(0.5, 0.30, 0.30))
            self.elements.extend([self.title2, self.description2, self.image2])

        for node in self.elements:
            node.setTransparency(1)
            node.setColorScale(1, 1, 1, 0)

    def makeInterval(self):
        if self.special == 'final':
            # Hide the last slide, rather than fade out
            return Sequence(ParentInterval(self.sceneRoot, render),
                            Func(doFade, 'in', self.elements), Wait(3),
                            Func(doFade, 'hide', self.elements),
                            ParentInterval(self.sceneRoot, hidden))
        else:
            # Just a normal slide
            return Sequence(ParentInterval(self.sceneRoot, render),
                            Func(doFade, 'in', self.elements), Wait(3.5),
                            Func(doFade, 'out', self.elements), Wait(0.5),
                            ParentInterval(self.sceneRoot, hidden))

    def unload(self):
        self.sceneRoot.removeNode()
        self.title.removeNode()
        self.description.removeNode()
        self.image.removeNode()
        self.elements = None
        self.toonName = None
        self.toonDescription = None
        self.toonImage = None
        self.side = None
Exemple #15
0
class ImagePresenter(MessagePresenter):
    """
    A display that can present images with a fixed (or optionally randomly chosen) position,
    size and other display properties (e.g. coloring).   
    
    See also MessagePresenter for usage information.
    """
    
    def __init__(self,
                 pos=(-0.25,0.5),       # position of the image center in the aspect2d viewport
                                        # may also be a callable object (e.g.a draw from a random number generator)
                 scale=0.2,             # scaling of the image; may also be callable
                 rotation=(0,0,0),      # yaw, pitch, roll -- the most relevant is the roll coordinate; may also be callable
                 color=(1,1,1,1),       # (r,g,b,a) image color
                 renderviewport=None,   # the parent viewport if desired
                 image='blank.tga',     # the initial image to present
                 *args,**kwargs
                 ):
        
        """Construct a new ImagePresenter."""
        MessagePresenter.__init__(self,*args,**kwargs) 
        self.pos = pos
        self.scale = scale
        self.rotation = rotation
        self.color = color
        self.renderviewport = renderviewport
        
        # set up the text panel...
        #if not (type(self.pos) is List or type(self.pos) is tuple):
            #pos = self.pos()
        #if callable(self.scale):
            #scale = self.scale()
        #if callable(self.rotation):
            #rotation = self.rotation()
        #if callable(self.color):
            #color = self.color()
        self.icon = OnscreenImage(image=image,pos=(pos[0],0,pos[1]),scale=scale,hpr=rotation,color= ((0,0,0,0) if image=="blank.tga" else self.color),parent=self.renderviewport)
        self.icon.setTransparency(TransparencyAttrib.MAlpha)

    def _present(self,message):
        self.icon.setImage(message.strip())
        self.icon.setTransparency(TransparencyAttrib.MAlpha)
        # select remaining properties randomly, if applicable            
        # if callable(self.pos):
        #    p = self.pos()
        #    self.icon.setPos(p[0],p[1],p[2])
        # if callable(self.scale):
        #    self.icon.setScale(self.scale())
        # if callable(self.rotation):
        #    rot = self.rotation()
        #    self.icon.setHpr(rot[0],rot[1],rot[2])
        col = self.color #() if callable(self.color) else self.color 
        self.icon.setColor(col[0],col[1],col[2],col[3])
        self.marker(222)

    def _unpresent(self):
        try:
            self.marker(223)
            self.icon.setColor(0,0,0,0)
        except:
            pass

    def destroy(self):
        self.icon.removeNode()

    def precache(self,message):
        loader.loadTexture(message)