[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/magazynier
From: Tadeusz Andrzej Kadłubowski <yess () hell ! org ! pl>
Date: 2009-12-12 16:58:03
Message-ID: 1260637083.314717.16293.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1061672 by tkadlubo:
The LevelModel now keeps track of the player orientation. It is done with QPoints of \
manhattan length 1. Renderer API supports getting player sprite with that \
orientation, but it ignores this parameter at the moment.
BTW: those m_moveDirXXX QPoints should be static, but I don't get C++ that much and I \
don't know how to do it.
M +15 -17 levelModel.cpp
M +11 -13 levelModel.h
M +1 -1 renderer.cpp
M +2 -1 renderer.h
--- trunk/playground/games/magazynier/levelModel.cpp #1061671:1061672
@@ -37,6 +37,11 @@
m_levelCompleted(false)
{
+ //Fixme those should be statis. How can I make static QPoint in C++?
+ m_moveDirUp = new QPoint(0, -1);
+ m_moveDirLeft = new QPoint(-1, 0);
+ m_moveDirDown = new QPoint(0, 1);
+ m_moveDirRight = new QPoint(1, 0);
}//}}}
LevelModel::~LevelModel() //{{{
@@ -50,6 +55,11 @@
delete m_levelItems;
delete m_playerPos;
+
+ delete m_moveDirUp;
+ delete m_moveDirLeft;
+ delete m_moveDirDown;
+ delete m_moveDirRight;
}//}}}
void LevelModel::initLevelData(QString &data) //{{{
@@ -101,7 +111,7 @@
if (line[col] == '@') {
newItem->setItemType(Player);
m_playerPos = new QPoint(col, row);
- m_playerOrientation = Up;
+ m_playerOrientation = m_moveDirUp;
continue;
}
if (line[col] == '$') {
@@ -182,6 +192,7 @@
if (sourceItem->itemType() == Player) {
*m_playerPos += delta;
+ m_playerOrientation = δ
kDebug() << "player position updated to" << *m_playerPos;
}
@@ -202,6 +213,7 @@
if (movingItemType == Player) {
*m_playerPos += delta;
+ m_playerOrientation = δ
kDebug() << "player position updated to" << *m_playerPos;
} else if (movingItemType == Box) {
--m_goalsLeft;
@@ -225,6 +237,7 @@
if (movingItemType == Player) {
*m_playerPos += delta;
+ m_playerOrientation = δ
kDebug() << "player position updated to" << *m_playerPos;
} else if (movingItemType == Box) {
++m_goalsLeft;
@@ -245,23 +258,13 @@
if (sourceItem->itemType() == (Player | Goal)) {
*m_playerPos += delta;
+ m_playerOrientation = δ
kDebug() << "player position updated to" << *m_playerPos;
}
return;
} //}}}
-QPoint LevelModel::orientationToDelta(Orientation o) //{{{
-{
- if (o == Up) return QPoint(0, -1);
- if (o == Down) return QPoint(0, 1);
- if (o == Left) return QPoint(-1, 0);
- if (o == Right) return QPoint(1, 0);
-
- Q_ASSERT();
- return QPoint(0, 0);
-} //}}}
-
bool LevelModel::canMove(QPoint delta) //{{{
{
MagazynierItem *target = getItem(*m_playerPos + delta);
@@ -281,11 +284,6 @@
return false;
} //}}}
-void LevelModel::move(Orientation orientation) //{{{
-{
- move(orientationToDelta(orientation));
-} //}}}
-
void LevelModel::move(QPoint delta) //{{{
{
if (!canMove(delta)) {
--- trunk/playground/games/magazynier/levelModel.h #1061671:1061672
@@ -34,12 +34,6 @@
Wall = 8
} ;
-enum Orientation {
- Up = 0,
- Right = 1,
- Down = 2,
- Left = 3
-} ;
class QGraphicsPixmapItem;
class QPoint;
@@ -53,6 +47,12 @@
Q_OBJECT
public:
+ QPoint *m_moveDirUp;
+ QPoint *m_moveDirLeft;
+ QPoint *m_moveDirDown;
+ QPoint *m_moveDirRight;
+
+
LevelModel(QObject *Parent=0);
~LevelModel();
void initLevelData(QString &data);
@@ -80,20 +80,18 @@
int m_shiftCount;
void setItem(QPoint pos, MagazynierItem *item);
QPoint *m_playerPos;
- Orientation m_playerOrientation;
+ QPoint *m_playerOrientation;
int m_columnCount, m_rowCount;
bool m_levelCompleted;
bool canMove(QPoint delta);
void move(QPoint delta);
- void move(Orientation orientation);
- QPoint orientationToDelta(Orientation o);
public slots:
- void moveUp(void) { move(Up); }
- void moveLeft(void) { move(Left); }
- void moveRight(void) { move(Right); }
- void moveDown(void) { move(Down); }
+ void moveUp(void) { move(*m_moveDirUp); }
+ void moveLeft(void) { move(*m_moveDirLeft); }
+ void moveRight(void) { move(*m_moveDirRight); }
+ void moveDown(void) { move(*m_moveDirDown); }
void moveDone(bool isShift);
void moveUndone(bool isShift);
--- trunk/playground/games/magazynier/renderer.cpp #1061671:1061672
@@ -78,7 +78,7 @@
m_pixmapCache->discard();
} //}}}
-QPixmap Renderer::get(int cellType) //{{{
+QPixmap Renderer::get(int cellType, QPoint *orientation) //{{{
{
Q_ASSERT(m_itemSize > 0);
QString name;
--- trunk/playground/games/magazynier/renderer.h #1061671:1061672
@@ -24,6 +24,7 @@
class KPixmapCache;
class KSvgRenderer;
class QPixmap;
+class QPoint;
class QString;
class Renderer : public QObject
@@ -33,7 +34,7 @@
public:
static Renderer *instance();
void loadTheme();
- QPixmap get(int cellType);
+ QPixmap get(int cellType, QPoint *orientation = 0);
QPixmap getBackground();
int getItemSize(void);
void setLevelSize(int height, int width); //height x width items
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic