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


Python Rectangle.move方法代码示例

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


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

示例1: RectangleTest

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import move [as 别名]
class RectangleTest(TestCase):

    def setUp(self):
        self.rectangle = Rectangle(1, 2, 3, 4)

    def test_getLength(self):
        assert_equal(self.rectangle.getLength(), 2)

    def test_getHeight(self):
        assert_equal(self.rectangle.getHeight(), 2)

    def test_getArea(self):
        assert_equal(self.rectangle.getArea(), 4)

    def test_move(self):
        self.rectangle.move(4, 8)
        self.test_getLength()
        self.test_getHeight()
        self.test_getArea()
开发者ID:cpatrick,项目名称:cython-cmake-example,代码行数:21,代码来源:rectangle_test.py

示例2: Rectangle

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import move [as 别名]
from rectangle import Rectangle
r = Rectangle(1, 2, 3, 4)
print r
print "Original area:", r.getArea()
r.move(1,2)
print r
print "Area is invariante under rigid motions:", r.getArea()
r += Rectangle(0,0,1,1)
print r
print "Now the aread is:", r.getArea()
r.setsize(3)
print r.getsize()
开发者ID:imsejae,项目名称:pyclaw,代码行数:14,代码来源:ustri.py

示例3: Vector

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import move [as 别名]
class Entity:
    """
    Game entity which can by a map object, item, robot etc.
    """
    # image file locations in filesystem, list item id number == entity id number
    # default = 0
    # floor = 1
    # barrel = 2
    # small crate = 3
    # medium crate = 4
    # high crate = 5
    # dump = 6
    # forklift = 7
    imageLocations = ["../Assets/default.png",
                      "../Assets/floor.png",
                      "../Assets/barrel.png",
                      "../Assets/large_crate.png",
                      "../Assets/large_crate.png",
                      "../Assets/large_crate.png",
                      "../Assets/forklift_up.png",
                      "../Assets/forklift_right.png",
                      "../Assets/forklift_down.png",
                      "../Assets/forklift_left.png"]

    # image sizes are normalized to range [0,1]
    imageSizes = [Vector(32/GAME_SCREEN_WIDTH,32/GAME_SCREEN_HEIGHT),
                  Vector(GAME_SCREEN_WIDTH/GAME_SCREEN_WIDTH,GAME_SCREEN_WIDTH/GAME_SCREEN_HEIGHT),
                  Vector(32/GAME_SCREEN_WIDTH,32/GAME_SCREEN_HEIGHT),
                  Vector(32/GAME_SCREEN_WIDTH,32/GAME_SCREEN_HEIGHT),
                  Vector(64/GAME_SCREEN_WIDTH,64/GAME_SCREEN_HEIGHT),
                  Vector(96/GAME_SCREEN_WIDTH,96/GAME_SCREEN_HEIGHT),
                  Vector(48/GAME_SCREEN_WIDTH,48/GAME_SCREEN_HEIGHT),
                  Vector(48/GAME_SCREEN_WIDTH,48/GAME_SCREEN_HEIGHT),
                  Vector(48/GAME_SCREEN_WIDTH,48/GAME_SCREEN_HEIGHT),
                  Vector(48/GAME_SCREEN_WIDTH,48/GAME_SCREEN_HEIGHT)]

    def __init__(self,x, y, id):
        self.sprite = Image(source=self.imageLocations[id])
        self.sprite.allow_stretch = True
        self.sprite.auto_bring_to_front = False
        self.id = id
        self.bounds = Rectangle(x,y,self.imageSizes[id].x,self.imageSizes[id].y)
        self.setSize(self.imageSizes[id].x, self.imageSizes[id].y)
        self.setPosition(x,y)

    def addToLayout(self, layout):
        """
        :param layout: Adds widget to specified layout
        :return:
        """
        layout.remove_widget(self.sprite)
        layout.add_widget(self.sprite)

    def collided(self, other):
        if(self.bounds.collided(other.bounds)):
            return True
        else:
            return False

    def setSprite(self, sprite):
        self.sprite = sprite

    def move(self,x,y):
        self.bounds.move(x,y)
        self.sprite.pos[0] += x
        self.sprite.pos[1] += y
        self.sprite.pos_hint = {'center_x' : self.bounds.center.x, 'center_y' : self.bounds.center.y}

    def setSize(self, width, height):
        self.sprite.size_hint = (width, height)
        self.bounds.setSize(width,height)

    def setPosition(self, x, y):
        self.bounds.setPosition(x,y)
        self.sprite.pos = (x,y)
        self.sprite.pos_hint = {'center_x' : x, 'center_y' : y}

    def __eq__(self, other):
        if(self.bounds.position.x == other.bounds.position.x and
           self.bounds.position.y == other.bounds.position.y and
           self.bounds.size.x == other.bounds.size.x and
           self.bounds.size.y == other.bounds.size.y):
            return True
        else:
            return False


    def __str__(self):
        return "Entity ID: " + str(self.id) + ", X,Y: (" + str(self.bounds.position.x) + ", " + str(self.bounds.position.y) + ")"
开发者ID:EdvinasKilbauskas,项目名称:BargainHunt,代码行数:91,代码来源:entities.py


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