[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/granatier/src
From: Mathias Kraus <k.hias () gmx ! de>
Date: 2009-09-23 21:29:09
Message-ID: 1253741349.618270.13207.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1027348 by mkraus:
refactoring of element.cpp/.h and elementitem.cpp/h
M +36 -29 element.cpp
M +107 -116 element.h
M +28 -22 elementitem.cpp
M +35 -36 elementitem.h
M +11 -33 game.cpp
M +1 -3 game.h
M +0 -3 gamescene.cpp
--- trunk/playground/games/granatier/src/element.cpp #1027347:1027348
@@ -1,4 +1,5 @@
/*
+ * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
@@ -19,16 +20,18 @@
#include "arena.h"
#include "player.h"
-Element::Element(qreal p_x, qreal p_y, Arena* p_arena) : m_xInit(p_x), m_yInit(p_y), m_arena(p_arena) {
- m_points = 0;
- initCoordinate();
+Element::Element(qreal p_x, qreal p_y, Arena* p_arena) : m_xInit(p_x), m_yInit(p_y), m_arena(p_arena)
+{
+ initCoordinate();
}
-Element::~Element() {
+Element::~Element()
+{
}
-void Element::doActionOnCollision(Player*) {
- // Do nothing by default : will be redefined within the subclasses
+void Element::doActionOnCollision(Player*)
+{
+ // Do nothing by default : will be redefined within the subclasses
}
void Element::setArena(Arena* p_arena)
@@ -42,41 +45,45 @@
m_yInit = p_y;
}
-qreal Element::getX() const {
- return m_x;
+qreal Element::getX() const
+{
+ return m_x;
}
-qreal Element::getY() const {
- return m_y;
+qreal Element::getY() const
+{
+ return m_y;
}
-void Element::setX(qreal p_x) {
- m_x = p_x;
- emit(moved(m_x, m_y));
+void Element::setX(qreal p_x)
+{
+ m_x = p_x;
+ emit(moved(m_x, m_y));
}
-void Element::setY(qreal p_y) {
- m_y = p_y;
- emit(moved(m_x, m_y));
+void Element::setY(qreal p_y)
+{
+ m_y = p_y;
+ emit(moved(m_x, m_y));
}
-int Element::getPoints() const {
- return m_points;
+Element::Type Element::getType() const
+{
+ return m_type;
}
-Element::Type Element::getType() const {
- return m_type;
+QString Element::getImageId() const
+{
+ return m_imageId;
}
-QString Element::getImageId() const {
- return m_imageId;
+void Element::setImageId(const QString & p_imageId)
+{
+ m_imageId = p_imageId;
}
-void Element::setImageId(const QString & p_imageId){
- m_imageId = p_imageId;
+void Element::initCoordinate()
+{
+ setX(m_xInit);
+ setY(m_yInit);
}
-
-void Element::initCoordinate(){
- setX(m_xInit);
- setY(m_yInit);
-}
--- trunk/playground/games/granatier/src/element.h #1027347:1027348
@@ -1,4 +1,5 @@
/*
+ * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
@@ -28,141 +29,131 @@
*/
class Element : public QObject {
- Q_OBJECT
-
- public:
-
- /** The Element possible types */
- enum Type {
- BLOCK,
- PLAYER,
- BOMB,
- PILL,
- ENERGYZER,
- BONUS
- };
-
- protected:
-
- /** The Element type */
- Type m_type;
+Q_OBJECT
- /** The Element initial x-coordinate */
- qreal m_xInit;
+public:
- /** The Element initial y-coordinate */
- qreal m_yInit;
+ /** The Element possible types */
+ enum Type
+ {
+ BLOCK,
+ PLAYER,
+ BOMB,
+ BONUS
+ };
+
+protected:
- /** The Element current x-coordinate */
- qreal m_x;
+ /** The Element type */
+ Type m_type;
- /** The Element current y-coordinate */
- qreal m_y;
+ /** The Element initial x-coordinate */
+ qreal m_xInit;
- /** The Arena the Element is on */
- Arena* m_arena;
+ /** The Element initial y-coordinate */
+ qreal m_yInit;
- /** The Id of the Element */
- QString m_imageId;
-
- /** Points won when the Element is eaten */
- int m_points;
+ /** The Element current x-coordinate */
+ qreal m_x;
- public:
+ /** The Element current y-coordinate */
+ qreal m_y;
- /**
- * Creates a new Element instance.
- * @param p_x the initial x-coordinate
- * @param p_y the initial y-coordinate
- * @param p_arena the Arena the Element is on
- */
- Element(qreal p_x, qreal p_y, Arena* p_arena);
+ /** The Arena the Element is on */
+ Arena* m_arena;
- /**
- * Deletes the Element instance.
- */
- ~Element();
+ /** The Id of the Element */
+ QString m_imageId;
- /**
- * Computes an action on a collision with the Player.
- * @param p_player the instance of Player which collides with the Element
- */
- virtual void doActionOnCollision(Player* p_player);
+public:
- /**
- * Sets arena for the element.
- * @param p_arena arena
- */
- void setArena(Arena* p_arena);
-
- /**
- * Sets the path initial position.
- * @param p_position initial position
- */
- void setInitialCoordinates (qreal p_x, qreal p_y);
-
- /**
- * Gets the path to the Element image.
- * @return the path to the Element image
- */
- QString getImageId() const;
-
- /**
- * Gets the value of the Element.
- * @return the points won when the Element is eaten
- */
- int getPoints() const;
-
- /**
- * Gets the type of the Element.
- * @return the Element type
- */
- Element::Type getType() const;
+ /**
+ * Creates a new Element instance.
+ * @param p_x the initial x-coordinate
+ * @param p_y the initial y-coordinate
+ * @param p_arena the Arena the Element is on
+ */
+ Element(qreal p_x, qreal p_y, Arena* p_arena);
- /**
- * Sets the Element image.
- * @param p_imageId the image to set
- */
- void setImageId(const QString & p_imageId);
+ /**
+ * Deletes the Element instance.
+ */
+ ~Element();
- /**
- * Gets the Element x-coordinate.
- * @return the x-coordinate
- */
- qreal getX() const;
+ /**
+ * Computes an action on a collision with the Player.
+ * @param p_player the instance of Player which collides with the Element
+ */
+ virtual void doActionOnCollision(Player* p_player);
- /**
- * Gets the Element y-coordinate.
- * @return the y-coordinate
- */
- qreal getY() const;
+ /**
+ * Sets arena for the element.
+ * @param p_arena arena
+ */
+ void setArena(Arena* p_arena);
+
+ /**
+ * Sets the path initial position.
+ * @param p_position initial position
+ */
+ void setInitialCoordinates (qreal p_x, qreal p_y);
+
+ /**
+ * Gets the path to the Element image.
+ * @return the path to the Element image
+ */
+ QString getImageId() const;
+
+ /**
+ * Gets the type of the Element.
+ * @return the Element type
+ */
+ Element::Type getType() const;
- /**
- * Sets the Element x-coordinate to the given value
- * @param p_x the x-coordinate to set
- */
- void setX(qreal p_x);
+ /**
+ * Sets the Element image.
+ * @param p_imageId the image to set
+ */
+ void setImageId(const QString & p_imageId);
- /**
- * Sets the Element y-coordinate to the given value
- * @param p_y the y-coordinate to set
- */
- void setY(qreal p_y);
+ /**
+ * Gets the Element x-coordinate.
+ * @return the x-coordinate
+ */
+ qreal getX() const;
- /**
- * Initializes Element x-coordinate and y-coordinate with
- * initial values
- */
- void initCoordinate();
+ /**
+ * Gets the Element y-coordinate.
+ * @return the y-coordinate
+ */
+ qreal getY() const;
- signals:
+ /**
+ * Sets the Element x-coordinate to the given value
+ * @param p_x the x-coordinate to set
+ */
+ void setX(qreal p_x);
- /**
- * Emitted on Element move.
- * @param p_x the new x-coordinate
- * @param p_y the new y-coordinate
- */
- void moved(qreal p_x, qreal p_y);
+ /**
+ * Sets the Element y-coordinate to the given value
+ * @param p_y the y-coordinate to set
+ */
+ void setY(qreal p_y);
+
+ /**
+ * Initializes Element x-coordinate and y-coordinate with
+ * initial values
+ */
+ void initCoordinate();
+
+signals:
+
+ /**
+ * Emitted on Element move.
+ * @param p_x the new x-coordinate
+ * @param p_y the new y-coordinate
+ */
+ void moved(qreal p_x, qreal p_y);
};
#endif
--- trunk/playground/games/granatier/src/elementitem.cpp #1027347:1027348
@@ -1,4 +1,5 @@
/*
+ * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
@@ -18,36 +19,41 @@
#include "elementitem.h"
#include "element.h"
-ElementItem::ElementItem(Element* p_model) : QGraphicsSvgItem() {
- m_model = p_model;
- // Init the view coordinates
- setPos(p_model->getX() - boundingRect().width() / 2, p_model->getY() - boundingRect().height() / 2);
- // Connects the model to the view
- connect(p_model, SIGNAL(moved(qreal, qreal)), this, SLOT(update(qreal, qreal)));
- setCacheMode(DeviceCoordinateCache);
- setMaximumCacheSize(QSize(500, 500));
+ElementItem::ElementItem(Element* p_model) : QGraphicsSvgItem()
+{
+ m_model = p_model;
+ // Init the view coordinates
+ setPos(p_model->getX() - boundingRect().width() / 2, p_model->getY() - boundingRect().height() / 2);
+ // Connects the model to the view
+ connect(p_model, SIGNAL(moved(qreal, qreal)), this, SLOT(update(qreal, qreal)));
+ setCacheMode(DeviceCoordinateCache);
+ setMaximumCacheSize(QSize(500, 500));
}
-ElementItem::~ElementItem() {
- delete m_model;
+ElementItem::~ElementItem()
+{
+ delete m_model;
}
-Element* ElementItem::getModel() const {
- return m_model;
+Element* ElementItem::getModel() const
+{
+ return m_model;
}
-QPainterPath ElementItem::shape() const {
- QPainterPath path;
- path.addEllipse(boundingRect());
- return path;
+QPainterPath ElementItem::shape() const
+{
+ QPainterPath path;
+ path.addEllipse(boundingRect());
+ return path;
}
-void ElementItem::update(qreal p_x, qreal p_y) {
- // Compute the top-right coordinates of the item
- qreal x = p_x - boundingRect().width() / 2;
- qreal y = p_y - boundingRect().height() / 2;
+void ElementItem::update(qreal p_x, qreal p_y)
+{
+ // Compute the top-right coordinates of the item
+ qreal x = p_x - boundingRect().width() / 2;
+ qreal y = p_y - boundingRect().height() / 2;
- // Updates the view coordinates
- setPos(x, y);
+ // Updates the view coordinates
+ setPos(x, y);
}
--- trunk/playground/games/granatier/src/elementitem.h #1027347:1027348
@@ -1,4 +1,5 @@
/*
+ * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
*
* This program is free software; you can redistribute it and/or
@@ -27,49 +28,47 @@
*/
class ElementItem : public QGraphicsSvgItem {
- Q_OBJECT
+Q_OBJECT
- private:
- /** The Label containing the points won when eaten, to display on the scene */
- QGraphicsTextItem* m_pointsToDisplay;
-
- protected:
-
- /** The instance of Element the ElementItem will represent */
- Element* m_model;
+private:
- public:
+protected:
- /**
- * Creates a new ElementItem instance.
- * @param p_model the Element model
- */
- ElementItem(Element* p_model);
+ /** The instance of Element the ElementItem will represent */
+ Element* m_model;
- /**
- * Deletes the ElementItem instance.
- */
- ~ElementItem();
-
- /**
- * Gets the Element model.
- * @return the model
- */
- Element* getModel() const;
+public:
- /**
- * Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions.
- */
- QPainterPath shape() const;
+ /**
+ * Creates a new ElementItem instance.
+ * @param p_model the Element model
+ */
+ ElementItem(Element* p_model);
- public slots:
+ /**
+ * Deletes the ElementItem instance.
+ */
+ ~ElementItem();
+
+ /**
+ * Gets the Element model.
+ * @return the model
+ */
+ Element* getModel() const;
- /**
- * Updates the ElementItem coordinates.
- * @param p_x the new x-coordinate
- * @param p_y the new y-coordinate
- */
- virtual void update(qreal p_x, qreal p_y);
+ /**
+ * Reimplement QGraphicsItem::shape() to return an ellipse to improve collisions.
+ */
+ QPainterPath shape() const;
+
+public slots:
+
+ /**
+ * Updates the ElementItem coordinates.
+ * @param p_x the new x-coordinate
+ * @param p_y the new y-coordinate
+ */
+ virtual void update(qreal p_x, qreal p_y);
};
#endif
--- trunk/playground/games/granatier/src/game.cpp #1027347:1027348
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Mathias Kraus <k.hias@gmx.de>
+ * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
* Copyright 2007-2008 Pierre-Benoit Besse <besse@gmail.com>
* Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
@@ -46,7 +46,7 @@
const int Game::FPS = 40;
-Game::Game(PlayerSettings* playerSettings) : m_isCheater(false), m_points(0), m_level(1)
+Game::Game(PlayerSettings* playerSettings) : m_isCheater(false), m_level(1)
{
m_playerSettings = playerSettings;
@@ -276,9 +276,6 @@
return m_isCheater;
}
-int Game::getScore() const {
- return m_points;
-}
int Game::getLives() const {
return 3;//m_lives;
}
@@ -618,35 +615,16 @@
}
-void Game::winPoints(Element* p_element) {
+void Game::winPoints(Element* p_element)
+{
+ if (p_element->getType() == Element::BONUS)
+ {
+ // Get the position of the Bonus
+ qreal xPos = p_element->getX();
+ qreal yPos = p_element->getY();
- // The value of won Points
- long wonPoints;
-
- wonPoints = p_element->getPoints();
-
- // Update of the points value
- m_points += wonPoints;
-
- // For each 10000 points we get a life more
- if (m_points / 10000 > (m_points - wonPoints) / 10000) {
- //m_lives++;
- emit(dataChanged(LivesInfo));
- }
-
- if (p_element->getType() == Element::PILL) {
- emit(elementEaten(p_element->getX(), p_element->getY()));
- } else if (p_element->getType() == Element::BONUS) {
- // Get the position of the Bonus
- qreal xPos = p_element->getX();
- qreal yPos = p_element->getY();
-
- // Sends to the scene the number of points to display and its position
- emit(pointsToDisplay(wonPoints, xPos, yPos));
-
- emit(bonusOff());
- }
- emit(dataChanged(ScoreInfo));
+ emit(bonusOff());
+ }
}
void Game::nextLevel() {
--- trunk/playground/games/granatier/src/game.h #1027347:1027348
@@ -1,4 +1,5 @@
/*
+ * Copyright 2009 Mathias Kraus <k.hias@gmx.de>
* Copyright 2007-2008 Thomas Gallinari <tg8187@yahoo.fr>
* Copyright 2007-2008 Alexandre Galinier <alex.galinier@hotmail.com>
*
@@ -90,9 +91,6 @@
/** The points which are needed to win */
int m_winPoints;
-
- /** The won points */
- long m_points;
/** Flag if the round is over */
int m_roundOver;
--- trunk/playground/games/granatier/src/gamescene.cpp #1027347:1027348
@@ -590,9 +590,6 @@
if (p_info & Game::LivesInfo) {
m_livesLabel->setPlainText(i18n("Lives: %1", m_game->getLives()));
}
- if (p_info & Game::ScoreInfo) {
- m_scoreLabel->setPlainText(i18n("Score: %1", m_game->getScore()));
- }
if (p_info & Game::LevelInfo) {
m_levelLabel->setPlainText(i18nc("The number of the game level", "Level: %1", m_game->getLevel()));
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic