コード例 #1
0
 def doKeys(self, keys, keysLastFrame, char):
     if char.moving:  # Player's currently moving, ignore keypresses
         return
     if self.activity == None and kbInput.isMenuPressed(
             keys) and not kbInput.isMenuPressed(keysLastFrame):
         self.renderMenu = not self.renderMenu
     if (self.renderMenu):
         if kbInput.isUpPressed(
                 keys) and not kbInput.isUpPressed(keysLastFrame):
             pass  # If we have more items, this decrements the menuIndex
         elif kbInput.isDownPressed(
                 keys) and not kbInput.isDownPressed(keysLastFrame):
             pass  # If we have more items, this increments the menuIndex
         elif kbInput.isOkayPressed(
                 keys) and not kbInput.isOkayPressed(keysLastFrame):
             self.renderMenu = False
             self.manager.go_to(scene.Scenes.CODING, plyr=self.main_player)
         elif kbInput.isBackPressed(
                 keys) and not kbInput.isBackPressed(keysLastFrame):
             self.renderMenu = False
     else:
         # Use change_direction instead of just changing the
         # variable since it also changes the sprite image
         if kbInput.isUpPressed(keys):
             self.move(char, game_objects.Direction.UP)
         elif kbInput.isRightPressed(keys):
             self.move(char, game_objects.Direction.RIGHT)
         elif kbInput.isDownPressed(keys):
             self.move(char, game_objects.Direction.DOWN)
         elif kbInput.isLeftPressed(keys):
             self.move(char, game_objects.Direction.LEFT)
コード例 #2
0
ファイル: intscene.py プロジェクト: ColdSauce/golems
 def doKeys(self, keys, keysLastFrame, char):
     if char.moving: # Player's currently moving, ignore keypresses
         return
     if self.activity == None and kbInput.isMenuPressed(keys) and not kbInput.isMenuPressed(keysLastFrame):
         self.renderMenu = not self.renderMenu
     if(self.renderMenu):
         if kbInput.isUpPressed(keys) and not kbInput.isUpPressed(keysLastFrame):
             pass  # If we have more items, this decrements the menuIndex
         elif kbInput.isDownPressed(keys) and not kbInput.isDownPressed(keysLastFrame):
             pass  # If we have more items, this increments the menuIndex
         elif kbInput.isOkayPressed(keys) and not kbInput.isOkayPressed(keysLastFrame):
             self.renderMenu = False
             self.manager.go_to(scene.Scenes.CODING, plyr = self.main_player)
         elif kbInput.isBackPressed(keys) and not kbInput.isBackPressed(keysLastFrame):
             self.renderMenu = False
     else:
         # Use change_direction instead of just changing the
         # variable since it also changes the sprite image
         if kbInput.isUpPressed(keys):
             self.move(char,game_objects.Direction.UP)
         elif kbInput.isRightPressed(keys):
             self.move(char,game_objects.Direction.RIGHT)
         elif kbInput.isDownPressed(keys):
             self.move(char,game_objects.Direction.DOWN)
         elif kbInput.isLeftPressed(keys):
             self.move(char,game_objects.Direction.LEFT)
コード例 #3
0
    def update(self, keys, keysLastFrame):

        currentTime = time.time()
        if currentTime >= self.nextTurnTime:
            self.nextTurn()
            self.nextTurnTime += self.gameSpeed

        keys = pygame.key.get_pressed()

        if kbInput.isUpPressed(keys):
            self.moveBotByDir(self.c1Bots[0], 0, 1)
            self.moveBotByDir(self.c2Bots[0], 0, 1)
        elif kbInput.isRightPressed(keys):
            self.moveBotByDir(self.c1Bots[0], 1, 0)
            self.moveBotByDir(self.c2Bots[0], 1, 0)
        elif kbInput.isDownPressed(keys):
            self.moveBotByDir(self.c1Bots[0], 0, -1)
            self.moveBotByDir(self.c2Bots[0], 0, -1)
        elif kbInput.isLeftPressed(keys):
            self.moveBotByDir(self.c1Bots[0], -1, 0)
            self.moveBotByDir(self.c2Bots[0], -1, 0)
