Permalink
Browse files

New GRAPHICS ANIMATION!!!

  • Loading branch information...
1 parent d84039a commit 8aa6a8e9708fc2648edb004f3d461089492b16c7 @Mandarancio committed May 26, 2012
Showing with 93 additions and 18 deletions.
  1. +25 −2 dynamicgoo.cpp
  2. +3 −1 dynamicgoo.h
  3. +54 −11 joint.cpp
  4. +6 −0 joint.h
  5. +2 −2 removablegoo.cpp
  6. +3 −2 stickygoo.cpp
View
@@ -4,6 +4,7 @@
#include <QDebug>
#include <qmath.h>
+#include <QRadialGradient>
DynamicGoo::DynamicGoo(b2World *world, QPoint p, int radius, QObject *parent):
Goo(radius,parent)
@@ -44,6 +45,9 @@ DynamicGoo::DynamicGoo(b2World *world, QPoint p, int radius, QObject *parent):
stickable=true;
maxJoints=7; //parameters
speed=50;
+ counter=10; //COUNTER FOR ANIMATION
+ rx=0; //Animation coordinate x
+ ry=0; //Animation coordinate y
type=DYNAMIC;
}
@@ -144,7 +148,7 @@ void DynamicGoo::moveToTarget(){
b2Vec2 dvec=(target->getVPosition()-getVPosition());
float d=qSqrt(dvec.x*dvec.x+dvec.y*dvec.y);
if (onGround && target->isOnGround() && d<distanceToJoint){
- double omega =(dP.x>0 ? speed*100*body->GetMass() : -speed*100*body->GetMass());
+ double omega =(dP.x>0 ? speed*100*body->GetMass() : -speed*100*body->GetMass());
body->SetAngularVelocity(omega);
body->ApplyForceToCenter(body->GetMass()*body->GetWorld()->GetGravity());
}
@@ -198,7 +202,26 @@ void DynamicGoo::paint(QPainter &p){
}
//paint goo
p.setPen(secondaryColor);
- p.setBrush(secondaryColor);
+
+ if (counter >=2) {
+ rx+=(rand()%5-2);
+ ry+=(rand()%5-2);
+ if (qAbs(rx)>15) rx=15*(rx/qAbs(rx));
+ if (qAbs(ry)>15) ry=15*(ry/qAbs(ry));
+ counter =0;
+ }
+
+ counter++;
+
+ QColor center=secondaryColor;
+ center.setRgb((center.red()+50 > 255 ? 255 : center.red()+50),(center.green()+50 > 255 ? 255 : center.green()+50),(center.blue()+50 > 255 ? 255 : center.blue()+50));
+
+
+ QRadialGradient rg(getPPosition().x()+rx,getPPosition().y()+ry,getRadius()+5);
+ rg.setColorAt(0,center);
+ rg.setColorAt(1,secondaryColor);
+
+ p.setBrush(rg);
p.drawEllipse(getPPosition(),getRadius(),getRadius());
}
View
@@ -27,12 +27,14 @@ class DynamicGoo :public Goo
b2World * world;// copy of the world
int speed; //Speed
bool sticked; //flag to know if is sticked to the ground
+
protected:
void moveToTarget(); //move to the target
QColor color; //Color for recognize type of dynamic goo
QColor secondaryColor; //For recognize secondary option
bool stickable; //Flag to know if is stickable
-
+ int counter; //ANIMATION COUNTER
+ int rx,ry; //ANIMATION COORDINATE
private slots:
View
@@ -11,6 +11,8 @@ Joint::Joint(Goo *a, Goo *b, b2World *world,bool child, QObject *parent):
this->b=b;
type=NORMAL;
if (!child) initialize(world);
+ animationValue=0.0;
+ counter=1;
}
void Joint::initialize(b2World * world){
@@ -31,17 +33,44 @@ void Joint::paint(QPainter &p){
pen.setBrush(lg);
pen.setWidth(4);
p.setPen(pen);
- QPoint a=toPoint(joint->GetBodyA()->GetPosition());
- QPoint b=toPoint(joint->GetBodyB()->GetPosition());
- p.drawLine(a,b);
- p.drawLine(a.x()-2,a.y()-2,b.x()+2,b.y()+2);
- p.drawLine(a.x()-1,a.y()-1,b.x()+1,b.y()+1);
- p.drawLine(a.x()-3,a.y()-3,b.x()+3,b.y()+3);
- p.drawLine(a.x()-4,a.y()-4,b.x()+4,b.y()+4);
- p.drawLine(a.x()+4,a.y()+4,b.x()-4,b.y()-4);
- p.drawLine(a.x()+3,a.y()+3,b.x()-3,b.y()-3);
- p.drawLine(a.x()+1,a.y()+1,b.x()-1,b.y()-1);
- p.drawLine(a.x()+2,a.y()+2,b.x()-2,b.y()-2);
+ drawLines(p);
+
+ if (counter>0){
+ counter++;
+ }
+ else if (counter<0){
+ counter--;
+ }
+ if ((qAbs(counter)==1) || !qAbs((counter)%3)){
+ animationValue+=0.06*(counter/qAbs(counter));
+ if (animationValue>=1.0){
+ counter=-1;
+ animationValue=1;
+ }
+ else if (animationValue<=0.0){
+ animationValue=0;
+ counter=+1;
+ }
+ }
+
+ QColor anColor(255,255,255);
+ if (a->getColor().blackF()<0.5 && b->getColor().blackF()<0.5)
+ anColor.setAlpha(30);
+
+ else
+ anColor.setAlpha(8);
+
+ lg=QLinearGradient(a->getPPosition(),b->getPPosition());
+ lg.setColorAt(0,Qt::transparent);
+ lg.setColorAt(1,Qt::transparent);
+ lg.setColorAt(animationValue,anColor);
+
+
+ pen.setBrush(lg);
+ p.setPen(pen);
+ drawLines(p);
+
+
}
void Joint::paintDebug(QPainter &p){
@@ -72,6 +101,20 @@ void Joint::status(){
}
}
+void Joint::drawLines(QPainter &p){
+ QPoint a=toPoint(joint->GetBodyA()->GetPosition());
+ QPoint b=toPoint(joint->GetBodyB()->GetPosition());
+ p.drawLine(a,b);
+ p.drawLine(a.x()-2,a.y()-2,b.x()+2,b.y()+2);
+ p.drawLine(a.x()-1,a.y()-1,b.x()+1,b.y()+1);
+ p.drawLine(a.x()-3,a.y()-3,b.x()+3,b.y()+3);
+ p.drawLine(a.x()-4,a.y()-4,b.x()+4,b.y()+4);
+ p.drawLine(a.x()+4,a.y()+4,b.x()-4,b.y()-4);
+ p.drawLine(a.x()+3,a.y()+3,b.x()-3,b.y()-3);
+ p.drawLine(a.x()+1,a.y()+1,b.x()-1,b.y()-1);
+ p.drawLine(a.x()+2,a.y()+2,b.x()-2,b.y()-2);
+}
+
b2Joint* Joint::getJoint(){
return joint;
}
View
@@ -24,6 +24,12 @@ class Joint : public QObject
b2Joint* joint; //The phisical joint
Goo *a,*b; //the two linked goo
virtual void status(); // function to check the status of the joint
+private:
+
+ //ANIMATION VARIABLE
+ float animationValue;
+ int counter;
+ void drawLines(QPainter & p);
signals:
void destroyJoint(Joint *j); //SIGNAL FOR DESTROY THIS JOINT
public slots:
View
@@ -6,8 +6,8 @@ RemovableGoo::RemovableGoo(b2World *world, QPoint point, int radius, QObject *pa
DynamicGoo(world,point,radius,parent)
{
type=REMOVIBLE;
- color=QColor(205,222,135); //the recognize color of normal dynamic goo is yellow;
- secondaryColor=Qt::black;
+ color=QColor(188,211,95);
+ secondaryColor=color;
}
//The only difference with dynamic goo is that the joint status is ignored.
View
@@ -3,8 +3,9 @@
StickyGoo::StickyGoo(b2World*world,QPoint point,int radius,QObject *parent) :
RemovableGoo(world,point,radius,parent)
{
- color=QColor(188,211,95);
- secondaryColor=QColor(188,211,95);
+
+ color=QColor(255,153,85);
+ secondaryColor=color;
stickness=100;
type=STICKY;
}

0 comments on commit 8aa6a8e

Please sign in to comment.