1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
MovementInput::MovementInput(bool t)
{
type = t;
if(type)
{
setRect(150,300,60,60);
}
else
{
setRect(450,300,60,60);
}
}
void MovementInput::keyPressEvent(QKeyEvent *event)
{
if(type)
{
if(event->key() == Qt::Key_Left)
{
setPos(x() - 5, y());
}
if(event->key() == Qt::Key_Right)
{
setPos(x() + 5, y());
}
if(event->key() == Qt::Key_Up)
{
setPos(x(), y() - 5);
}
if(event->key() == Qt::Key_Down)
{
setPos(x(), y() + 5);
}
}
else
{
if(event->key() == Qt::Key_A)
{
setPos(x() - 5, y());
}
if(event->key() == Qt::Key_D)
{
setPos(x() + 5, y());
}
if(event->key() == Qt::Key_W)
{
setPos(x(), y() - 5);
}
if(event->key() == Qt::Key_S)
{
setPos(x(), y() + 5);
}
}
QList<QGraphicsItem*> colliding_items = collidingItems();
int n = colliding_items.size();
for(int i=0; i<n; ++i)
{
qDebug() << "Collision Detected";
}
}
|