[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdegames/kolf
From: Stefan Majewsky <majewsky () gmx ! net>
Date: 2010-10-31 22:15:17
Message-ID: 20101031221517.19CCFAC8AB () svn ! kde ! org
[Download RAW message or body]
SVN commit 1191676 by majewsky:
Port Ball to Tagaro::SpriteObjectItem, and kill useless Wall::paint method.
The only class which fetches its pixmaps directly from KGameRenderer is
the BlackHole. I tried to port it, but the change to
Tagaro::SpriteObjectItem seems to break the collision detection.
M +12 -25 ball.cpp
M +7 -7 ball.h
M +0 -7 game.cpp
M +0 -1 game.h
--- trunk/KDE/kdegames/kolf/ball.cpp #1191675:1191676
@@ -24,16 +24,18 @@
#include <KGameRenderer>
Ball::Ball(QGraphicsItem* parent)
- : QGraphicsEllipseItem(parent)
+ : Tagaro::SpriteObjectItem(Kolf::renderer(), QLatin1String("ball"), parent)
{
baseDiameter = 8;
resizeFactor = 1;
+ setOffset(-0.5 * baseDiameter, -0.5 * baseDiameter);
+ Tagaro::SpriteObjectItem::setSize(baseDiameter, baseDiameter);
+
setData(0, Rtti_Ball);
m_doDetect = true;
m_collisionLock = false;
setBeginningOfHole(false);
setBlowUp(false);
- setPen(QPen(Qt::black));
resetSize();
collisionId = 0;
m_addStroke = false;
@@ -50,7 +52,6 @@
label->setBrush(Qt::white);
label->setPos(5, 5);
label->setVisible(false);
- pixmapInitialised=false; //it can't be initialised yet because when a ball is first \
created it has no game (and therefore no renderer to create the pixmap)
// this sets z
setState(Stopped);
@@ -73,7 +74,8 @@
void Ball::resetSize()
{
- setRect(baseDiameter*-0.5, baseDiameter*-0.5, baseDiameter, baseDiameter);
+ setOffset(-0.5 * baseDiameter, -0.5 * baseDiameter);
+ Tagaro::SpriteObjectItem::setSize(baseDiameter, baseDiameter);
}
void Ball::resize(double resizeFactor)
@@ -83,8 +85,7 @@
font.setPixelSize((int)(baseFontPixelSize*resizeFactor));
label->setFont(font);
setPos(baseX, baseY); //not multiplied by resizeFactor since setPos takes care of \
that for the ball
- setRect(-0.5*baseDiameter*resizeFactor, -0.5*baseDiameter*resizeFactor, \
baseDiameter*resizeFactor, baseDiameter*resizeFactor);
- pixmap=Kolf::renderer()->spritePixmap("ball", rect().size().toSize());
+// setRect(-0.5*baseDiameter*resizeFactor, -0.5*baseDiameter*resizeFactor, \
baseDiameter*resizeFactor, baseDiameter*resizeFactor); }
void Ball::setPos(qreal x, qreal y)
@@ -100,7 +101,7 @@
//for a procedure that does not automatically take into account resizing use \
setResizedPos baseX = pos.x();
baseY = pos.y();
- QGraphicsEllipseItem::setPos(pos.x()*resizeFactor, pos.y()*resizeFactor);
+ Tagaro::SpriteObjectItem::setPos(pos.x()*resizeFactor, pos.y()*resizeFactor);
}
void Ball::setResizedPos(qreal x, qreal y)
@@ -108,23 +109,9 @@
//unlike Ball::setPos this does not automatically take into account resizing but \
instead sets the ball's position to exactly that which is inputted in x and y baseX \
= x/resizeFactor; baseY = y/resizeFactor;
- QGraphicsEllipseItem::setPos(x, y);
+ Tagaro::SpriteObjectItem::setPos(x, y);
}
-
-void Ball::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, \
QWidget * /*widget*/ )
-{
- if(pixmapInitialised == 0) {
- if(game == 0)
- return;
- else {
- pixmap=Kolf::renderer()->spritePixmap("ball", rect().size().toSize());
- pixmapInitialised=true;
- }
- }
- painter->drawPixmap((int)rect().x(), (int)rect().y(), pixmap);
-}
-
void Ball::advance(int /*phase*/)
{
// not used anymore
@@ -198,7 +185,7 @@
double oldy;
oldx = x();
oldy = y();
- QGraphicsEllipseItem::moveBy(dx, dy);
+ Tagaro::SpriteObjectItem::moveBy(dx, dy);
baseX += baseDx;
baseY += baseDy;
@@ -332,7 +319,7 @@
//Create the halo. This is an ellipse centered around the ball, and bigger than \
it. This allows us to detect walls which we could be about to collide into, and react \
intelligently to them, even though we are not colliding with them quite yet const \
double haloSizeFactor = 2;
- halo = new QGraphicsEllipseItem( rect().x() * haloSizeFactor, rect().y() * \
haloSizeFactor, rect().width() * haloSizeFactor, rect().height() * haloSizeFactor, \
this ); + halo = new QGraphicsEllipseItem( QRectF(pos() * haloSizeFactor, size() * \
haloSizeFactor), this ); halo->hide();
QList<QGraphicsItem *> haloCollisions = halo->collidingItems();
@@ -622,7 +609,7 @@
void Ball::setVisible(bool yes)
{
- QGraphicsEllipseItem::setVisible(yes);
+ Tagaro::SpriteObjectItem::setVisible(yes);
label->setVisible(yes && game && game->isInfoShowing());
}
--- trunk/KDE/kdegames/kolf/ball.h #1191675:1191676
@@ -21,12 +21,13 @@
#include "canvasitem.h"
#include "vector.h"
+#include "tagaro/spriteobjectitem.h"
class Wall;
enum BallState { Rolling = 0, Stopped, Holed };
-class Ball : public QGraphicsEllipseItem, public CanvasItem
+class Ball : public Tagaro::SpriteObjectItem, public CanvasItem
{
public:
Ball(QGraphicsItem* parent);
@@ -48,7 +49,7 @@
* set the position of the ball to exactly x and y, without taking into account \
resizing
*/
void setResizedPos(qreal x, qreal y);
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *);
+
virtual void advance(int phase);
virtual void doAdvance();
/*
@@ -69,7 +70,7 @@
void setState(BallState newState);
QColor color() const { return m_color; }
- void setColor(QColor color) { m_color = color; setBrush(color); setPen(color); }
+ void setColor(QColor color) { m_color = color; }
void setMoved(bool yes) { m_moved = yes; }
bool moved() const { return m_moved; }
@@ -109,8 +110,8 @@
virtual void setName(const QString &);
virtual void setVisible(bool yes);
- double width() { return rect().width(); }
- double height() { return rect().height(); }
+ double width() { return size().width(); }
+ double height() { return size().height(); }
double getBaseX() { return baseX; }
double getBaseY() { return baseY; }
@@ -123,8 +124,7 @@
private:
BallState state;
QColor m_color;
- QPixmap pixmap;
- bool pixmapInitialised;
+
long int collisionId;
double frictionMultiplier;
//base numbers are the size or position when no resizing has taken place (i.e. the \
defaults)
--- trunk/KDE/kdegames/kolf/game.cpp #1191675:1191676
@@ -2027,13 +2027,6 @@
editModeChanged(false);
}
-void Wall::paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget \
*widget)
-{
- if(antialiasing)
- p->setRenderHint(QPainter::Antialiasing, true);
- QGraphicsLineItem::paint(p, style, widget);
-}
-
void Wall::resize(double resizeFactor)
{
this->resizeFactor = resizeFactor;
--- trunk/KDE/kdegames/kolf/game.h #1191675:1191676
@@ -471,7 +471,6 @@
double dampening;
void setAlwaysShow(bool yes);
- void paint(QPainter *p, const QStyleOptionGraphicsItem *style, QWidget *widget);
virtual void setZValue(double newz);
void resize(double resizeFactor);
void setBasePenWidth(double basePenWidth) { this->basePenWidth=basePenWidth; }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic