1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
| //qgraphicscene et qgraphicview ne sont pas utilisees dans ce programme
// schema2.cpp = texture1.cpp + texture2.cpp + caisse.cpp + personnage.cpp
// schema1.cpp = texture1 + texture2
#include "schema2b.h"
#include <QTimer>
#include <QApplication>
#include <QPainter>
#include <QPixmap>
#include <QColor>
#include <QLabel>
#include <QPolygon>
#include <QVector>
#include <QPushButton>
#include <QVBoxLayout>
//include <QWidget>
// liste x et y coordonnee de deplacement
// liste x
QVector <int> liste_x()
{ QVector <int> list ;
list << 200 << 250 << 250 << 250 << 250 << 400 << 400 << 400 ;
list << 400 << 250 << 250 << 250 << 250 << 100 << 100 << 100 ;
list << 100 << 100 << 100 << 100 << 100 << 0 << 0 << 0 ;
list << 0 << 50 << 100 << 250 << 50 << 100 << 100 << 100 ;
list << 100 << 300 << 300 << 300 << 300 << 400 << 400 << 400 ;
list << 400 << 250 << 250 << 250 << 250 << 250 << 250 << 400 ;
list << 400 << 400 << 400 << 300 << 250 << 50 ;
return list ;
}
// liste y
QVector <int> liste_y()
{ QVector <int> list ;
list << 200 << 200 << 200 << 300 << 300 << 300 << 300 << 400;
list << 400 << 400 << 400 << 450 << 450 << 450 << 450 << 400 ;
list << 350 << 250 << 400 << 450 << 450 << 450 << 450 << 250 ;
list << 250 << 250 << 250 << 250 << 250 << 250 << 250 << 450 ;
list << 450 << 450 << 450 << 400 << 400 << 400 << 400 << 300 ;
list << 300 << 300 << 250 << 0 << 300 << 100 << 100 << 100 ;
list << 100 << 0 << 0 << 0 << 0 << 0 ;
return list ;
}
//elements personnage ,caisse,unite texture blanc legerement bleu,unité texture mur bleu
QPixmap caisse()
{ QPixmap csse(50, 50) ;
QColor gris1(200, 200, 200) ;
QColor gris2(80, 80, 80) ;
csse.fill(gris1) ;
QPolygon triangl1 ;
QPolygon triangl2 ;
QPolygon triangl3 ;
QPolygon triangl4 ;
triangl1.setPoints(3, 5, 10, 20, 25, 5, 40) ;
triangl2.setPoints(3, 10, 45, 25, 30, 40, 45) ;
triangl3.setPoints(3, 45, 10, 30, 25, 45, 40) ;
triangl4.setPoints(3, 10, 5, 25, 20, 40, 5) ;
QPainter crayo(&csse) ;
crayo.drawRect(1, 1, 48, 48) ;
crayo.drawRect(2, 2, 46, 46) ;
crayo.drawRect(0, 0, 47, 47) ;
crayo.setBrush(gris2) ;
crayo.drawPolygon(triangl1) ;
crayo.drawPolygon(triangl2) ;
crayo.drawPolygon(triangl3) ;
crayo.drawPolygon(triangl4) ;
crayo.end() ;
return csse ;
}
QPixmap personaj1()
{ QPixmap prsj1(50, 50) ;
QColor brun(145, 70, 0) ;
QColor noir(0, 0, 0) ;
prsj1.fill(brun) ;
QPolygon triangl ;
triangl.setPoints(3, 18, 21, 20,18,22,21) ;
QPainter crayo(&prsj1) ;
crayo.fillRect(0, 0, 40, 10,noir ) ;
crayo.fillRect(6,14, 8, 6,noir) ;
crayo.fillRect(26,14, 8, 6, noir) ;
crayo.setBrush(noir) ;
crayo.drawPolygon(triangl) ;
crayo.drawRect(8,28,24 ,4 ) ;
crayo.drawRect(8, 26, 2, 2) ;
crayo.end() ;
return prsj1 ;
}
QPixmap blancbleufct()
{ QPixmap blancbleu(23, 23);
QPainter crayon(&blancbleu) ;
QColor couleur1(255, 255, 255) ;
int xline = 0 ;
int val1 = 0 ;
int val2 = 0 ;
int yline = 0 ;
for (xline = 0 ; xline < 23 ; xline++)
{ val1 = 255 - xline * 3 ;
yline = xline ;
couleur1.setRgb(val1,val1,255) ;
crayon.setPen(couleur1) ;
crayon.drawLine(0,yline,xline,0) ;
val2 = 255 - 69 - xline * 3 ;
couleur1.setRgb(val2, val2, 255) ;
crayon.setPen(couleur1) ;
crayon.drawLine(xline,23,23,yline) ;
}
crayon.end() ;
return blancbleu ;
}
QPixmap murfct()
{ QPixmap mur(25,25) ;
mur.fill(Qt::black) ;
int x1 = 0 ;
int x2 = 0 ;
int y2 = 0 ;
int y1 = 0 ;
int val1 = 0 ;
int val2 = 0 ;
QColor couleur1(0, 0, 0) ;
QColor couleur2(0, 0, 0) ;
QPainter crayon(&mur) ;
for(x1 = 1 ;x1 < 13;x1++)
{ x2 = 25 - x1 ;
y1 = x1 ;
val1 = 110 + x1 * 10 ;
couleur1.setRgb(0, 0, val1 ) ;
crayon.setPen(couleur1) ;
crayon.drawLine(x1,y1,x2,y1) ;
y2 = 25 - x1 ;
crayon.drawLine(x1,y2,x2,y2) ;
val2 = 230 - val1 ;
couleur2.setRgb(0, 0, val2) ;
crayon.setPen(couleur2) ;
crayon.drawLine(x1, y1, x1, y2) ;
crayon.drawLine(x2, y1, x2, y2) ;
}
crayon.end() ;
return mur ;
}
//alistfct() et blistefct() sont les coordonnées de remplissage texture1 et texture2 alist
QVector <int> alistfct()
{ QVector <int> alist ;
alist << 0<< 0<< 0<< 0<< 0<< 0<< 0<< 0<< 0<< 0 ;
alist << 25<< 25<< 25<< 25<< 25<< 25<< 25<< 25<< 25<< 25 ;
alist << 50<< 50<< 50<< 50<< 50<< 50 ;
alist << 75<< 75<< 75<< 75<< 75<< 75 ;
alist << 100<< 100<< 125<< 125 ;
alist << 150<< 150<< 150<< 150<< 150<< 150<< 150<< 150 ;
alist << 175<< 175<< 175<< 175<< 175<< 175<< 175<< 175 ;
alist << 200<< 200<< 200<< 200<< 200<< 200<< 200<< 200<< 200<< 200 ;
alist << 225<< 225<< 225<< 225<< 225<< 225<< 225<< 225<< 225<< 225 ;
alist << 250<< 250<< 275<< 275 ;
alist << 300<< 300<< 300<< 300<< 300<< 300<< 300<< 300 ;
alist << 325<< 325<< 325<< 325<< 325<< 325<< 325<< 325 ;
alist << 350<< 350<< 350<< 350<< 350<< 350<< 350<< 350 ;
alist << 375<< 375<< 375<< 375<< 375<< 375<< 375<< 375 ;
alist << 400<< 400<< 400<< 400<< 425<< 425<< 425<< 425 ;
alist << 450<< 450<< 450<< 450<< 450<< 450<< 450<< 450<< 450<< 450<< 450<< 450 ;
alist << 475<< 475<< 475<< 475<< 475<< 475<< 475<< 475<< 475<< 475<< 475<< 475 ;
return alist ;
}
QVector <int> blistfct()
{ QVector <int> blist ;
blist << 0<< 25<< 50<< 75<< 100<< 125<< 150<< 175<< 200<< 225 ;
blist << 0<< 25<< 50<< 75<< 100<< 125<< 150<< 175<< 200<< 225 ;
blist << 300<< 325<< 350<< 375<< 400<< 425 ;
blist << 300<< 325<< 350<< 375<< 400<< 425 ;
blist << 200<< 225<< 200<< 225 ;
blist << 50<< 75<< 200<< 225<< 350<< 375<< 400<< 425 ;
blist << 50<< 75<< 200<< 225<< 350<< 375<< 400<< 425 ;
blist << 50<< 75<< 100<< 125<< 300<< 325<< 350<< 375<< 400<< 425 ;
blist << 50<< 75<< 100<< 125<< 300<< 325<< 350<< 375<< 400<< 425 ;
blist << 350<< 375<< 350<< 375 ;
blist << 50<< 75<< 200<< 225<< 250<< 275<< 350<< 375 ;
blist << 50<< 75<< 200<< 225<< 250<< 275<< 350<< 375 ;
blist << 50<< 75<< 200<< 225<< 350<< 375<< 450<< 475 ;
blist << 50<< 75<< 200<< 225<< 350<< 375<< 450<< 475 ;
blist << 200<< 225<< 450<< 475 << 200<< 225<< 450<< 475 ;
blist << 0 << 25<< 50<< 75<< 100<< 125<< 300<< 325<< 400<< 425 << 450<< 475;
blist << 0<< 25<< 50<< 75<< 100<< 125<< 300<< 325<< 400<< 425 << 450<< 475;
return blist ;
}
//-----------------------------------------------------------------------------------
int main(int argc,char ** argv)
{ QApplication app(argc,argv) ;
QPixmap fond(500, 500);
fond.fill(Qt::black);
QPixmap elmnt ;
elmnt = blancbleufct() ;
QPixmap elmnt2 ;
elmnt2 = murfct() ;
//remplissage de texture
QVector <int> xlist = alistfct() ;
QVector <int> ylist = blistfct() ;
int xh = 0 ;
int xh1 = 0 ;
int yh1 = 0 ;
QPainter crayon2(&fond) ;
for (xh = 0 ;xh < 21 ;xh++)
{ if (xh == 20)
{ yh1 += 25 ; xh = 0 ; }
xh1 = xh * 25 ;
crayon2.drawPixmap(xh1,yh1,elmnt) ;
if ((yh1 == 475) and (xh == 19))
{ xh = 21;}
}
crayon2.end() ;
xh1 = 0 ;
yh1 = 0 ;
QPainter crayon3(&fond) ;
for (xh = 0;xh < 140; xh++)
{ xh1 = xlist.at(xh) ;
yh1 = ylist.at(xh) ;
crayon3.drawPixmap(xh1, yh1, elmnt2) ;
}
crayon3.end() ;
//----------------------------------------------------------------
QTimer * temporel = new QTimer ;
temporel->setInterval(33) ;
//utilisation des coordonnees de deplacements
QPixmap elmnt3 ;
QPixmap elmnt4 ;
elmnt3 = caisse() ;
elmnt4 = personaj1() ;
QVector <int> listx ;
listx = liste_x() ;
QVector <int> listy ;
listy = liste_y() ;
//-----------------------------------------------------------------
QLabel * mlabel = new QLabel ;
mlabel->setPixmap(fond) ;
mlabel->show() ;
QPushButton * mbouton = new QPushButton("ACTIVE DEMO") ;
mbouton->setFixedSize(100, 50);
QVBoxLayout * vlayout = new QVBoxLayout ;
vlayout->addWidget(mlabel) ;
vlayout->addWidget(mbouton,0,Qt::AlignHCenter) ;
QWidget * fenetre = new QWidget ;
fenetre->setLayout(vlayout) ;
Level obj ;
obj.config1(mlabel,fenetre) ;
obj.config2(elmnt4,elmnt3,fond) ;
obj.config3(listx, listy) ;
obj.config4() ;
fenetre->show() ;
QObject::connect(mbouton, SIGNAL(clicked()), temporel, SLOT(start()) ) ;
QObject::connect(temporel, SIGNAL(timeout()), &obj, SLOT(choix()) ) ;
QObject::connect(&obj,SIGNAL(vermovc()), &obj, SLOT(movcaiss()) ) ;
QObject::connect(&obj,SIGNAL(vermovp()), &obj, SLOT(movpersonaj()) ) ;
QObject::connect(&obj, SIGNAL(verinc()), &obj, SLOT(inc()) ) ;
QObject::connect(&obj, SIGNAL(refresh()), &obj, SLOT(deroul()) ) ;
QObject::connect(&obj, SIGNAL(suite()),temporel, SLOT(start()) ) ;
QObject::connect(&obj, SIGNAL(fin()),temporel, SLOT(stop()) ) ;
app.exec() ;
return 0 ;
} |
Partager