Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

animate flying bombs

  • Loading branch information...
commit ee7c85393cad71e4d464637aac7b5c957e279fb2 1 parent 611dd70
Sébastien Escudier authored
View
2  common/Bomb.h
@@ -84,7 +84,7 @@ class Bomb : public QObject
protected:
bool dud_bomb;
bool flying; /// When a player use a glove, the bomb is flying above the blocks
- QPoint fl_destination; /// If a bomb if flying indicate its destination
+ QPoint fl_destination; /// If a bomb is flying indicate its destination
qint32 fl_Heartbeat; /// Indicate at which heartbeat the bomb will arrive
public:
View
31 common/Map.cpp
@@ -147,31 +147,52 @@ void Map<P,B,SL>::getNextBlock(int x, int y, int &xdest, int &ydest, globalDirec
{
xdest = x;
ydest = y;
+ /* The loop is used by flying bombs, and they go outsite the field (1 block) before coming to the other side */
switch(direction)
{
case dirLeft:
- if(xdest > 0)
+ if( xdest > 0)
xdest--;
else if(loop)
- xdest = width - 1;
+ {
+ if(xdest == 0)
+ xdest--;
+ else
+ xdest = width;
+ }
break;
case dirRight:
if(xdest < width - 1)
xdest++;
else if(loop)
- xdest = 0;
+ {
+ if(xdest == width - 1)
+ xdest++;
+ else
+ xdest = -1;
+ }
break;
case dirDown:
if(ydest > 0)
ydest--;
else if(loop)
- ydest = height - 1;
+ {
+ if(ydest == 0)
+ ydest = -1;
+ else
+ ydest = height;
+ }
break;
case dirUp:
if(ydest < height - 1)
ydest++;
else if(loop)
- ydest = 0;
+ {
+ if(ydest == height - 1)
+ ydest++;
+ else
+ ydest = -1;
+ }
break;
default:
break;
View
2  common/Map.h
@@ -43,6 +43,8 @@ class PixelToBlock
{}
qint8 operator()(qint16 val) {
+ if(val < 0)
+ return (val / blockSize) - 1;
return val / blockSize;
}
View
42 gui/GameArena.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2010,2011 Sébastien Escudier
+ Copyright (C) 2010,2011,2012 Sébastien Escudier
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -189,8 +189,11 @@ void GameArena::setMap(MapClient *newMap)
connect(map, SIGNAL(sigAddBonus(Bonus::Bonus_t,qint16,qint16)), this, SLOT(slotAddBonus(Bonus::Bonus_t,qint16,qint16)));
connect(map, SIGNAL(sigRemoveBonus(qint16,qint16)), this, SLOT(slotRemoveBonus(qint16,qint16)));
connect(map, SIGNAL(sigAddBomb(int)), this, SLOT(slotAddBomb(int)), Qt::DirectConnection);
- connect(map, SIGNAL(sigMovedBomb(int)), this, SLOT(slotMovedBomb(int)), Qt::DirectConnection);
- connect(map, SIGNAL(sigFlyingBomb(int)), this, SLOT(slotFlyingBomb(int)), Qt::DirectConnection);
+ /* move and flying bomb slots must be queued connection because the value of
+ * bomb->flying can change between a sigMovedBomb and a sigFlyingBomb
+ * */
+ connect(map, SIGNAL(sigMovedBomb(int)), this, SLOT(slotMovedBomb(int)), Qt::QueuedConnection);
+ connect(map, SIGNAL(sigFlyingBomb(int,qint32)), this, SLOT(slotFlyingBomb(int,qint32)), Qt::QueuedConnection);
connect(map, SIGNAL(sigRemoveBomb(int)), this, SLOT(slotRemoveBomb(int)), Qt::DirectConnection);
connect(map, SIGNAL(sigRemoveBombRC(int)), this, SLOT(slotRemoveBombRC(int)), Qt::DirectConnection);
connect(map, SIGNAL(sigAddFlame(int,qint16,qint16)), this, SLOT(slotAddFlame(int,qint16,qint16)));
@@ -305,7 +308,8 @@ void GameArena::slotHearbeatUpdated(qint32 value) {
QMap<int, QBomb*>::iterator itb;
for (itb = bombs.begin();itb!=bombs.end();++itb)
{
- itb.value()->nextFrame();
+ itb.value()->nextFrame(value);
+
}
QMap<int, QFlame*>::iterator itf;
for (itf = flames.begin();itf!=flames.end();++itf)
@@ -393,14 +397,36 @@ void GameArena::slotAddBomb(int id)
void GameArena::slotMovedBomb(int id)
{
const BombClient& bomb = map->getRefBomb(id);
- bombs[id]->setPos(bomb.getX() - squareSize/2, bomb.getY() - squareSize/2, squareSize);
+ QBomb *qb = bombs[id];
+ // A bomb is considered non flying when it moves and the flying flag is false
+ if(!bomb.getFlying())
+ qb->setNonFlying();
+ qb->setPos(bomb.getX() - squareSize/2, bomb.getY() - squareSize/2);
}
-void GameArena::slotFlyingBomb(int id)
+void GameArena::slotFlyingBomb(int id, qint32 heartBeat)
{
+ //We received a new flying bomb, or one already flying has moved and is still flying.
const BombClient& bomb = map->getRefBomb(id);
- //qDebug() << "GameArena : new flying bomb";
- /* Todo : animate the flying bomb */
+ Q_ASSERT(bomb.getFlying());
+
+ QMap<int, QBomb*>::iterator itb = bombs.find(id);
+ Q_ASSERT(itb != bombs.end());
+
+ QPoint Destination = bomb.getDestination();
+ QPoint centreDest = map->getCenterCoordForBlock(Destination.x(), Destination.y());
+ int HB_left = heartBeat - bomb.getFlHeartbeat();
+ int xDistance = bomb.getX() - centreDest.x();
+ int yDistance = bomb.getY() - centreDest.y();
+ /**
+ * There is no animation when the bomb is going from one side to the other side of the game field.
+ * And the minus 2 is for the case where the player throw the bomb directly to the other side
+ */
+
+ if( HB_left > 0 && qAbs(xDistance) < ( map->getWidth() - 2 ) * map->getBlockSize() && qAbs(yDistance) < ( map->getHeight() - 2 ) * map->getBlockSize() )
+ {
+ itb.value()->setFlying(HB_left, xDistance, yDistance );
+ }
}
//todo vérifier s'il existe pas un moyen moins chelou pour supprimer un couple
View
2  gui/GameArena.h
@@ -93,7 +93,7 @@ private slots:
void slotRemoveBonus(qint16 x, qint16 y);
void slotAddBomb(int id);
void slotMovedBomb(int id);
- void slotFlyingBomb(int id);
+ void slotFlyingBomb(int id, qint32 heartBeat);
void slotRemoveBomb(int id);
void slotRemoveBombRC(int id);
void slotRemoveHurryUp();
View
6 gui/QAnimateditem.cpp
@@ -30,6 +30,12 @@ void QAnimatedItem::setPos(int x, int y, int size)
this->size=size;
}
+void QAnimatedItem::setPos(int x, int y)
+{
+ setX(x);
+ setY(y);
+}
+
QRectF QAnimatedItem::boundingRect() const
{
return QRectF(0,0,size,size);
View
1  gui/QAnimateditem.h
@@ -38,6 +38,7 @@ class QAnimatedItem : public QGraphicsItem
QList<QPixmap*>* currentAnim;
QAnimatedItem();
void setPos(int,int,int);
+ void setPos(int,int);
void nextFrame();
static void appendNewFrame(QList<QPixmap*>* anim, const QString &path);
};
View
2  gui/QGraphicsSquareItem.cpp
@@ -45,7 +45,7 @@ QGraphicsPixmapItem *QGraphicsSquareItem::getItem()
void QGraphicsSquareItem::paint(QPainter*p, const QStyleOptionGraphicsItem* qs, QWidget* qw)
{
- qDebug() <<"qgsi painter"<<p;
+ //qDebug() <<"qgsi painter"<<p;
pix.paint(p,qs,qw);
}
View
43 gui/qbomb.cpp
@@ -21,17 +21,16 @@ QList<QPixmap*> QBomb::rcPix= QList<QPixmap*>();
QList<QPixmap*> QBomb::dudPix= QList<QPixmap*>();
-QBomb::QBomb()
+QBomb::QBomb() :
+ flying(false), xStep(0), yStep(0), nbStep(0), normalSize(0)
{
Q_ASSERT(!normalPix.empty());
- size=0;
- currentPix=0;
}
-QBomb::QBomb(int x, int y , int size)
+QBomb::QBomb(int x, int y, int size) :
+ flying(false), xStep(0), yStep(0), nbStep(0), normalSize(0)
{
Q_ASSERT(!normalPix.empty());
- currentPix=0;
currentAnim=&QBomb::normalPix;
setPos(x,y,size);
@@ -46,12 +45,46 @@ void QBomb::setDudBomb()
currentPix=0;
currentAnim=&QBomb::dudPix;
}
+
void QBomb::setRC()
{
currentPix=0;
currentAnim=&QBomb::rcPix;
}
+void QBomb::setFlying(int nb, int x, int y)
+{
+ if(!flying)
+ normalSize = size;
+ flying = true;
+ nbStep = nb;
+ xStep = x/nb;
+ yStep = y/nb;
+}
+
+void QBomb::setNonFlying()
+{
+ if(flying)
+ {
+ flying = false;
+ setPos(x(), y(), normalSize);
+ }
+}
+
+void QBomb::nextFrame(int hb)
+{
+ if(flying && --nbStep > 0)
+ {
+ //setPos(x() - xStep, y() - yStep, normalSize);
+ int newSize = size;
+ if( hb % 5 == 0 )
+ newSize = size > normalSize ? normalSize : normalSize + 10;
+ setPos(x() - xStep, y() - yStep, newSize);
+ }
+ QAnimatedItem::nextFrame();
+}
+
+
void QBomb::loadPixs()
{
if (QBomb::normalPix.isEmpty())
View
12 gui/qbomb.h
@@ -25,7 +25,14 @@
class QBomb : public QAnimatedItem
{
private:
-
+ /**
+ * Flying parameters
+ */
+ bool flying;
+ int xStep; //number of pixel to move at each frame
+ int yStep;
+ int nbStep; //number of frame
+ int normalSize;
public:
QBomb();
QBomb(int,int,int);
@@ -39,6 +46,9 @@ class QBomb : public QAnimatedItem
void setRC();
void setNormalBomb();
void setDudBomb();
+ void setFlying(int nb, int x, int y);
+ void setNonFlying();
+ void nextFrame(int hb);
};
#endif // QBOMB_H
View
10 network/client/MapClient.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2010,2011 Sébastien Escudier
+ Copyright (C) 2010,2011,2012 Sébastien Escudier
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -87,10 +87,10 @@ void MapClient::updateMap(QByteArray& updateBlock) {
qint16 bombId, nx, ny;
updateIn >> bombId >> nx >> ny;
BombClient* b = getBomb(bombId);
- if(b != 0) {
+ if(b != NULL) {
b->setX(nx);
b->setY(ny);
- b->setFlying(false);
+ b->setFlying(false); //if the bomb is still flying, it will be set back right after.
}
emit sigMovedBomb(bombId);
}
@@ -102,13 +102,13 @@ void MapClient::updateMap(QByteArray& updateBlock) {
qint32 hb;
updateIn >> bombId >> nx >> ny >> hb;
BombClient* b = getBomb(bombId);
- if(b != 0) {
+ if(b != NULL) {
QPoint dest(nx,ny);
b->setFlying(true);
b->setDestination(dest);
b->setFlHeartbeat(hb);
}
- emit sigFlyingBomb(bombId);
+ emit sigFlyingBomb(bombId, heartBeat);
}
qint8 nbExplosions;
View
2  network/client/MapClient.h
@@ -63,7 +63,7 @@ public :
void sigRemoveBonus(qint16 x, qint16 y);
void sigAddBomb(int);
void sigMovedBomb(int);
- void sigFlyingBomb(int);
+ void sigFlyingBomb(int,qint32);
void sigRemoveBomb(int);
void sigRemoveBombRC(int);
void sigAddFlame(int id, qint16 x, qint16 y);
View
18 network/server/MapServer.cpp
@@ -417,7 +417,6 @@ void MapServer::throwBomb(BombServer *bomb, globalDirection direction, int dista
bomb->setDirection(direction);
bomb->setDestination(bombPoint);
bomb->setFlHeartbeat(heartBeat - FLYINGBOMB_MOVE_SPEED);
- //qDebug() << "throwing a bomb" << (int)direction << bombPoint.x() << bombPoint.y();
}
bool MapServer::moveFlyingBomb(BombServer* b)
@@ -426,7 +425,8 @@ bool MapServer::moveFlyingBomb(BombServer* b)
if(b->getFlHeartbeat() == heartBeat)
{
QPoint dest = b->getDestination();
- bool bEmply = getType(dest.x(),dest.y()) == BlockMapProperty::empty
+ bool bEmply = dest.x() >= 0 && dest.y() >= 0 && dest.x() < width && dest.y() < height
+ && getType(dest.x(),dest.y()) == BlockMapProperty::empty
&& !blockContainsPlayer(dest.x(), dest.y()) && !getTileBomb(dest.x(), dest.y());
QPoint centre = getCenterCoordForBlock(dest.x(), dest.y());
b->setX(centre.x());
@@ -1414,7 +1414,7 @@ void MapServer::newHeartBeat() {
if(bombN->getFlying())
{
hasMoved = moveFlyingBomb(bombN);
- if(hasMoved && bombN->getFlying())
+ if(hasMoved && bombN->getFlying())
flyingBombs << bombN;
}
else
@@ -1438,7 +1438,9 @@ void MapServer::newHeartBeat() {
if(hasMoved) {
QPoint neighBlock = getOverlappingBlockPosition(bombN->getX(), bombN->getY());
- delete removeBonus(neighBlock.x(), neighBlock.y());
+ //flying bombs can go outside the field
+ if(neighBlock.x() >= 0 && neighBlock.y() >= 0 && neighBlock.x() < width && neighBlock.y() < height )
+ delete removeBonus(neighBlock.x(), neighBlock.y());
movingBombs.append(bombN);
}
}
@@ -1446,10 +1448,10 @@ void MapServer::newHeartBeat() {
// serialize the moving bombs
updateOut << static_cast<qint8>(movingBombs.size());
foreach(BombServer* bombN, movingBombs) {
- updateOut << bombN->getBombId() << bombN->getX() << bombN->getY();
+ updateOut << bombN->getBombId() << bombN->getX() << bombN->getY();;
}
- // serialize the new flying bombs
+ // serialize the new (or moved) flying bombs
updateOut << static_cast<qint8>(flyingBombs.size());
foreach(BombServer* bombN, flyingBombs) {
QPoint p = bombN->getDestination();
@@ -1471,9 +1473,9 @@ void MapServer::newHeartBeat() {
QMap<BombServer::bombId_t, BombServer*>::const_iterator itBomb = getBombList().begin();
while(itBomb != getBombList().end()) {
BombServer* b = *itBomb;
- if( b->mustExplode() ||
+ if( !b->getFlying() && ( b->mustExplode() ||
( b->getIsRC() && players[b->getPlayerId()]->getOptKey() ) ||
- getTileFlames(b->getTileX(), b->getTileY()).size() > 0
+ getTileFlames(b->getTileX(), b->getTileY()).size() > 0 )
)
{
explodeList.append(explosion(*itBomb));
Please sign in to comment.
Something went wrong with that request. Please try again.