当前位置: 首页>>代码示例>>Python>>正文


Python HelperFunctions.generateSafeXY方法代码示例

本文整理汇总了Python中HelperFunctions.generateSafeXY方法的典型用法代码示例。如果您正苦于以下问题:Python HelperFunctions.generateSafeXY方法的具体用法?Python HelperFunctions.generateSafeXY怎么用?Python HelperFunctions.generateSafeXY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HelperFunctions的用法示例。


在下文中一共展示了HelperFunctions.generateSafeXY方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateSafeXY [as 别名]
    def __init__(self, gameSettings = None):

        ### --------- initialise pygame and set up the window
        pygame.init()
        pygame.display.set_caption(Config.PAGE_TITLE)
        Config.screen.fill(Config.BACKGROUND_COLOUR)


        self.gameScore = 0

        self.userEscape = False  # User ends game by ESC
        self.gameOver = False  # Game over by death

        self.freezeActiveBallsTimer = 0

        self.clock = pygame.time.Clock()

        ### --------- Generate the snake

        self.snake = Snake_Module.Snake()

        self.snakeSprite = pygame.sprite.Group()
        self.snakeSprite.add(self.snake.get_sections())

        

        # needed for clear/draw
        self.snakeSections = self.snake.get_sections()
        


        ### --------- Initial food

        self.foodGroup  = pygame.sprite.Group()
        # config['food']['standard']['initial']
        for n in range(Config.INITIAL_FOOD_NUM):
            self.foodGroup.add(Food_Module.make_food(self.snake))

        for n in range(Config.INITIAL_FOOD_SUPER_NUM):
            self.foodGroup.add(Food_Module.make_food(self.snake,'FoodSuper'))

        for n in range(Config.INITIAL_FOOD_MYSTERIOUS_NUM):
            self.foodGroup.add(Food_Module.make_food(self.snake, 'FoodMysterious'))

        for n in range(Config.INITIAL_FOOD_CURSE_NUM):
            self.foodGroup.add(Food_Module.make_food(self.snake, 'FoodCurse'))


        ### --------- Initial balls

        self.ballGroup  = pygame.sprite.Group()

        for n in range(Config.INITIAL_BALL_NUM):
            self.ballGroup.add(Ball_Module.BallStandard(HelperFunctions.generateSafeXY(self.snake, self.ballGroup, None, self.foodGroup)))

        self.ballKillerGroup = pygame.sprite.Group()
        if Config.INITIAL_BALL_KILLER_NUM != 0:
            self.ballKillerGroup.add(Ball_Module.BallKiller(HelperFunctions.generateSafeXY(self.snake, self.ballGroup, None, self.foodGroup)))            
开发者ID:jamietanna,项目名称:PySnake,代码行数:60,代码来源:Game_Module.py

示例2: handleRandoms

# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateSafeXY [as 别名]
    def handleRandoms(self):
        time = pygame.time.get_ticks()

        if ((time % Config.RANDOM_FOOD_MYSTERIOUS_CHANCE) == 0):
            print "Random Melon of Mystery generated"
            self.foodGroup.add(Food_Module.FoodMysterious(None, None, None, HelperFunctions.generateSafeXY(self.snake, self.ballGroup, self.ballKillerGroup, self.foodGroup)))
        
        if ((time % Config.RANDOM_FOOD_CURSE_CHANCE) == 0):
            print "Random Berries of Bane generated"
            self.foodGroup.add(Food_Module.FoodCurse(None, None, None, HelperFunctions.generateSafeXY(self.snake, self.ballGroup, self.ballKillerGroup, self.foodGroup)))
开发者ID:jamietanna,项目名称:PySnake,代码行数:12,代码来源:Game_Module.py

示例3: handleCollisions

# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import generateSafeXY [as 别名]
    def handleCollisions(self):
        snakeHead = self.snake.get_head()

        #### FOOD

        ballKiller = killerFromGroup(self.ballKillerGroup)


        collisionsFood = pygame.sprite.spritecollide(snakeHead,
                    self.foodGroup, True)
        if collisionsFood:

            # get the collided food item, then recreate it in a new random, position

            properties = collisionsFood[0].get_properties()

            if properties['autoRespawn']:
                self.foodGroup.add(Food_Module.make_food(self.snake, properties['type'], properties['colour'], properties['size'], properties['effect']))

            if properties['effect']['curse'] == True:
                self.snake.curse_tail()

            if properties['effect']['spawnKiller']:
                # 40% chance
                t = pygame.time.get_ticks()
                
                if self.ballKillerSpawned() == False and (t % 5 == 0 or t % 5 == 1):
                # maybe make the stimulus for a killer ball to be spawned more complicated 
                    self.ballKillerGroup.add(Ball_Module.BallKiller(HelperFunctions.generateSafeXY(self.snake, self.ballGroup, ballKiller, self.foodGroup)))

            if properties['effect']['spawnStandard']:
                if len(self.ballGroup) + 1 < Config.MAX_BALLS:
                    self.ballGroup.add(Ball_Module.BallStandard(HelperFunctions.generateSafeXY(self.snake, self.ballGroup, ballKiller, self.foodGroup)))

            if properties['effect']['freezeBall'] > 0:
                # then no hard coded values, works based on the FPS *not* faster/slower hardware values
                self.freezeActiveBallsTimer += Config.FPS * properties['effect']['freezeBall']

                print "Balls Frozen for " + str(self.freezeActiveBallsTimer)
                
                
            if properties['effect']['removeStandard']:
                print "Removed ball"

                # bad way of removing the first element, but it works and isn't too complicated
                for b in self.ballGroup:
                    self.ballGroup.remove(b)
                    break

            if properties['effect']['removeKiller']:
                print "Removed killer ball"
                if self.ballKillerSpawned():
                    self.ballKillerGroup.empty()

            self.snake.adjust_tail_size(properties['effect']['size'])

            # generate the score based on the score base per the food, how long is left on the food before it expires, 
            # and then divide it by the FPS (as time is in FPS), then apply difficulty bonus
            _S = (float) ((properties['effect']['score'] * properties['time']))
            self.gameScore += int((round(_S / Config.FPS)) * Config.DIFFICULTY_BONUS)


            self.setWindowTitle(str(self.gameScore))

            # update these so we can then redraw them later - only update once we've got a larger snake, otherwise we're wasting CPU!

            self.snakeSprite = pygame.sprite.Group()
            self.snakeSprite.add(self.snake.get_sections())
            self.snakeSections = self.snake.get_sections()

        # only work on collisions with ballKiller if we've got one in play
        # if len(self.ballKillerGroup) > 0:
        ballKiller = killerFromGroup(self.ballKillerGroup)

        if ballKiller != None:
            collisionsFoodKiller = pygame.sprite.spritecollide(ballKiller, self.foodGroup, True)

            if collisionsFoodKiller:
                for f in collisionsFoodKiller:
                    properties = collisionsFoodKiller[0].get_properties()
                    if properties['autoRespawn']:
                        self.foodGroup.add(Food_Module.make_food(self.snake, properties['type'], properties['colour'], properties['size'], properties['effect']))
            
            # don't remove balls, just bounce
            collisionsBallsKiller = pygame.sprite.spritecollide(ballKiller, self.ballGroup, False)    

            if collisionsBallsKiller:
                for b in collisionsBallsKiller:
                    b.collision(ballKiller)
            

        # handle this more quickly
        allBalls = pygame.sprite.Group()

        allBalls.add(self.ballGroup)
        allBalls.add(self.ballKillerGroup)

        if len(allBalls) > 0:
            collisionsBall = pygame.sprite.spritecollide(snakeHead, allBalls, False)
            if collisionsBall:
#.........这里部分代码省略.........
开发者ID:jamietanna,项目名称:PySnake,代码行数:103,代码来源:Game_Module.py


注:本文中的HelperFunctions.generateSafeXY方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。