コード例 #4
0
ファイル: battlescene.py プロジェクト: ColdSauce/golems
 def update(self, keys, keysLastFrame):
     
     currentTime = time.time()
     if currentTime >= self.nextTurnTime:
         self.nextTurn()
         self.nextTurnTime += self.gameSpeed
     
     keys = pygame.key.get_pressed()
         
     if kbInput.isUpPressed(keys):
         self.moveBotByDir(self.c1Bots[0],0,1)
         self.moveBotByDir(self.c2Bots[0],0,1)
     elif kbInput.isRightPressed(keys):
         self.moveBotByDir(self.c1Bots[0],1,0)
         self.moveBotByDir(self.c2Bots[0],1,0)
     elif kbInput.isDownPressed(keys):
         self.moveBotByDir(self.c1Bots[0],0,-1)
         self.moveBotByDir(self.c2Bots[0],0,-1)
     elif kbInput.isLeftPressed(keys):
         self.moveBotByDir(self.c1Bots[0],-1,0)
         self.moveBotByDir(self.c2Bots[0],-1,0)
コード例 #5
0
ファイル: codingscene.py プロジェクト: ColdSauce/golems
 def doKeys(self, keys, keysLastFrame):
     if(self.blockMenu): # Menu is open
     
         if(self.activity != None): # Only do if we're on a Sugar-based System
             if kbInput.isOkayPressed(keys) and not kbInput.isOkayPressed(keysLastFrame):
                 self.blockMenu = False
                 self.inputIndex = 0
             elif(isinstance(self.selBlock, game_objects.CommentBlock)):
                 if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                     self.inputIndex = max(self.inputIndex - 1, 0)
                 elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                     self.inputIndex = min(self.inputIndex + 1, len(self.selBlock.comment))
                 newCmmnt, self.inputIndex = kbInput.kbTextInput(keys, keysLastFrame, self.selBlock.comment, self.inputIndex)
                 self.selBlock.setComment(newCmmnt)
             elif(isinstance(self.selBlock, game_objects.SayBlock)):
                 if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                     self.inputIndex = max(self.inputIndex - 1, 0)
                 elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                     self.inputIndex = min(self.inputIndex + 1, len(self.selBlock.message))
                 newMsg, self.inputIndex = kbInput.kbTextInput(keys, keysLastFrame, self.selBlock.message, self.inputIndex)
                 self.selBlock.setMessage(newMsg)
             elif(isinstance(self.selBlock, game_objects.IfManaBlock)):
                 if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                     self.inputIndex = max(self.inputIndex - 1, 0)
                 elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                     self.inputIndex = min(self.inputIndex + 1, len(str(self.selBlock.mthresh)))
                 newThresh, self.inputIndex = kbInput.kbNumInput(keys, keysLastFrame, self.selBlock.mthresh, self.inputIndex)
                 self.selBlock.setThresh(newThresh)
             elif(isinstance(self.selBlock, game_objects.IfOwnHealthBlock)):
                 if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                     self.inputIndex = max(self.inputIndex - 1, 0)
                 elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                     self.inputIndex = min(self.inputIndex + 1, len(str(self.selBlock.hthresh)))
                 newThresh, self.inputIndex = kbInput.kbNumInput(keys, keysLastFrame, self.selBlock.hthresh, self.inputIndex)
                 self.selBlock.setThresh(newThresh)
             self.inputIndex = max(self.inputIndex, 0)
             
         else: # Do on a non-Sugar System
             if kbInput.isMenuPressed(keys) and not kbInput.isMenuPressed(keysLastFrame):
                 self.blockMenu = False
                 self.menuIndex = 0
             if kbInput.isDownPressed(keys, False) and not kbInput.isDownPressed(keysLastFrame, False):
                 self.inputIndex = 0
                 if(self.mode == 0):
                     self.menuIndex = min(self.menuIndex + 1, 12)
                 elif(self.mode == 1):
                     self.menuIndex = min(self.menuIndex + 1, 3)
                 elif(self.mode == 2):
                     self.menuIndex = min(self.menuIndex + 1, 6)
             if kbInput.isUpPressed(keys, False) and not kbInput.isUpPressed(keysLastFrame, False):
                 self.inputIndex = 0
                 self.menuIndex = max(self.menuIndex - 1, 0)
             if kbInput.isOkayPressed(keys) and not kbInput.isOkayPressed(keysLastFrame):
                 if(self.menuIndex < 3):
                     self.mode = self.menuIndex
                     self.blockMenu = False
                     self.menuIndex = 0
                     self.selIndex = 0
                     self.currentBlockIndex = 0
                 else:
                     if(self.mode == 0):
                         newBlock = None
                         if(self.menuIndex == 3):
                             newBlock = game_objects.CommentBlock()
                         elif(self.menuIndex == 4):
                             newBlock = game_objects.SayBlock()
                         elif(self.menuIndex == 5):
                             newBlock = game_objects.WhileBlock()
                         elif(self.menuIndex == 6):
                             newBlock = game_objects.IfManaBlock()
                         elif(self.menuIndex == 7):
                             newBlock = game_objects.IfOwnHealthBlock()
                         elif(self.menuIndex == 8):
                             newBlock = game_objects.HealBlock(20, 15)
                         elif(self.menuIndex == 9):
                             newBlock = game_objects.FireballBlock(10, 15)
                         elif(self.menuIndex == 10):
                             newBlock = game_objects.MossLeechBlock(10, 15)
                         elif(self.menuIndex == 11):
                             newBlock = game_objects.DouseBlock(10, 15)
                         elif(self.menuIndex == 12):
                             newBlock = game_objects.EndTurnBlock()
                         if(self.insert(newBlock)):
                             self.selIndex += 1
                     elif(self.mode == 2):
                         if(self.menuIndex == 6):
                             self.remove()
             if(self.mode == 1 and self.menuIndex == 3):
                 if(isinstance(self.selBlock, game_objects.CommentBlock)):
                     if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                         self.inputIndex = max(self.inputIndex - 1, 0)
                     elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                         self.inputIndex = min(self.inputIndex + 1, len(self.selBlock.comment))
                     newCmmnt, self.inputIndex = kbInput.kbTextInput(keys, keysLastFrame, self.selBlock.comment, self.inputIndex)
                     self.selBlock.setComment(newCmmnt)
                 elif(isinstance(self.selBlock, game_objects.SayBlock)):
                     if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                         self.inputIndex = max(self.inputIndex - 1, 0)
                     elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                         self.inputIndex = min(self.inputIndex + 1, len(self.selBlock.message))
                     newMsg, self.inputIndex = kbInput.kbTextInput(keys, keysLastFrame, self.selBlock.message, self.inputIndex)
                     self.selBlock.setMessage(newMsg)
                 elif(isinstance(self.selBlock, game_objects.IfManaBlock)):
                     if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                         self.inputIndex = max(self.inputIndex - 1, 0)
                     elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                         self.inputIndex = min(self.inputIndex + 1, len(str(self.selBlock.mthresh)))
                     newThresh, self.inputIndex = kbInput.kbNumInput(keys, keysLastFrame, self.selBlock.mthresh, self.inputIndex)
                     self.selBlock.setThresh(newThresh)
                 elif(isinstance(self.selBlock, game_objects.IfOwnHealthBlock)):
                     if kbInput.isLeftPressed(keys, False) and not kbInput.isLeftPressed(keysLastFrame, False):
                         self.inputIndex = max(self.inputIndex - 1, 0)
                     elif kbInput.isRightPressed(keys, False) and not kbInput.isRightPressed(keysLastFrame, False):
                         self.inputIndex = min(self.inputIndex + 1, len(str(self.selBlock.hthresh)))
                     newThresh, self.inputIndex = kbInput.kbNumInput(keys, keysLastFrame, self.selBlock.hthresh, self.inputIndex)
                     self.selBlock.setThresh(newThresh)
                 self.inputIndex = max(self.inputIndex, 0)
                 
     else: # Menu is closed
         if kbInput.isBackPressed(keys) and not kbInput.isBackPressed(keysLastFrame):
             self.manager.go_to(scene.Scenes.INTERACTIVE)
             self.selIndex = 0
         if kbInput.isDownPressed(keys) and not kbInput.isDownPressed(keysLastFrame):
             if(self.mode == 0):
                 self.selIndex = min(self.selIndex + 1, self.totalArrowCount)
             else:
                 self.selIndex = min(self.selIndex + 1, self.totalBlockCount - 1)
         if kbInput.isUpPressed(keys) and not kbInput.isUpPressed(keysLastFrame):
             self.selIndex = max(self.selIndex - 1, 0)
         if self.activity == None and kbInput.isMenuPressed(keys) and not kbInput.isMenuPressed(keysLastFrame):
             self.blockMenu = True
     keysLastFrame = keys
