當前位置: 首頁>>代碼示例>>Python>>正文


Python Rectangle.setPosition方法代碼示例

本文整理匯總了Python中rectangle.Rectangle.setPosition方法的典型用法代碼示例。如果您正苦於以下問題:Python Rectangle.setPosition方法的具體用法?Python Rectangle.setPosition怎麽用?Python Rectangle.setPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rectangle.Rectangle的用法示例。


在下文中一共展示了Rectangle.setPosition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Vector

# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import setPosition [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.setPosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。