QTfrontend/ui/widget/bgwidget.cpp
changeset 6242 27297c421bbc
parent 6241 e2c7771162ae
child 6243 9777d802be1a
equal deleted inserted replaced
6241:e2c7771162ae 6242:27297c421bbc
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    18  */
    18  */
    19 
    19 
    20 #include "bgwidget.h"
    20 #include "bgwidget.h"
    21 
    21 
    22 SpritePosition::SpritePosition(QWidget * parent, int sh)
    22 SpritePosition::SpritePosition(QWidget * parent, int sw, int sh)
    23 {
    23 {
    24     wParent = parent;
    24     wParent = parent;
       
    25     iSpriteWidth = sw;
    25     iSpriteHeight = sh;
    26     iSpriteHeight = sh;
    26     reset();
    27     reset();
    27 }
    28 }
    28 
    29 
    29 SpritePosition::~SpritePosition()
    30 SpritePosition::~SpritePosition()
    40     else if ((fY - fYMov) > wParent->height()) reset();
    41     else if ((fY - fYMov) > wParent->height()) reset();
    41 }
    42 }
    42 
    43 
    43 void SpritePosition::reset()
    44 void SpritePosition::reset()
    44 {
    45 {
    45     fY = -1 * iSpriteHeight;
    46     // random movement values
    46     fX = (qrand() % ((int)(wParent->width() * 1.5))) - wParent->width()/2;
       
    47     fYMov = ((qrand() % 400)+300) / 100.0f;
    47     fYMov = ((qrand() % 400)+300) / 100.0f;
    48     fXMov = fYMov * 0.2f+((qrand()%100)/100.0f * 0.6f); //so between 0.2 and 0.6, or 0.5 +/- 0.3
    48     fXMov = fYMov * 0.2f+((qrand()%100)/100.0f * 0.6f); //so between 0.2 and 0.8, or 0.5 +/- 0.3
       
    49 
       
    50     // random respawn locations
       
    51     int tmp = fXMov * (wParent->height() / fYMov);
       
    52     fX = (qrand() % (wParent->width() + tmp)) - tmp;
       
    53 
       
    54     // adjust respawn location to be next to (but outside) the parent's limits
       
    55     if (fX > -iSpriteWidth)
       
    56     {
       
    57         fY = -1 * iSpriteHeight;
       
    58     }
       
    59     else
       
    60     {
       
    61         fY = (-iSpriteWidth - fX) * (fYMov / fXMov);
       
    62         fX = -iSpriteWidth;
       
    63     }
       
    64 
       
    65     // random initial angle
    49     iAngle = qrand() % 360;
    66     iAngle = qrand() % 360;
    50 }
    67 }
    51 
    68 
    52 QPoint SpritePosition::pos()
    69 QPoint SpritePosition::pos()
    53 {
    70 {
    70     setAttribute(Qt::WA_NoSystemBackground, true);
    87     setAttribute(Qt::WA_NoSystemBackground, true);
    71     sprite.load(":/res/Star.png");
    88     sprite.load(":/res/Star.png");
    72 
    89 
    73     setAutoFillBackground(false);
    90     setAutoFillBackground(false);
    74 
    91 
    75     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height());
    92     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.width(), sprite.height());
    76 
    93 
    77     for (int i = 0; i < 90; i++)
    94     for (int i = 0; i < 90; i++)
    78     {
    95     {
    79         rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32);
    96         rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32);
    80         rotatedSprites[i]->fill(0);
    97         rotatedSprites[i]->fill(0);