2 Mancala - A Historical Board Game
3 Copyright (C) 2009-2010 A.H.M.Mahfuzur Rahman 65mahfuz90@gmail.com
4 Copyright (c) 2010 Reto Zingg g.d0b3rm4n@gmail.com
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <QSvgRenderer>
24 #include <QGraphicsItemAnimation>
27 // #include "kdebug.h"
28 // #include "kstandarddirs.h"
33 //Stone::Stone(int index , QSvgRenderer *render, GameInfo* gameInfo, ThemeManager* theme)
34 Stone::Stone(int index , GameInfo* gameInfo, ThemeManager* theme,QGraphicsSvgItem *parent)
35 : QGraphicsSvgItem(parent)
38 m_themeManager = theme;
39 m_gameInfo = gameInfo;
40 m_board = qgraphicsitem_cast<Board*>(parent);
42 setSharedRenderer((QSvgRenderer*)theme);
43 setElementId("stone");
50 void Stone::setPosition(qreal x, qreal y){
55 //kDebug() << "Pos Here: " << x << " " << y;
60 void Stone::animateStones(QPointF newPos){
62 //kDebug() << "Stone Pos: New: "<< newPos << " Old: " << m_pos;
63 int steps = abs(m_pos.x() - newPos.x()) + abs(m_pos.y() - newPos.y()),diff;
65 QTimeLine *timer = new QTimeLine(1000);
66 timer->setFrameRange(0, 100);
68 QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
69 animation->setItem(this);
70 animation->setTimeLine(timer);
72 for (int i = 0; i < (int)steps; ++i){
74 if(i < abs(m_pos.x() - newPos.x()) ){
75 if( m_pos.x() < newPos.x() ){
76 animation->setPosAt(i / (qreal)steps, QPointF( i + m_pos.x() , m_pos.y()));
77 //kDebug() << "Position: " << QPointF( i + m_pos.x() , m_pos.y());
79 else animation->setPosAt(i / (qreal)steps, QPointF( m_pos.x() - i , m_pos.y()));
83 //if( diff+1 == i) kDebug() <<"Diff is:" << diff;
85 if(m_pos.y() < newPos.y()){
86 animation->setPosAt( i/ (qreal) steps, QPointF(newPos.x() , i-diff+m_pos.y() ));
87 //kDebug() << "Position: " << QPointF(newPos.x() , i-diff+m_pos.y() );
90 animation->setPosAt( i/ (qreal) steps, QPointF(newPos.x() , m_pos.y()-(i-diff) ));
91 //kDebug() << "Position: " << QPointF(newPos.x() , m_pos.y()-(i-diff));
98 m_pos.setX(newPos.x());
99 m_pos.setY(newPos.y());