當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。