예제 #1
0
    def __init__(self, fsm, side):
        #TODO: add temporary mapping.. see the todo in pollEvents
        #lets start by creating a mapping a key to a number, so we get independant of keyboards, controllers, cpu and networking.
        #this code, still is keyboard dependant is it maps keys to an event number (the index of the key)
        #using ["a","b","c"] , will make key a the event 1, b event 2 and so on.
        #given my godlike power to define indices at will...
        #i hearby delcare index  1 to 4 will map to up,down,left, right.
        #further i declare thet event 5 shall be punch, 6 kick, 7 defense , 8 special1
        #index 9 shall play a cute animation on cute characters and some raw and macho-like animation on raw-macho like chars
        #dont dare to disobey.
        #to leave event indices unset, stuff with  "" 
        #example keymap = ["","arrow_up","arrow_down","arrow_left","arrow_right","1","2","3"] 

        #negative event numbers map to key-lift events . so we cant use event 0 as -0 == 0 , stuffing "" as index 0 , 0 will double as "no event key neccessary"
        ##TODO: load the keymap from a config file!
        keymap = readKeys()
        keymap = keymap[side]
        # The keymap stores button presses as a positive number, and button releases
        # as negative, so we make sure index 0 isn't used, since 0 = -0
        keymap.insert(0, "")
        self.fsm = fsm
        self.side = side
        self.keystatus = set()

        # Bind our event 
        for index, key in enumerate(keymap):
            self.accept(key, self.setKey, [index, 1])
            self.accept(key + "-up", self.setKey, [index, 0])
            self.keystatus.add(-index)
        self.eventRecorder = EventRecorder() #will store the keys pressed in the past
        self.stateTimer = Sequence() #this will contain a sequence with a Wait and Func interval, requesting the next state
                               #unless overwritten by a more recent state (as in double-tab combo)
        self.nextState = None  #the state into wich the the stateTimer will change so we can avoid lockups when requesting the same state over and over again
        self.permaTriggers = [] #contains the "permanent" mapped inputs, cant be deleted by the fsm.

        self.permaTriggers.append(StateTrigger(1, "Jump", [-2])) #-2 means no jumping when the user presses down.
        self.permaTriggers.append(StateTrigger(1, ["JumpIn" ,"JumpOut" ], [-2, 4]))
        self.permaTriggers.append(StateTrigger(1, ["JumpOut","JumpIn"  ], [-2, 3]))
        self.permaTriggers.append(StateTrigger(0, "Crouch", [2]))  #0 means, no special trigger key
        self.permaTriggers.append(StateTrigger(0, ["RunIn" , "RunOut"], [4]))
        self.permaTriggers.append(StateTrigger(0, ["RunOut", "RunIn" ], [3]))
        self.permaTriggers.append(StateTrigger(5, "Punch", [-2])) #ne regular punch when crouching
        self.permaTriggers.append(StateTrigger(7, "Defense", [-2, 7])) # turn the first 7 (trigger key) to 0 if you like the make attack->defense with static buttons
        self.permaTriggers.append(StateTrigger(6, "Kick", [-2]))
        self.permaTriggers.append(StateTrigger(5, "CrouchPunch", [2])) #crouch punch needs crouching *nodnod*
        self.permaTriggers.append(StateTrigger(6, "CrouchKick", [2])) #so does kicking ..
        self.permaTriggers.append(StateTrigger(7, "CrouchDefense", [2, 7])) # 
        self.permaTriggers.append(StateTrigger(1, ["EvadeCW","EvadeCCW"], [0], eventOrder=[1,1])) #there was some.. really odd bug that added event 1, to the event map of
        self.permaTriggers.append(StateTrigger(2, ["EvadeCCW","EvadeCW"], [0], eventOrder=[2,2])) #this line here.when i did not specify the [0]. so i added 0
예제 #2
0
    def __init__(self, callback = None):
        self.charRoot = NodePath("characterSelectRoot")
        
        self.players = [{},{}]
        # heights on which preview strips appear
        heights = [0.8,-0.8]
        # determines separation between previews
        previews = [0.5, -0.5]

        self.callback = callback
        self.preview_size = [-0.3,  0.3, -0.3, 0.3]
        self.generator = CardMaker("PreviewMaker") 
        self.generator.setFrame(*self.preview_size)
        self.players_ready = 0
        
        self.vs = OnscreenText("vs")
        self.vs.reparentTo(self.charRoot)
        
        players = self.players
        for i in range(2):
            players[i]["strip"] = PreviewStrip("../assets/fighters", def_height = heights[i])
            players[i]["strip"].getStripNP().reparentTo(self.charRoot)
            
            players[i]["text"] = OnscreenText("")
            players[i]["text"].reparentTo(self.charRoot)
            players[i]["text"].setPos(0, players[i]["strip"].height - (2*i-1)* 0.25)
            
            players[i]["preview"] = self.charRoot.attachNewNode(self.generator.generate())
            players[i]["preview"].setPos(previews[i],.2, 0.0)
            players[i]["select"] = OnscreenText("ready")
            players[i]["select"].reparentTo(self.charRoot)
            players[i]["select"].setPos(0, players[i]["strip"].height)
            players[i]["select"].hide()

        self.keys = readKeys()
        self.left = [self.keys[0][1], self.keys[1][2]]
        self.right = [self.keys[0][3], self.keys[1][3]]
        self.confirm = [self.keys[0][4], self.keys[1][4]]

        self.updateText()
        self.updateImg()
예제 #3
0
 def __init__(self, callback = None):
     self.stageRoot = NodePath("stageSelectRoot")
     
     self.ps = PreviewStrip("../assets/stages" ,-0.7)
     self.ps.getStripNP().reparentTo(self.stageRoot)
     
     self.callback = callback
     # name of the stage will be displayed here
     self.text = OnscreenText("")
     self.text.reparentTo(self.stageRoot)
     self.text.setPos(0,self.ps.height - 0.4)
     
     self.preview_size = [-0.5,  0.5, -0.5, 0.5]
     
     self.generator = CardMaker("PreviewMaker") 
     self.generator.setFrame(*self.preview_size)
     
     self.preview = self.stageRoot.attachNewNode(self.generator.generate())
     self.preview.setPos(0,0, 0.4)
     # keys are read so that the first in the pair is from player 1
     # and second from the player 2, so that they both can decide
     self.keys = readKeys()
     self.left = [self.keys[0][1], self.keys[1][2]]
     self.right = [self.keys[0][3], self.keys[1][3]]
     self.select = [self.keys[0][4], self.keys[1][4]]
     
     self.ready = OnscreenText("ready")
     self.ready.reparentTo(self.stageRoot)
     self.ready.setPos(0,self.ps.height)
     # will be shown when players selected the stage
     self.ready.hide()
     # we notify ourselves to enable the key input and update text
     # and preview
     
     self.updateText()
     self.updateImg() 
     
     self.disableInput()