int main(int argc, char *argv[])
{
QApplication a(argc, argv);
+ a.setApplicationName("Ghosts Overboard");
+ a.setApplicationVersion("0.0.1");
MainWindow w;
#if defined(Q_WS_S60)
w.showMaximized();
#include <QDebug>
#include <QAction>
#include <QMenuBar>
+#include <QMessageBox>
+#include <QApplication>
{
paused_ = false;
+ setWindowIcon(QIcon(":/pix/laiva_10aave.png"));
+
pScene_ = new SeaScene ();
pView_ = new QGraphicsView ();
menuBar()->addAction(pPauseAction);
QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
- pRestartLevelAction->setCheckable(true);
addAction(pRestartLevelAction);
connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
menuBar()->addAction(pRestartLevelAction);
+ QAction * pAboutAction = new QAction(tr("About"),this);
+ addAction(pAboutAction);
+ connect(pAboutAction,SIGNAL(triggered()),this,SLOT(about()));
+ menuBar()->addAction(pAboutAction);
+
//the boundaries of the scene are set to match the size of the view window, which is not
//available in the constructor --> timer needed
qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
- pScene_->setupMap(5,5,5);
+ pScene_->setupMap(11,5,5);
}
void MainWindow::pause(bool paused)
{
pScene_->setupMap(5,5,5);
}
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()),
+ tr("Version %1"
+ "<p>Copyright 2011 Heli Hyvättinen"
+ "<p>License: General Public License v2"
+ ).arg(QApplication::applicationVersion()));
+
+
+
+}
void initializeBoundaries();
void pause(bool paused);
void restartLevel();
+ void about();
private:
<file>kari.png</file>
<file>aave.png</file>
<file>laiva.png</file>
+ <file>laiva_1aave.png</file>
+ <file>laiva_2aave.png</file>
+ <file>laiva_3aave.png</file>
+ <file>laiva_4aave.png</file>
+ <file>laiva_5aave.png</file>
+ <file>laiva_6aave.png</file>
+ <file>laiva_7aave.png</file>
+ <file>laiva_8aave.png</file>
+ <file>laiva_9aave.png</file>
+ <file>laiva_10aave.png</file>
</qresource>
</RCC>
return;
}
- Ship * pShip = new Ship (QPixmap(":/pix/laiva.png"));
+ QList<QPixmap> shipImages;
+ shipImages.append(QPixmap(":/pix/laiva.png"));
+ shipImages.append(QPixmap(":/pix/laiva_1aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_2aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_3aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_4aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_5aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_6aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_7aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_8aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_9aave.png"));
+ shipImages.append(QPixmap(":/pix/laiva_10aave.png"));
+
+ Ship * pShip = new Ship (shipImages);
pShip->setData(0,"ship");
pShip->setPos(*pPosition);
addItem(pShip);
#include "ship.h"
#include <QDebug>
-Ship::Ship(QPixmap pixmap, QGraphicsItem *parent) :
- OrientationControlledGraphicsPixmapObject(pixmap,parent)
+Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
+ OrientationControlledGraphicsPixmapObject(pixmapList.at(0),parent)
{
+ shipImages_ = pixmapList;
ghostsAboard_ = 0;
}
// drop all ghosts when hitting an obstacle
emit droppingGhosts(ghostsAboard_);
ghostsAboard_ = 0;
+ updateShipImage();
return false;
}
else if (type == "ghost")
{
ghostsAboard_++;
+ updateShipImage();
qDebug() << ghostsAboard_ << " ghosts aboard";
}
}
+
+void Ship::updateShipImage()
+{
+ int index = qBound(0,ghostsAboard_,shipImages_.length()-1);
+ setPixmap(shipImages_.at(index));
+}
class Ship : public OrientationControlledGraphicsPixmapObject
{
- Q_OBJECT
+
+ Q_OBJECT
public:
- explicit Ship(QPixmap pixmap = 0, QGraphicsItem *parent = 0);
+ explicit Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent = 0);
signals:
/*! Emitted when a ghost is hit */
void pickingGhost(QGraphicsItem* pGhost);
+
+
/*! Emitted when ghosts fall over board */
void droppingGhosts (int ghosts);
protected:
bool handleCollisions();
+ void updateShipImage();
+
int ghostsAboard_;
+ QList<QPixmap> shipImages_;
+
};