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


Python Ball.update_position方法代码示例

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


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

示例1: main

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import update_position [as 别名]
def main():
    set_clear_color(1, 1, 1)
    enable_smoothing()
    
    ball = Ball(20, 20, 0, 0, .3, .3, 1.)

    while not window_closed():
        clear()
    
        ball.draw(PIXELS_PER_METER)

        ball.update_position(TIMESTEP)
        ball.update_velocity(TIMESTEP)
   
        request_redraw()
        sleep(TIMESTEP)
开发者ID:CS98,项目名称:TheOneRepo,代码行数:18,代码来源:ball_example2.py

示例2: IceBlocks

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import update_position [as 别名]
class IceBlocks(cocos.layer.ColorLayer):
    is_event_handler = True
    keys_pressed = {}

    def __init__(self):
        super(IceBlocks, self).__init__(*BG_COLOR, a=255)
        self.keys_pressed = []
        self.current_lives = LIVES
        self.level = BlockFactory().get_level(0)
        self.schedule(self.update)

        self.peddle = Peddle()
        self.ball = Ball()
        self.add(self.peddle, z=1)
        self.add(self.ball, z=1)
        self.draw_blocks()
        self.collman = cm.CollisionManagerGrid(0, WINDOW_W,
                                               0, WINDOW_H,
                                               self.width, self.height)
        self.draw_lives()

    def restart_game(self):
        self.remove(self.message)
        self.current_lives = LIVES
        self.level = BlockFactory().get_level(0)
        self.draw_blocks()
        self.draw_lives()
        self.ball.update_position((self.peddle.position[0] +
                                   self.peddle.width / 2, self.peddle.height))
        self.resume_scheduler()

    def blocks_remaining(self):
        count = 0
        for z, node in self.children:
            if isinstance(node, Block):
                count += 1
        return count

    def level_up(self):        
        self.pause_scheduler()
        
        self.ball.update_position((self.peddle.position[0]
                                   + self.peddle.width
                                   / 2, self.peddle.height))
        
        try:
            self.level = BlockFactory().get_level(self.level.level + 1)
        except Exception as ex:
            message, code = ex.args
            if code == 0:
                self.message = MessageLayer()
                self.message.show_message(message, self.restart_game)
                self.add(self.message)
                return


        self.draw_blocks()
        
        self.message = MessageLayer()
        self.message.show_message('Level ' + str(self.level.level
                                                         + 1), self.resume_scheduler)
        self.add(self.message)
        
        #self.draw_blocks()
        
        #self.resume_scheduler()

    def update(self, dt):
        if self.current_lives > -1:
            self.peddle.update(self.keys_pressed)
            result = self.ball.update(self.peddle)
            if result == -1:
                self.current_lives -= 1
                self.update_lives()
                #self.pause_scheduler()

            self.collman.clear()
            for z, node in self.children:
                if isinstance(node, Block):
                    self.collman.add(node)
            for obj in self.collman.objs_colliding(self.ball):
                ball_rcornerx = math.ceil(self.ball.position[0] + self.ball.width)
                ball_rcornery = math.ceil(self.ball.position[1] + self.ball.width)
                ball_lcornerx = math.ceil(self.ball.position[0])
                ball_lcornery = math.ceil(self.ball.position[1])
                block_lcornerx = math.ceil(obj.position[0])
                block_lcornery = math.ceil(obj.position[1])
                block_rcornerx = math.ceil(obj.position[0] + obj.width)
                block_rcornery = math.ceil(obj.position[1] + obj.width)

                if ball_rcornerx <= block_lcornerx :
                    if ball_rcornerx == block_lcornerx and (block_lcornery == (ball_rcornery+self.ball.height) or (block_lcornery+obj.height) == ball_rcornery):
                        self.ball.dx = self.ball.dx * -1
                        self.ball.dy = self.ball.dy * -1
                    else :
                        self.ball.dx = self.ball.dx * -1
                elif ball_lcornerx >= block_rcornerx :
                    if ball_lcornerx == block_rcornerx and (block_rcornery == (ball_lcornery+self.ball.height) or (block_rcornery+obj.height) == ball_lcornery) :
                        self.ball.dx = self.ball.dx * -1
                        self.ball.dy = self.ball.dy * -1
#.........这里部分代码省略.........
开发者ID:sandro93,项目名称:iceblocks,代码行数:103,代码来源:iceblocks.py

示例3: Ball

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import update_position [as 别名]
from ball import Ball  # import the Ball class

# Create a Ball object and store its address in the variable myball.
myball = Ball(5.0, 4.0, 3.0, 6.0)

print "Ball location " + str(myball.x) + ", " + str(myball.y)

# move the ball at current velocity for 0.1 seconds
myball.update_position(0.1) 

print "Ball location " + str(myball.x) + ", " + str(myball.y)
开发者ID:CS98,项目名称:TheOneRepo,代码行数:13,代码来源:move_ball.py


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