本文整理汇总了Python中PyQt4.QtGui.QGraphicsPolygonItem.collidingItems方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsPolygonItem.collidingItems方法的具体用法?Python QGraphicsPolygonItem.collidingItems怎么用?Python QGraphicsPolygonItem.collidingItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsPolygonItem
的用法示例。
在下文中一共展示了QGraphicsPolygonItem.collidingItems方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: auto
# 需要导入模块: from PyQt4.QtGui import QGraphicsPolygonItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPolygonItem import collidingItems [as 别名]
class auto(QGraphicsPixmapItem):
def __init__(self, *args):
self.seleccionado = False
self.velocity = random.randint(1,10)
QGraphicsPixmapItem.__init__(self, *args)
self.setPixmap(QPixmap("sprites/"+str(random.randint(1,45))+".png"))
self.setTransformOriginPoint(self.boundingRect().width()/2.0,self.boundingRect().height()/2.0)
self.setZValue(10)
##menu contextual
self.menu = QMenu()
self.Actions =[] #arreglo de acciones
self.Actions.append( self.menu.addAction("Seguir") )
self.Actions.append( self.menu.addAction("Editar") )
self.Actions.append( self.menu.addAction("girar clockwise") )
self.Actions.append( self.menu.addAction("girar anti-clockwise") )
self.Actions.append( self.menu.addAction("Colisiones") )
self.Actions.append( self.menu.addAction("Duplicar") )
self.Actions.append( self.menu.addAction("Eliminar") )
self.menu.triggered[QAction].connect(self.test)
##offset para el arrastre
self.offset= QPointF(0,0)
##poligono de vision
poligono = QPolygonF()
poligono.append(QPointF(-1,10))
poligono.append(QPointF(-1,20))
poligono.append(QPointF(-30,40))
poligono.append(QPointF(-40,15))
poligono.append(QPointF(-30,-10))
self.vision = QGraphicsPolygonItem(poligono,self,self.scene())
self.vision.setBrush(QColor(255, 255, 0,100))
self.vision.setPen(QColor(255, 255, 0))
def info(self):
return "Velocidad "+ str(self.velocity)+" posicion "+ str(self.pos())[20:]+"\n"
def test(self,act):
print act.text()
if act.text()=="girar clockwise":
self.setRotation(self.rotation()-45)
if act.text()=="girar anti-clockwise":
self.setRotation(self.rotation()+45)
if act.text()=="Colisiones":
print "colisiones con",self.collidingItems(1),self.vision.collidingItems(1)
if act.text()=="Duplicar":
self.scene().addItem(auto())
if act.text()=="Eliminar":
self.scene().removeItem(self)
def contextMenuEvent(self,event):
self.menu.popup(event.screenPos())
def mousePressEvent(self, event):
p = event.pos()
self.offset= QPointF(p.x()*1.0,p.y()*1.0)
self.seleccionado = not self.seleccionado
def mouseMoveEvent(self, event):
self.setPos(event.scenePos()-self.offset)
def avanza(self):
if self.velocity !=0:
"""print velocity
print "current pos (%f,%f)"%(self.pos().x(),self.pos().y())
print "angle %f "%(self.rotation())"""
radians = self.rotation()*0.0174532925
""" print "angle rad %f "%(radians)"""
nx = 1.0*self.velocity*cos(radians)
ny = 1.0*self.velocity*sin(radians)
""" print "avanzara a (%f,%f)"%(nx,ny) """
self.setPos(self.pos().x()-nx,self.pos().y()-ny)
"""for i in self.collidingItems():