本文整理汇总了Python中rectangle.Rectangle.collided方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.collided方法的具体用法?Python Rectangle.collided怎么用?Python Rectangle.collided使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rectangle.Rectangle
的用法示例。
在下文中一共展示了Rectangle.collided方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vector
# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import collided [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) + ")"