本文整理匯總了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():