@@ -23,10 +23,10 @@

#define RADIUS 18
#define INTERVALL 4
#define DELAY 20
#define DELAY 10

Level::Level(QRect geometry, QString level,RunFlag flag,bool multiWindow, QWidget *parent) :
QGLWidget(QGLFormat::defaultFormat(),parent)
Level::Level(QRect geometry, QString level,BackGroundWidget *bg,RunFlag flag,bool multiWindow, QWidget *parent) :
QWidget(parent), backGroundWidget(bg)
{
scale=1.0;
goal = 100;
@@ -74,7 +74,7 @@ Level::Level(QRect geometry, QString level,RunFlag flag,bool multiWindow, QWidge

//setup the step variable
//this one is the interval between step
step=1.0/60.0;
step=1.0/30.0;
//initialize variables for draggin goo
drag = false;
dragged=NULL;
@@ -185,6 +185,7 @@ void Level::initialize()
//Clean function
void Level::clean(){
//clear object bodies
backGroundWidget->clear();
for (int i=0;i<objects.length();i++){
world->DestroyBody(objects[i]->getBody());
delete objects[i];
@@ -269,6 +270,8 @@ void Level::moveOf(QPoint dP){
//Check if is possible
if (!limit.contains(view)) return;
translation=QPoint(xf,yf);
if (dP.x()/2 || dP.y()/2)
backGroundWidget->translated(translation);
}

//Create a joint
@@ -424,14 +427,9 @@ void Level::paintEvent(QPaintEvent *e){
p.save();
p.scale(scale,scale);
p.translate(translation);
paintBg(p);
for (int i=0;i<background.length();i++){
background[i]->setTranslate(translation);
background[i]->paint(p);
}

for (int i=0;i<ground.length();i++) ground[i]->paint(p);
if (target) target->paint(p);

if (drag && (dragged->getType()!=BALOON &&possibility.length()>1) && (showJointTimer>DELAY))
{
for (int i=0;i<possibility.length();i++)
@@ -778,17 +776,6 @@ void Level::towerLost(){

}

void Level::paintBg(QPainter &p){
QColor c1,c2;
c1.setRgb(95,141,211);
c2.setRgb(21,33,50);
QRadialGradient g(QPoint(0,height()/2),2*height());
g.setColorAt(0,c1);
g.setColorAt(1,c2);
p.setPen(Qt::transparent);
p.setBrush(g);
p.drawRect(limit.x(),+limit.y(),limit.width(),limit.height());
}

void Level::paintScore(QPainter &p){
QColor bg(0,0,0,200);
@@ -936,11 +923,16 @@ void Level::setLimit(QRect limit){
this->limit.setTopLeft(limit.topLeft()*scale);
this->limit.setSize(limit.size()*scale);
if (scale>1) this->translation=QPoint(-limit.topLeft().x(),limit.topLeft().y());
backGroundWidget->setLimit(limit);
backGroundWidget->translated(translation);
backGroundWidget->setScale(scale);
if (flag==DEBUG) qWarning()<<"SCALE"<<scale;
}

void Level::setGround(QPoint gCenter, QList<QPoint> gList){
ground.push_back(new Ground(world,gCenter,gList,this));
Ground * g=new Ground(world,gCenter,gList,this);
backGroundWidget->addGround(g);
ground.push_back(g);
if (flag==DEBUG) qWarning()<<"Ground created.";
}

@@ -966,7 +958,7 @@ void Level::setStartArea(int n, QRect area,int type){
y=area.y()+qrand()%area.height();
radius=RADIUS+(qrand()%(INTERVALL*2)-INTERVALL);

if (type==1) { //Create a standard gooo
if (type==0) { //Create a standard gooo
DynamicGoo* dg=new DynamicGoo(world,QPoint(x,y),radius);
goos.push_back(dg);
connect(dg,SIGNAL(nextTargetPlease(Goo*)),this,SLOT(giveTarget(Goo*)));
@@ -975,7 +967,7 @@ void Level::setStartArea(int n, QRect area,int type){
connect(dg,SIGNAL(createSticky(QPoint)),this,SLOT(createSticky(QPoint)));
connect(dg,SIGNAL(checkForNeighbors(QPoint)),this,SLOT(checkForNeighbors(QPoint)));
}
else if (type==0){ //Create a removable goo
else if (type==1){ //Create a removable goo
RemovableGoo* rg=new RemovableGoo(world,QPoint(x,y),radius);
goos.push_back(rg);
connect(rg,SIGNAL(nextTargetPlease(Goo*)),this,SLOT(giveTarget(Goo*)));
@@ -1181,6 +1173,7 @@ void Level::addBGShape(int id, QPolygon poly, QColor color){
}
else {
BackGround *bg=new BackGround(id,this);
backGroundWidget->addBackGround(bg);
bg->addPolygon(poly,color);
bg->setDelta(0.3*(3-id));
background.push_back(bg);
12 level.h
@@ -2,7 +2,7 @@
#define LEVEL_H

//#include <QWidget> <--To use without opengl
#include <QGLWidget>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QTimerEvent>
@@ -27,6 +27,8 @@

#include "qb2draw.h"

#include "backgroundwidget.h"

#include <stickylink.h>


@@ -36,15 +38,16 @@ enum RunFlag {STANDARD, DEBUG};
//This is the Scene Widget
//It initialize evrithing
//The world (b2World) object is here
class Level : public QGLWidget //QWidget <--To use without openGL
class Level : public QWidget //QWidget <--To use without openGL
{
Q_OBJECT
public:
explicit Level(QRect geometry,QString level,RunFlag flag = STANDARD,bool multiWindow=false,QWidget *parent = 0); //Geometry is needed to have the display dimension information, level is the level to load
explicit Level(QRect geometry,QString level,BackGroundWidget *bg,RunFlag flag = STANDARD,bool multiWindow=false,QWidget *parent = 0); //Geometry is needed to have the display dimension information, level is the level to load
~Level();
//Function to start the level;
bool startLevel();


private:
float scale;
//Run type flag
@@ -108,6 +111,7 @@ class Level : public QGLWidget //QWidget <--To use without openGL
// bool parseString(QString string); //Split a line of the file in the two component the tag and the real information
// bool parseInfo(QString tag,QString info); //Recognize the tag and use the info

BackGroundWidget * backGroundWidget; //This is a widget to draw the semi-static ground and background.

//INITIALIZE FUNCTION
void initialize();
@@ -133,8 +137,8 @@ class Level : public QGLWidget //QWidget <--To use without openGL
bool createJoints(QPoint p); //Function to create



//Funcion to draw background, score and win
void paintBg(QPainter &p);
void paintScore(QPainter &p);
void paintWin(QPainter &p);

@@ -1,7 +1,7 @@
#ifndef LEVELSELECTOR_H
#define LEVELSELECTOR_H

#include <QGLWidget>
#include <QWidget>
#include <QPainter>
#include <QMouseEvent>
#include <QDir>
@@ -1,6 +1,6 @@
#include "mainmenu.h"
#define MAINMENULEVEL "mainmenu.level"
MainMenu::MainMenu(QRect geometry, RunFlag flag, bool multiWindow, QWidget *parent) :
Level(geometry,MAINMENULEVEL,flag,multiWindow,parent)
{
}
//#include "mainmenu.h"
//#define MAINMENULEVEL "mainmenu.level"
//MainMenu::MainMenu(QRect geometry, RunFlag flag, bool multiWindow, QWidget *parent) :
// Level(geometry,MAINMENULEVEL,flag,multiWindow,parent)
//{
//}
@@ -1,18 +1,18 @@
#ifndef MAINMENU_H
#define MAINMENU_H
//#ifndef MAINMENU_H
//#define MAINMENU_H

#include "level.h"
//#include "level.h"

class MainMenu : public Level
{
Q_OBJECT
public:
explicit MainMenu(QRect geometry,RunFlag flag=STANDARD,bool multiWindow=false ,QWidget *parent = 0);
//class MainMenu : public Level
//{
// Q_OBJECT
//public:
// explicit MainMenu(QRect geometry,RunFlag flag=STANDARD,bool multiWindow=false ,QWidget *parent = 0);

signals:
//signals:

public slots:
//public slots:

};
//};

#endif // MAINMENU_H
//#endif // MAINMENU_H
@@ -52,29 +52,30 @@ void MainWidget::levelSelected()//Create the level selected
{

if (multiwindow) this->hide();
bgWidget =new BackGroundWidget(this);
bgWidget->setGeometry(0,0,geometry.width(),geometry.height());
bgWidget->show();

if (multiwindow){
if (!debug)
level=new Level(geometry,levelS->getLevelSelected(),STANDARD,true); //Create the level
level=new Level(geometry,levelS->getLevelSelected(),bgWidget,STANDARD,true,bgWidget); //Create the level
else{
level=new Level(geometry,levelS->getLevelSelected(),DEBUG,true); //Create the level
level=new Level(geometry,levelS->getLevelSelected(),bgWidget,DEBUG,true,bgWidget); //Create the level
qWarning()<<"Level object created";
}
}
else {
if (!debug)
level=new Level(geometry,levelS->getLevelSelected(),STANDARD,false,this); //Create the level
level=new Level(geometry,levelS->getLevelSelected(),bgWidget,STANDARD,false,this); //Create the level
else{
level=new Level(geometry,levelS->getLevelSelected(),DEBUG,false,this); //Create the level
level=new Level(geometry,levelS->getLevelSelected(),bgWidget,DEBUG,false,this); //Create the level
qWarning()<<"Level object created";
}
}

delete levelS;
levelS=NULL;

this->repaint();

connect(level,SIGNAL(closing()),this,SLOT(close()));//Connect the closing of the level with the closing of the game
connect(level,SIGNAL(eventBackToMainMenu()),this,SLOT(backToMainMenu()));
if (level->startLevel()){
@@ -91,6 +92,7 @@ void MainWidget::backToMainMenu()
this->show();
qWarning()<<"BackToMainMenu!";
delete level;
delete bgWidget;
levelS=new LevelSelector(geometry,this);//Create the level selector
levelS->show();//Show the level selector
level=NULL;
@@ -1,10 +1,11 @@
#ifndef MAINWIDGET_H
#define MAINWIDGET_H

#include <QGLWidget>
#include <QWidget>
#include <QCloseEvent>
#include "level.h"
#include "levelselector.h"
#include "backgroundwidget.h"

class MainWidget : public QWidget
{
@@ -16,6 +17,7 @@ class MainWidget : public QWidget
private:
Level *level;
LevelSelector *levelS;
BackGroundWidget * bgWidget;

QRect geometry;
bool debug;
@@ -20,7 +20,7 @@ void StickyLink::checkStatus(){
// qWarning()<<joint->GetReactionForce(1.0/60).Length();
if (goo==NULL || joint==NULL) return;
if (goo->isDragging() || !goo->hasJoint()) emit destroySticky();
else if (joint->GetReactionForce(1.0/60).Length()>strength){
else if (joint->GetReactionForce(1.0/60).Length()>strength*2){
//qWarning()<<this->strength<<joint->GetReactionForce(1.0/60.0).Length();
emit destroySticky(); //If the force > of the maximum force barke the link!
}