コード例 #6
0
    def doKeys(self, keys, keysLastFrame):
        if (self.blockMenu):  # Menu is open

            if (self.activity !=
                    None):  # Only do if we're on a Sugar-based System
                if kbInput.isOkayPressed(
                        keys) and not kbInput.isOkayPressed(keysLastFrame):
                    self.blockMenu = False
                    self.inputIndex = 0
                elif (isinstance(self.selBlock, game_objects.CommentBlock)):
                    if kbInput.isLeftPressed(
                            keys, False) and not kbInput.isLeftPressed(
                                keysLastFrame, False):
                        self.inputIndex = max(self.inputIndex - 1, 0)
                    elif kbInput.isRightPressed(
                            keys, False) and not kbInput.isRightPressed(
                                keysLastFrame, False):
                        self.inputIndex = min(self.inputIndex + 1,
                                              len(self.selBlock.comment))
                    newCmmnt, self.inputIndex = kbInput.kbTextInput(
                        keys, keysLastFrame, self.selBlock.comment,
                        self.inputIndex)
                    self.selBlock.setComment(newCmmnt)
                elif (isinstance(self.selBlock, game_objects.SayBlock)):
                    if kbInput.isLeftPressed(
                            keys, False) and not kbInput.isLeftPressed(
                                keysLastFrame, False):
                        self.inputIndex = max(self.inputIndex - 1, 0)
                    elif kbInput.isRightPressed(
                            keys, False) and not kbInput.isRightPressed(
                                keysLastFrame, False):
                        self.inputIndex = min(self.inputIndex + 1,
                                              len(self.selBlock.message))
                    newMsg, self.inputIndex = kbInput.kbTextInput(
                        keys, keysLastFrame, self.selBlock.message,
                        self.inputIndex)
                    self.selBlock.setMessage(newMsg)
                elif (isinstance(self.selBlock, game_objects.IfManaBlock)):
                    if kbInput.isLeftPressed(
                            keys, False) and not kbInput.isLeftPressed(
                                keysLastFrame, False):
                        self.inputIndex = max(self.inputIndex - 1, 0)
                    elif kbInput.isRightPressed(
                            keys, False) and not kbInput.isRightPressed(
                                keysLastFrame, False):
                        self.inputIndex = min(self.inputIndex + 1,
                                              len(str(self.selBlock.mthresh)))
                    newThresh, self.inputIndex = kbInput.kbNumInput(
                        keys, keysLastFrame, self.selBlock.mthresh,
                        self.inputIndex)
                    self.selBlock.setThresh(newThresh)
                elif (isinstance(self.selBlock,
                                 game_objects.IfOwnHealthBlock)):
                    if kbInput.isLeftPressed(
                            keys, False) and not kbInput.isLeftPressed(
                                keysLastFrame, False):
                        self.inputIndex = max(self.inputIndex - 1, 0)
                    elif kbInput.isRightPressed(
                            keys, False) and not kbInput.isRightPressed(
                                keysLastFrame, False):
                        self.inputIndex = min(self.inputIndex + 1,
                                              len(str(self.selBlock.hthresh)))
                    newThresh, self.inputIndex = kbInput.kbNumInput(
                        keys, keysLastFrame, self.selBlock.hthresh,
                        self.inputIndex)
                    self.selBlock.setThresh(newThresh)
                self.inputIndex = max(self.inputIndex, 0)

            else:  # Do on a non-Sugar System
                if kbInput.isMenuPressed(
                        keys) and not kbInput.isMenuPressed(keysLastFrame):
                    self.blockMenu = False
                    self.menuIndex = 0
                if kbInput.isDownPressed(keys,
                                         False) and not kbInput.isDownPressed(
                                             keysLastFrame, False):
                    self.inputIndex = 0
                    if (self.mode == 0):
                        self.menuIndex = min(self.menuIndex + 1, 12)
                    elif (self.mode == 1):
                        self.menuIndex = min(self.menuIndex + 1, 3)
                    elif (self.mode == 2):
                        self.menuIndex = min(self.menuIndex + 1, 6)
                if kbInput.isUpPressed(keys,
                                       False) and not kbInput.isUpPressed(
                                           keysLastFrame, False):
                    self.inputIndex = 0
                    self.menuIndex = max(self.menuIndex - 1, 0)
                if kbInput.isOkayPressed(
                        keys) and not kbInput.isOkayPressed(keysLastFrame):
                    if (self.menuIndex < 3):
                        self.mode = self.menuIndex
                        self.blockMenu = False
                        self.menuIndex = 0
                        self.selIndex = 0
                        self.currentBlockIndex = 0
                    else:
                        if (self.mode == 0):
                            newBlock = None
                            if (self.menuIndex == 3):
                                newBlock = game_objects.CommentBlock()
                            elif (self.menuIndex == 4):
                                newBlock = game_objects.SayBlock()
                            elif (self.menuIndex == 5):
                                newBlock = game_objects.WhileBlock()
                            elif (self.menuIndex == 6):
                                newBlock = game_objects.IfManaBlock()
                            elif (self.menuIndex == 7):
                                newBlock = game_objects.IfOwnHealthBlock()
                            elif (self.menuIndex == 8):
                                newBlock = game_objects.HealBlock(20, 15)
                            elif (self.menuIndex == 9):
                                newBlock = game_objects.FireballBlock(10, 15)
                            elif (self.menuIndex == 10):
                                newBlock = game_objects.MossLeechBlock(10, 15)
                            elif (self.menuIndex == 11):
                                newBlock = game_objects.DouseBlock(10, 15)
                            elif (self.menuIndex == 12):
                                newBlock = game_objects.EndTurnBlock()
                            if (self.insert(newBlock)):
                                self.selIndex += 1
                        elif (self.mode == 2):
                            if (self.menuIndex == 6):
                                self.remove()
                if (self.mode == 1 and self.menuIndex == 3):
                    if (isinstance(self.selBlock, game_objects.CommentBlock)):
                        if kbInput.isLeftPressed(
                                keys, False) and not kbInput.isLeftPressed(
                                    keysLastFrame, False):
                            self.inputIndex = max(self.inputIndex - 1, 0)
                        elif kbInput.isRightPressed(
                                keys, False) and not kbInput.isRightPressed(
                                    keysLastFrame, False):
                            self.inputIndex = min(self.inputIndex + 1,
                                                  len(self.selBlock.comment))
                        newCmmnt, self.inputIndex = kbInput.kbTextInput(
                            keys, keysLastFrame, self.selBlock.comment,
                            self.inputIndex)
                        self.selBlock.setComment(newCmmnt)
                    elif (isinstance(self.selBlock, game_objects.SayBlock)):
                        if kbInput.isLeftPressed(
                                keys, False) and not kbInput.isLeftPressed(
                                    keysLastFrame, False):
                            self.inputIndex = max(self.inputIndex - 1, 0)
                        elif kbInput.isRightPressed(
                                keys, False) and not kbInput.isRightPressed(
                                    keysLastFrame, False):
                            self.inputIndex = min(self.inputIndex + 1,
                                                  len(self.selBlock.message))
                        newMsg, self.inputIndex = kbInput.kbTextInput(
                            keys, keysLastFrame, self.selBlock.message,
                            self.inputIndex)
                        self.selBlock.setMessage(newMsg)
                    elif (isinstance(self.selBlock, game_objects.IfManaBlock)):
                        if kbInput.isLeftPressed(
                                keys, False) and not kbInput.isLeftPressed(
                                    keysLastFrame, False):
                            self.inputIndex = max(self.inputIndex - 1, 0)
                        elif kbInput.isRightPressed(
                                keys, False) and not kbInput.isRightPressed(
                                    keysLastFrame, False):
                            self.inputIndex = min(
                                self.inputIndex + 1,
                                len(str(self.selBlock.mthresh)))
                        newThresh, self.inputIndex = kbInput.kbNumInput(
                            keys, keysLastFrame, self.selBlock.mthresh,
                            self.inputIndex)
                        self.selBlock.setThresh(newThresh)
                    elif (isinstance(self.selBlock,
                                     game_objects.IfOwnHealthBlock)):
                        if kbInput.isLeftPressed(
                                keys, False) and not kbInput.isLeftPressed(
                                    keysLastFrame, False):
                            self.inputIndex = max(self.inputIndex - 1, 0)
                        elif kbInput.isRightPressed(
                                keys, False) and not kbInput.isRightPressed(
                                    keysLastFrame, False):
                            self.inputIndex = min(
                                self.inputIndex + 1,
                                len(str(self.selBlock.hthresh)))
                        newThresh, self.inputIndex = kbInput.kbNumInput(
                            keys, keysLastFrame, self.selBlock.hthresh,
                            self.inputIndex)
                        self.selBlock.setThresh(newThresh)
                    self.inputIndex = max(self.inputIndex, 0)

        else:  # Menu is closed
            if kbInput.isBackPressed(
                    keys) and not kbInput.isBackPressed(keysLastFrame):
                self.manager.go_to(scene.Scenes.INTERACTIVE)
                self.selIndex = 0
            if kbInput.isDownPressed(
                    keys) and not kbInput.isDownPressed(keysLastFrame):
                if (self.mode == 0):
                    self.selIndex = min(self.selIndex + 1,
                                        self.totalArrowCount)
                else:
                    self.selIndex = min(self.selIndex + 1,
                                        self.totalBlockCount - 1)
            if kbInput.isUpPressed(
                    keys) and not kbInput.isUpPressed(keysLastFrame):
                self.selIndex = max(self.selIndex - 1, 0)
            if self.activity == None and kbInput.isMenuPressed(
                    keys) and not kbInput.isMenuPressed(keysLastFrame):
                self.blockMenu = True
        keysLastFrame = keys