summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederik Schwarzer <[email protected]>2016-04-26 02:00:40 +0200
committerFrederik Schwarzer <[email protected]>2016-04-26 02:00:40 +0200
commitba34ed874b289fbd89f8ac5a0e31452327e3c8ff (patch)
treece86a0dee04d3275a995483ec5526e96de73d669
parentc6598414500786a71aef74f5db284f088a940d82 (diff)
Format.
-rw-r--r--src/board.cpp43
-rw-r--r--src/board.h29
-rw-r--r--src/bomb.cpp7
-rw-r--r--src/bomb.h6
-rw-r--r--src/bomber.cpp65
-rw-r--r--src/bomber.h12
-rw-r--r--src/bomberwidget.cpp94
-rw-r--r--src/bomberwidget.h23
-rw-r--r--src/building.cpp21
-rw-r--r--src/building.h12
-rw-r--r--src/explodable.cpp24
-rw-r--r--src/explodable.h14
-rw-r--r--src/main.cpp4
-rw-r--r--src/plane.cpp6
-rw-r--r--src/plane.h5
15 files changed, 188 insertions, 177 deletions
diff --git a/src/board.cpp b/src/board.cpp
index f4ae25f..3f4e7e9 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -17,18 +17,18 @@
*/
#include "board.h"
-#include "plane.h"
-#include "building.h"
#include "bomb.h"
+#include "building.h"
+#include "plane.h"
#include "settings.h"
#include <KRandom>
-#include <QTimer>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QStandardPaths>
+#include <QTimer>
/** The value that the plane velocity increases by */
const qreal PLANE_INC_VELOCITY = 0.0005;
@@ -49,8 +49,11 @@ const unsigned int PLANE_EXPLODE_TIME = 2000;
/** This time in milliseconds that the bomb exploding animation is played for */
const unsigned int BOMB_EXPLODE_TIME = 1000;
-BomberBoard::BomberBoard(KGameRenderer *renderer, QGraphicsView *view, QObject *parent) :
- QGraphicsScene(parent), m_renderer(renderer), m_bomb(nullptr), m_view(view)
+BomberBoard::BomberBoard(KGameRenderer * renderer, QGraphicsView * view, QObject * parent)
+ : QGraphicsScene(parent)
+ , m_renderer(renderer)
+ , m_bomb(nullptr)
+ , m_view(view)
{
m_clock = new QTimer(this);
m_clock->setInterval(GAME_DELAY);
@@ -77,7 +80,7 @@ void BomberBoard::resetPlane()
m_plane->resetPosition();
}
-void BomberBoard::resize(QSize &size)
+void BomberBoard::resize(QSize & size)
{
setBackgroundBrush(m_renderer->spritePixmap(QLatin1Literal("background"), size));
@@ -86,7 +89,7 @@ void BomberBoard::resize(QSize &size)
m_tileSize = QSize(minTileSizeWidth, minTileSizeHeight);
- foreach (Building *building, m_buildings) {
+ foreach (Building * building, m_buildings) {
building->resize(m_tileSize);
}
@@ -166,7 +169,7 @@ void BomberBoard::tick()
m_bomb->advanceItem();
}
- foreach (Bomb *bomb, m_explodingBombs) {
+ foreach (Bomb * bomb, m_explodingBombs) {
bomb->advanceItem();
}
@@ -177,7 +180,7 @@ void BomberBoard::tick()
m_bomb->update();
}
- foreach (Bomb *bomb, m_explodingBombs) {
+ foreach (Bomb * bomb, m_explodingBombs) {
bomb->update();
}
}
@@ -194,9 +197,8 @@ void BomberBoard::dropBomb()
void BomberBoard::checkCollisions()
{
- foreach (Building *building, m_buildings) {
- if (m_plane->nextBoundingRect().intersects(building->boundingRect()) && m_plane->state()
- == Explodable::State::Moving) {
+ foreach (Building * building, m_buildings) {
+ if (m_plane->nextBoundingRect().intersects(building->boundingRect()) && m_plane->state() == Explodable::State::Moving) {
// Plane crashed into the building
building->destoryTop();
--m_buildingBlocks;
@@ -204,8 +206,7 @@ void BomberBoard::checkCollisions()
}
if (m_bomb != nullptr) {
- if (m_bomb->nextBoundingRect().intersects(building->boundingRect()) && m_bomb->state()
- == Explodable::State::Moving) {
+ if (m_bomb->nextBoundingRect().intersects(building->boundingRect()) && m_bomb->state() == Explodable::State::Moving) {
// Bomb hit a building
building->destoryTop();
--m_buildingBlocks;
@@ -225,7 +226,7 @@ void BomberBoard::checkCollisions()
}
}
-void BomberBoard::bombHit(Bomb *bomb, qreal moveBombToX, qreal moveBombToY)
+void BomberBoard::bombHit(Bomb * bomb, qreal moveBombToX, qreal moveBombToY)
{
bomb->setPosition(moveBombToX, moveBombToY);
bomb->setState(Bomb::State::Exploding);
@@ -236,7 +237,7 @@ void BomberBoard::bombHit(Bomb *bomb, qreal moveBombToX, qreal moveBombToY)
void BomberBoard::bombExploded()
{
- Bomb *bomb = m_explodingBombs.dequeue();
+ Bomb * bomb = m_explodingBombs.dequeue();
bomb->hide();
delete bomb;
}
@@ -273,14 +274,12 @@ void BomberBoard::clear()
resetPlane();
}
-QPoint BomberBoard::mapPosition(const QPointF &pos) const
+QPoint BomberBoard::mapPosition(const QPointF & pos) const
{
- return QPoint(static_cast<unsigned int>(m_tileSize.width() * pos.x()),
- static_cast<int>(m_tileSize.height() * pos.y()));
+ return QPoint(static_cast<unsigned int>(m_tileSize.width() * pos.x()), static_cast<int>(m_tileSize.height() * pos.y()));
}
-QPointF BomberBoard::unmapPosition(const QPoint &pos) const
+QPointF BomberBoard::unmapPosition(const QPoint & pos) const
{
- return QPointF(1.0 * pos.x() / m_tileSize.width(), 1.0 * pos.y()
- / m_tileSize.height());
+ return QPointF(1.0 * pos.x() / m_tileSize.width(), 1.0 * pos.y() / m_tileSize.height());
}
diff --git a/src/board.h b/src/board.h
index 28d7af7..44bc3bf 100644
--- a/src/board.h
+++ b/src/board.h
@@ -18,13 +18,13 @@
#ifndef BOARD_H
#define BOARD_H
-#include <QGraphicsScene>
#include <KGameRenderer>
+#include <QGraphicsScene>
-#include <QSize>
+#include <QDir>
#include <QList>
#include <QQueue>
-#include <QDir>
+#include <QSize>
class Plane;
class Building;
@@ -34,19 +34,18 @@ class Bomb;
* This class used to represent the game board. This makes sure all the game objects
* get moved and redrawn every second. It also checks for any collisions
*/
-class BomberBoard: public QGraphicsScene
+class BomberBoard : public QGraphicsScene
{
Q_OBJECT
public:
-
/**
* The constructor used to create the board.
* \param renderer The renderer used to render game objects
* \param view The graphics view object which this board is bound to
* \param parent The widget which the board is inserted into
*/
- explicit BomberBoard(KGameRenderer *renderer, QGraphicsView *view, QObject *parent = nullptr);
+ explicit BomberBoard(KGameRenderer * renderer, QGraphicsView * view, QObject * parent = nullptr);
~BomberBoard();
@@ -54,7 +53,7 @@ public:
* This is called when the game board is resized
* \param size The new tile size used on the game board
*/
- void resize(QSize &size);
+ void resize(QSize & size);
/**
* This will redraw the game board
@@ -78,14 +77,14 @@ public:
* \param pos The cords relative to the tile
* \return The cords relative to the widget
*/
- QPoint mapPosition(const QPointF &pos) const;
+ QPoint mapPosition(const QPointF & pos) const;
/**
* This will convert the widget location to tile locations
* \param pos The cords relative to the widget
* \return The cords relative to the tile
*/
- QPointF unmapPosition(const QPoint &pos) const;
+ QPointF unmapPosition(const QPoint & pos) const;
/**
* Used to set the plane state to flying and move it to the start position
@@ -146,7 +145,7 @@ private:
* \param moveBombToX The x position to move the explosion too
* \param moveBombToY The y position to move the explosion too
*/
- void bombHit(Bomb *bomb, qreal moveBombToX, qreal moveBombToY);
+ void bombHit(Bomb * bomb, qreal moveBombToX, qreal moveBombToY);
/**
* This is used to remove all the current game objects, usually called before
@@ -167,23 +166,23 @@ private:
/**
* This is the renderer used to render game objects
*/
- KGameRenderer *m_renderer;
+ KGameRenderer * m_renderer;
/**
* This is the size of a tiling block
*/
QSize m_tileSize;
- QTimer *m_clock;
+ QTimer * m_clock;
/**
* If their is a bomb currently dropping then it is pointed to by this
*/
- Bomb *m_bomb;
+ Bomb * m_bomb;
/**
* This points to the plane object used in the level
*/
- Plane *m_plane;
+ Plane * m_plane;
/**
* This contains all the buildings in the current level
@@ -203,7 +202,7 @@ private:
/**
* This is the graphics view object which this board is bound.
*/
- QGraphicsView *m_view;
+ QGraphicsView * m_view;
};
#endif
diff --git a/src/bomb.cpp b/src/bomb.cpp
index 2147998..6b83bbb 100644
--- a/src/bomb.cpp
+++ b/src/bomb.cpp
@@ -27,10 +27,9 @@ const qreal DEFAULT_VELOCITY = 0.2;
const qreal Bomb::BOMB_RELATIVE_SIZE_H = 0.7;
const qreal Bomb::BOMB_RELATIVE_SIZE_W = 0.2;
-Bomb::Bomb(KGameRenderer *renderer, BomberBoard *board, qreal xPos,
- qreal yPos, const QSize &tileSize) :
- Explodable(QLatin1Literal("bomb"), QLatin1Literal("bomb_explode"), BOMB_RELATIVE_SIZE_W,
- BOMB_RELATIVE_SIZE_H, renderer, board)
+Bomb::Bomb(KGameRenderer * renderer, BomberBoard * board, qreal xPos, qreal yPos, const QSize & tileSize)
+ : Explodable(QLatin1Literal("bomb"), QLatin1Literal("bomb_explode"), BOMB_RELATIVE_SIZE_W,
+ BOMB_RELATIVE_SIZE_H, renderer, board)
{
setVelocity(DEFAULT_VELOCITY);
setPosition(xPos, yPos);
diff --git a/src/bomb.h b/src/bomb.h
index e36826f..ee0c706 100644
--- a/src/bomb.h
+++ b/src/bomb.h
@@ -24,7 +24,7 @@
* This is the bomb game object class. It extends Explodable as it
* is a explodable object.
*/
-class Bomb: public Explodable
+class Bomb : public Explodable
{
public:
/** The width of the bomb relative to the tile */
@@ -32,8 +32,8 @@ public:
/** The height of the bomb relative to the tile */
static const qreal BOMB_RELATIVE_SIZE_H;
- Bomb(KGameRenderer *renderer, BomberBoard *board, qreal xPos, qreal yPos,
- const QSize &tileSize);
+ Bomb(KGameRenderer * renderer, BomberBoard * board, qreal xPos, qreal yPos,
+ const QSize & tileSize);
~Bomb();
/**
diff --git a/src/bomber.cpp b/src/bomber.cpp
index 8e0f0df..b5ee5c5 100644
--- a/src/bomber.cpp
+++ b/src/bomber.cpp
@@ -20,24 +20,24 @@
#include "bomberwidget.h"
#include "settings.h"
-#include <QAction>
#include <KActionCollection>
#include <KLocalizedString>
#include <KMessageBox>
-#include <krandom.h>
+#include <KScoreDialog>
#include <KToggleAction>
-#include <QStatusBar>
+#include <QAction>
#include <QLabel>
-#include <kstandardgameaction.h>
-#include <KScoreDialog>
+#include <QStatusBar>
#include <kgthemeselector.h>
+#include <krandom.h>
+#include <kstandardgameaction.h>
Bomber::Bomber()
{
m_provider.discoverThemes(
"appdata", QLatin1String("themes"), //theme data location
- QLatin1String("kbomber") //default theme name
- );
+ QLatin1String("kbomber")); //default theme name
+
m_selector = new KgThemeSelector(&m_provider);
m_statusBar = statusBar();
@@ -89,7 +89,7 @@ void Bomber::initXMLUI()
actionCollection()->addAction(QLatin1String("toggle_sound"), m_soundAction);
connect(m_soundAction, &KToggleAction::triggered, m_gameWidget, &BomberGameWidget::setSoundsEnabled);
- QAction *dropBombAction = actionCollection()->addAction(QLatin1String("drop_bomb"));
+ QAction * dropBombAction = actionCollection()->addAction(QLatin1String("drop_bomb"));
dropBombAction->setText(i18nc("The name of the action used for dropping bombs", "&Drop bomb"));
dropBombAction->setToolTip(i18nc("The tool tip text for the action used to drop bombs", "Drop bomb"));
dropBombAction->setWhatsThis(i18nc("Description of the action used to drop bombs",
@@ -110,7 +110,7 @@ void Bomber::newGame()
// Check for running game
closeGame();
if (m_gameWidget->state() == BomberGameWidget::State::BeforeFirstGame
- || m_gameWidget->state() == BomberGameWidget::State::GameOver) {
+ || m_gameWidget->state() == BomberGameWidget::State::GameOver) {
m_gameWidget->newGame();
}
}
@@ -127,7 +127,7 @@ void Bomber::pauseGame()
void Bomber::closeGame()
{
if (m_gameWidget->state() == BomberGameWidget::State::BeforeFirstGame
- || m_gameWidget->state() == BomberGameWidget::State::GameOver) {
+ || m_gameWidget->state() == BomberGameWidget::State::GameOver) {
return;
}
@@ -136,7 +136,8 @@ void Bomber::closeGame()
m_gameWidget->setPaused(true);
}
int ret = KMessageBox::questionYesNo(this, i18nc("Message displayed when player tries to quit a game that is currently running",
- "Do you really want to close the running game?"), QString(),
+ "Do you really want to close the running game?"),
+ QString(),
KStandardGuiItem::close(), KStandardGuiItem::cancel());
if (ret == KMessageBox::Yes) {
m_gameWidget->closeGame();
@@ -174,41 +175,41 @@ void Bomber::highscore()
void Bomber::displayLevel(unsigned int level)
{
m_level->setText(i18nc(
- "Used to display the current level of play to the user",
- "Level: %1", level));
+ "Used to display the current level of play to the user",
+ "Level: %1", level));
}
void Bomber::displayScore(unsigned int score)
{
m_score->setText(i18nc(
- "Used to inform the user of their current score", "Score: %1",
- score));
+ "Used to inform the user of their current score", "Score: %1",
+ score));
}
void Bomber::displayLives(unsigned int lives)
{
m_lives->setText(i18nc(
- "Used to tell the user how many lives they have left", "Lives: %1",
- lives));
+ "Used to tell the user how many lives they have left", "Lives: %1",
+ lives));
}
void Bomber::gameStateChanged(BomberGameWidget::State state)
{
switch (state) {
- case BomberGameWidget::State::Paused:
- m_pauseAction->setChecked(true);
- m_statusBar->clearMessage();
- break;
- case BomberGameWidget::State::Running:
- m_pauseAction->setChecked(false);
- m_statusBar->clearMessage();
- break;
- case BomberGameWidget::State::GameOver:
- m_statusBar->showMessage(i18nc("Game over messaged displayed in the status bar", "Game over. Press '%1' for a new game",
- m_newAction->shortcuts().first().toString(QKeySequence::NativeText)));
- highscore();
- break;
- default:
- break;
+ case BomberGameWidget::State::Paused:
+ m_pauseAction->setChecked(true);
+ m_statusBar->clearMessage();
+ break;
+ case BomberGameWidget::State::Running:
+ m_pauseAction->setChecked(false);
+ m_statusBar->clearMessage();
+ break;
+ case BomberGameWidget::State::GameOver:
+ m_statusBar->showMessage(i18nc("Game over messaged displayed in the status bar", "Game over. Press '%1' for a new game",
+ m_newAction->shortcuts().first().toString(QKeySequence::NativeText)));
+ highscore();
+ break;
+ default:
+ break;
}
}
diff --git a/src/bomber.h b/src/bomber.h
index 3a964ca..d302d5e 100644
--- a/src/bomber.h
+++ b/src/bomber.h
@@ -20,8 +20,8 @@
#include "bomberwidget.h"
-#include <kxmlguiwindow.h>
#include <kgthemeprovider.h>
+#include <kxmlguiwindow.h>
class QAction;
class QStatusBar;
@@ -35,7 +35,7 @@ class QLabel;
*
* @short Main window class
*/
-class Bomber: public KXmlGuiWindow
+class Bomber : public KXmlGuiWindow
{
Q_OBJECT
public:
@@ -61,13 +61,13 @@ private:
void setupActions();
KgThemeProvider m_provider;
- KgThemeSelector *m_selector;
+ KgThemeSelector * m_selector;
- BomberGameWidget *m_gameWidget;
- QStatusBar *m_statusBar;
+ BomberGameWidget * m_gameWidget;
+ QStatusBar * m_statusBar;
KToggleAction *m_pauseAction, *m_backgroundShowAction, *m_soundAction;
- QAction *m_newAction;
+ QAction * m_newAction;
QLabel *m_level, *m_score, *m_lives;
};
diff --git a/src/bomberwidget.cpp b/src/bomberwidget.cpp
index e836291..8e981da 100644
--- a/src/bomberwidget.cpp
+++ b/src/bomberwidget.cpp
@@ -19,9 +19,9 @@
#include "bomberwidget.h"
#include "settings.h"
-#include <QTimer>
-#include <QGraphicsView>
#include <QGraphicsItem>
+#include <QGraphicsView>
+#include <QTimer>
#include <KLocalizedString>
#include <sys/stat.h>
@@ -36,11 +36,15 @@ static const unsigned int TICKS_PER_SECOND = 1000 / GAME_TIME_DELAY;
/** The z-value for overlays */
static const unsigned int OVERLAY_Z_VALUE = 1000;
-BomberGameWidget::BomberGameWidget(KgThemeProvider *provider, QWidget *parent) :
- QGraphicsView(parent), m_state(State::BeforeFirstGame), m_level(0), m_lives(0), m_time(0),
- m_renderer(provider),
- m_soundBomb((QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("bomber/sounds/bomb.ogg")))),
- m_soundCrash((QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("bomber/sounds/crash.ogg"))))
+BomberGameWidget::BomberGameWidget(KgThemeProvider * provider, QWidget * parent)
+ : QGraphicsView(parent)
+ , m_state(State::BeforeFirstGame)
+ , m_level(0)
+ , m_lives(0)
+ , m_time(0)
+ , m_renderer(provider)
+ , m_soundBomb((QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("bomber/sounds/bomb.ogg"))))
+ , m_soundCrash((QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("bomber/sounds/crash.ogg"))))
{
// Gameboard
m_board = new BomberBoard(&m_renderer, this, this);
@@ -211,7 +215,7 @@ void BomberGameWidget::tick()
}
}
-void BomberGameWidget::resizeEvent(QResizeEvent *ev)
+void BomberGameWidget::resizeEvent(QResizeEvent * ev)
{
QSize boardSize = ev->size();
m_board->resize(boardSize);
@@ -239,7 +243,7 @@ void BomberGameWidget::newLevel()
redraw();
}
-void BomberGameWidget::mouseReleaseEvent(QMouseEvent *event)
+void BomberGameWidget::mouseReleaseEvent(QMouseEvent * event)
{
if (event->button() & Qt::LeftButton) {
onDropBomb();
@@ -262,28 +266,28 @@ void BomberGameWidget::redraw()
if (size().isEmpty()) {
return;
}
- QGraphicsItem *item;
+ QGraphicsItem * item;
switch (m_state) {
- case State::BeforeFirstGame:
- foreach (item, m_board->items()) {
- item->hide();
- }
- generateOverlay();
- m_overlay->show();
- break;
- case State::Running:
- foreach (item, m_board->items()) {
- item->show();
- }
- m_overlay->hide();
- break;
- default:
- foreach (item, m_board->items()) {
- item->show();
- }
- generateOverlay();
- m_overlay->show();
- break;
+ case State::BeforeFirstGame:
+ foreach (item, m_board->items()) {
+ item->hide();
+ }
+ generateOverlay();
+ m_overlay->show();
+ break;
+ case State::Running:
+ foreach (item, m_board->items()) {
+ item->show();
+ }
+ m_overlay->hide();
+ break;
+ default:
+ foreach (item, m_board->items()) {
+ item->show();
+ }
+ generateOverlay();
+ m_overlay->show();
+ break;
}
m_board->redraw();
update();
@@ -305,21 +309,21 @@ void BomberGameWidget::generateOverlay()
QString text;
switch (m_state) {
- case State::BeforeFirstGame:
- text = i18nc("Message show to the user when the game is loaded", "Welcome to Bomber.\nClick to start a game");
- break;
- case State::Paused:
- text = i18nc("Message show to the user while the game is paused", "Paused");
- break;
- case State::BetweenLevels:
- text = i18nc("Message telling user which level they just completed", "You have successfully cleared level %1\n", m_level - 1)
- + i18nc("Message telling user which level they are about to start", "On to level %1.", m_level);
- break;
- case State::GameOver:
- text = i18nc("Used to tell the user that the game is over", "Game over.");
- break;
- default:
- text.clear();
+ case State::BeforeFirstGame:
+ text = i18nc("Message show to the user when the game is loaded", "Welcome to Bomber.\nClick to start a game");
+ break;
+ case State::Paused:
+ text = i18nc("Message show to the user while the game is paused", "Paused");
+ break;
+ case State::BetweenLevels:
+ text = i18nc("Message telling user which level they just completed", "You have successfully cleared level %1\n", m_level - 1)
+ + i18nc("Message telling user which level they are about to start", "On to level %1.", m_level);
+ break;
+ case State::GameOver:
+ text = i18nc("Used to tell the user that the game is over", "Game over.");
+ break;
+ default:
+ text.clear();
}
QFont font;
diff --git a/src/bomberwidget.h b/src/bomberwidget.h
index 6fa8319..be67af9 100644
--- a/src/bomberwidget.h
+++ b/src/bomberwidget.h
@@ -32,7 +32,7 @@ class KgThemeProvider;
/**
* This is the main game widget class. It manages things like the lives, source counts and game states.
*/
-class BomberGameWidget: public QGraphicsView
+class BomberGameWidget : public QGraphicsView
{
Q_OBJECT
@@ -40,10 +40,14 @@ public:
/**
* The different states that the game can be in
*/
- enum class State
- { BeforeFirstGame, Running, BetweenLevels, Paused, Suspended, GameOver};
+ enum class State { BeforeFirstGame,
+ Running,
+ BetweenLevels,
+ Paused,
+ Suspended,
+ GameOver };
- explicit BomberGameWidget(KgThemeProvider *provider, QWidget *parent = nullptr);
+ explicit BomberGameWidget(KgThemeProvider * provider, QWidget * parent = nullptr);
~BomberGameWidget();
/**
@@ -162,8 +166,8 @@ private slots:
void onPlaneCrashed();
private:
- virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
- virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+ virtual void resizeEvent(QResizeEvent * event) Q_DECL_OVERRIDE;
+ virtual void mouseReleaseEvent(QMouseEvent * event) Q_DECL_OVERRIDE;
/**
* Create the overlay used to display info to the user. The info will
@@ -183,16 +187,17 @@ private:
unsigned int m_score;
unsigned int m_lives;
unsigned int m_time;
+
/**
* Used to store the remaining score before a new life is given
*/
int m_scoreLeftBeforeNewLife;
KGameRenderer m_renderer;
- QTimer *m_clock;
- BomberBoard *m_board;
+ QTimer * m_clock;
+ BomberBoard * m_board;
- QGraphicsPixmapItem *m_overlay;
+ QGraphicsPixmapItem * m_overlay;
KgSound m_soundBomb;
KgSound m_soundCrash;
diff --git a/src/building.cpp b/src/building.cpp
index c1147fb..18dfaf1 100644
--- a/src/building.cpp
+++ b/src/building.cpp
@@ -36,9 +36,12 @@ const qreal BUILDING_RELATIVE_HEIGHT = 1.0;
/** The vertical tile number of the bottom tile in the building */
const unsigned int Building::BUILD_BASE_LOCATION = 16;
-Building::Building(KGameRenderer *renderer, BomberBoard *board, unsigned int position,
- unsigned int height) :
- m_height(0), m_renderer(renderer), m_board(board), m_xPos(position)
+Building::Building(KGameRenderer * renderer, BomberBoard * board, unsigned int position,
+ unsigned int height)
+ : m_height(0)
+ , m_renderer(renderer)
+ , m_board(board)
+ , m_xPos(position)
{
setHeight(height);
setupBuildingTiles();
@@ -46,7 +49,7 @@ Building::Building(KGameRenderer *renderer, BomberBoard *board, unsigned int pos
Building::~Building()
{
- foreach (KGameRenderedItem *tile, m_buildingTiles) {
+ foreach (KGameRenderedItem * tile, m_buildingTiles) {
m_board->removeItem(tile);
}
qDeleteAll(m_buildingTiles);
@@ -92,12 +95,12 @@ void Building::setupBuildingTiles()
const QString pixmap = QString::fromLatin1("roof_%1_0").arg(style);
m_buildingTiles.append(createBuildingTile(pixmap));
m_boundingRect.moveTo(m_xPos, BUILD_BASE_LOCATION - m_height + 1);
- foreach (KGameRenderedItem *tile, m_buildingTiles) {
+ foreach (KGameRenderedItem * tile, m_buildingTiles) {
m_board->addItem(tile);
}
}
-KGameRenderedItem *Building::createBuildingTile(const QString &pixmap)
+KGameRenderedItem * Building::createBuildingTile(const QString & pixmap)
{
auto tile = new KGameRenderedItem(m_renderer, pixmap);
tile->setRenderSize(QSize(32, 64));
@@ -106,17 +109,17 @@ KGameRenderedItem *Building::createBuildingTile(const QString &pixmap)
void Building::show()
{
- foreach (KGameRenderedItem *tile, m_buildingTiles) {
+ foreach (KGameRenderedItem * tile, m_buildingTiles) {
tile->show();
}
}
-void Building::resize(const QSize &size)
+void Building::resize(const QSize & size)
{
QSize tileSize(static_cast<unsigned int>(BUILDING_RELATIVE_WIDTH * size.width()),
static_cast<unsigned int>(BUILDING_RELATIVE_HEIGHT * size.height()));
for (int i = 0; i < m_buildingTiles.size(); ++i) {
- KGameRenderedItem *tile = m_buildingTiles.at(i);
+ KGameRenderedItem * tile = m_buildingTiles.at(i);
tile->setRenderSize(tileSize);
tile->setPos(m_board->mapPosition(QPointF(m_xPos, BUILD_BASE_LOCATION - i)));
}
diff --git a/src/building.h b/src/building.h
index d818c9b..ef31b7c 100644
--- a/src/building.h
+++ b/src/building.h
@@ -19,9 +19,9 @@
#ifndef BUILDING_H
#define BUILDING_H
+#include <QList>
#include <QRect>
#include <QSize>
-#include <QList>
class KGameRenderedItem;
class KGameRenderer;
@@ -35,7 +35,7 @@ class Building
{
public:
static const unsigned int BUILD_BASE_LOCATION;
- Building(KGameRenderer *renderer, BomberBoard *board, unsigned int position,
+ Building(KGameRenderer * renderer, BomberBoard * board, unsigned int position,
unsigned int height);
~Building();
@@ -54,7 +54,7 @@ public:
/**
* Sets width and height of plane.
*/
- void resize(const QSize &tileSize);
+ void resize(const QSize & tileSize);
/**
* Sets building's current frame
@@ -94,12 +94,12 @@ private:
* \param pixmap The pixmap the building tile should be created with
* \return The new created building tile
*/
- KGameRenderedItem *createBuildingTile(const QString &pixmap);
+ KGameRenderedItem * createBuildingTile(const QString & pixmap);
unsigned int m_height;
QRectF m_boundingRect;
- KGameRenderer *m_renderer;
- BomberBoard *m_board;
+ KGameRenderer * m_renderer;
+ BomberBoard * m_board;
QList<KGameRenderedItem *> m_buildingTiles;
qreal m_xPos;
diff --git a/src/explodable.cpp b/src/explodable.cpp
index 643c97e..d5e43dc 100644
--- a/src/explodable.cpp
+++ b/src/explodable.cpp
@@ -33,11 +33,13 @@ const qreal Explodable::EXPLOSION_RELATIVE_SIZE_H = 1.0;
*/
const qreal Explodable::EXPLOSION_RELATIVE_SIZE_W = 1.0;
-Explodable::Explodable(const QString &mainSvg, const QString &explosionSvg,
- qreal relativeWidth, qreal relativeHeight, KGameRenderer *renderer,
- BomberBoard *board) :
- KGameRenderedItem(renderer, mainSvg), m_board(board), m_mainSvg(
- mainSvg), m_explosionSvg(explosionSvg)
+Explodable::Explodable(const QString & mainSvg, const QString & explosionSvg,
+ qreal relativeWidth, qreal relativeHeight, KGameRenderer * renderer,
+ BomberBoard * board)
+ : KGameRenderedItem(renderer, mainSvg)
+ , m_board(board)
+ , m_mainSvg(mainSvg)
+ , m_explosionSvg(explosionSvg)
{
setRenderSize(QSize(32, 64));
m_relativeWidth = relativeWidth;
@@ -64,19 +66,17 @@ void Explodable::update()
setPos(m_board->mapPosition(QPointF(m_xPos, m_yPos)));
}
-void Explodable::resize(const QSize &tileSize)
+void Explodable::resize(const QSize & tileSize)
{
m_lastSize = tileSize;
if (m_state == State::Moving) {
setRenderSize(QSize(
- m_relativeWidth * tileSize.width(),
- m_relativeHeight * tileSize.height()
- ));
+ m_relativeWidth * tileSize.width(),
+ m_relativeHeight * tileSize.height()));
} else {
setRenderSize(QSize(
- EXPLOSION_RELATIVE_SIZE_W * tileSize.width(),
- EXPLOSION_RELATIVE_SIZE_H * tileSize.height()
- ));
+ EXPLOSION_RELATIVE_SIZE_W * tileSize.width(),
+ EXPLOSION_RELATIVE_SIZE_H * tileSize.height()));
}
setPos(m_board->mapPosition(QPointF(m_xPos, m_yPos)));
}
diff --git a/src/explodable.h b/src/explodable.h
index f93f15b..ea3d109 100644
--- a/src/explodable.h
+++ b/src/explodable.h
@@ -26,12 +26,14 @@ class BomberBoard;
/**
* This is a game object that can explode.
*/
-class Explodable: public KGameRenderedItem
+class Explodable : public KGameRenderedItem
{
public:
/** The states that a bomb can be in */
enum class State {
- Moving, Exploding, Exploded
+ Moving,
+ Exploding,
+ Exploded
};
/** The width of the explosion relative to the tile */
@@ -39,9 +41,9 @@ public:
/** The height of the explosion relative to the tile */
static const qreal EXPLOSION_RELATIVE_SIZE_H;
- explicit Explodable(const QString &mainSvg, const QString &explosionSvg,
+ explicit Explodable(const QString & mainSvg, const QString & explosionSvg,
qreal relativeWidth, qreal relativeHeight,
- KGameRenderer *renderer, BomberBoard *board);
+ KGameRenderer * renderer, BomberBoard * board);
virtual ~Explodable();
/**
@@ -54,7 +56,7 @@ public:
* Sets width and height of bomb. Using the current tile size.
* \param tileSize The size of the tile
*/
- void resize(const QSize &tileSize);
+ void resize(const QSize & tileSize);
/**
* Sets the velocity of the explodable object
@@ -117,7 +119,7 @@ protected:
QRectF m_nextBoundingRect;
private:
- BomberBoard *m_board;
+ BomberBoard * m_board;
qreal m_velocity;
diff --git a/src/main.cpp b/src/main.cpp
index 3975162..0b71448 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,17 +20,17 @@
#include <KAboutData>
#include <KCrash>
+#include <KDBusService>
#include <KLocalizedString>
#include <QApplication>
#include <QCommandLineParser>
#include <kdelibs4configmigrator.h>
-#include <KDBusService>
static const char description[] = I18N_NOOP("Arcade bombing game");
static const char version[] = "0.4";
-int main(int argc, char **argv)
+int main(int argc, char ** argv)
{
QApplication app(argc, argv);
Kdelibs4ConfigMigrator migrate(QStringLiteral("bomber"));
diff --git a/src/plane.cpp b/src/plane.cpp
index a24b06f..f6353c3 100644
--- a/src/plane.cpp
+++ b/src/plane.cpp
@@ -29,9 +29,9 @@ const qreal Plane::PLANE_RELATIVE_SIZE = 1;
/** This is the position before the plane goes off the screen */
const qreal Plane::PLANE_MAX_POSITION_X = 12;
-Plane::Plane(KGameRenderer *renderer, BomberBoard *board) :
- Explodable(QLatin1Literal("plane"), QLatin1Literal("plane_explode"), PLANE_RELATIVE_SIZE,
- PLANE_RELATIVE_SIZE, renderer, board)
+Plane::Plane(KGameRenderer * renderer, BomberBoard * board)
+ : Explodable(QLatin1Literal("plane"), QLatin1Literal("plane_explode"), PLANE_RELATIVE_SIZE,
+ PLANE_RELATIVE_SIZE, renderer, board)
{
setVelocity(DEFAULT_VELOCITY);
resetPosition();
diff --git a/src/plane.h b/src/plane.h
index 4ab7584..05c6833 100644
--- a/src/plane.h
+++ b/src/plane.h
@@ -26,9 +26,8 @@
* flys from left to right and each time it goes off the side of the screen it
* is repositioned back at the left side, one place lower than before.
*/
-class Plane: public Explodable
+class Plane : public Explodable
{
-
public:
/** This is the planes size relative to the tile */
static const qreal PLANE_RELATIVE_SIZE;
@@ -39,7 +38,7 @@ public:
/** The speed the plane will fly at */
static const qreal DEFAULT_VELOCITY;
- Plane(KGameRenderer *renderer, BomberBoard *board);
+ Plane(KGameRenderer * renderer, BomberBoard * board);
~Plane();
/**