class PowerUp(QtGui.QGraphicsRectItem):
def __init__(self):
QtGui.QGraphicsRectItem.__init__(self)
self.images = ['data/images/objects/bonus_block/full-0.png',
'data/images/objects/bonus_block/full-1.png',
'data/images/objects/bonus_block/full-2.png',
'data/images/objects/bonus_block/full-3.png',
'data/images/objects/bonus_block/full-4.png']
self.image = self.images[0]
self.current = 0
self.position()
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.animation_step)
self.timer.start(175)
#random.choice([slide(), ghost()])
def position(self):
self.pos_x = random.randint(-300, 300)
self.pos_y = random.randint(-200, 200)
def boundingRect(self):
return QtCore.QRectF(0, 0, 32, 32)
def paint(self, painter, option, widget):
painter.setBrush(QtGui.QBrush(self.image))
painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
painter.drawRect(0, 0, 32, 32)
self.setPos(self.pos_x, self.pos_y)
def animation_step(self):
self.image = QtGui.QPixmap(self.images[self.current])
self.current += 1
if self.current == len(self.images):
self.current = 0