本文整理匯總了Python中rectangle.Rectangle.setSize方法的典型用法代碼示例。如果您正苦於以下問題:Python Rectangle.setSize方法的具體用法?Python Rectangle.setSize怎麽用?Python Rectangle.setSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rectangle.Rectangle
的用法示例。
在下文中一共展示了Rectangle.setSize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Vector
# 需要導入模塊: from rectangle import Rectangle [as 別名]
# 或者: from rectangle.Rectangle import setSize [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) + ")"