1 /*
2 * DESCRIPCION DEL JUEGO
3 * Copyright (C) 2007 Javier P�rez Pacheco
4 *
5 * Este juego tienen licencia Creative Commons y se permite
6 * su modificacion y utilizacion libremente siempre y cuando se
7 * cite al autor original y se comparta con la misma licencia.
8 * No se permite su uso comercial.
9 *
10 * Para mas informacion visite la web:
11 * http://creativecommons.org/licenses/by-nc-sa/2.0/es/
12 *
13 * PROGRAMADOR
14 * Javier P�rez Pacheco
15 * Cadiz (Spain)
16 * javielinux@gmail.com
17 *
18 * GRAFISMO Y 3D
19 * Jesus Carrasco
20 * Cadiz (Spain)
21 * carrasco.carrasco@gmail.com
22 *
23 * MUSICA Y GRAFISMO
24 * Shano Lores
25 * Cadiz (Spain)
26 * shanakla@gmail.com
27 *
28 */
29
30 #include "class_editgame.h"
31
32 /*****************************
33 **
34 ** CLASE Door
35 **
36 ******************************/
37
38
EditDoor()39 EditDoor::EditDoor() : Door () {
40
41 }
42
~EditDoor()43 EditDoor::~EditDoor () {
44 unLoad();
45 }
46
setForcePosition(BoardPosition p)47 bool EditDoor::setForcePosition(BoardPosition p) {
48 if (!p.out) {
49 if ( (p.x==0) || (p.x==EditBoard::GetInstance()->getCols()-1)
50 || (p.y==0) || (p.y==EditBoard::GetInstance()->getRows()-1) ) {
51 xBoard = p.x;
52 yBoard = p.y;
53 if (p.x==0) {
54 setDoorPosition(LEFT);
55 setX(Plot::GetInstance()->getX(p.x,p.y)+(20*getCurrentScaleX()));
56 setY(Plot::GetInstance()->getY(p.x,p.y)-heightElement);
57 }
58 if (p.x==EditBoard::GetInstance()->getCols()-1) {
59 setDoorPosition(RIGHT);
60 setX(Plot::GetInstance()->getX(p.x,p.y)-(30*getCurrentScaleX()));
61 setY(Plot::GetInstance()->getY(p.x,p.y)-heightElement);
62 }
63 if (p.y==0) {
64 setDoorPosition(UP);
65 setX(Plot::GetInstance()->getX(p.x,p.y)-(23*getCurrentScaleX()));
66 setY(Plot::GetInstance()->getY(p.x,p.y)-heightElement);
67 }
68 if (p.y==EditBoard::GetInstance()->getRows()-1) {
69 setDoorPosition(DOWN);
70 setX(Plot::GetInstance()->getX(p.x,p.y)+(25*getCurrentScaleX()));
71 setY(Plot::GetInstance()->getY(p.x,p.y)-heightElement);
72 }
73
74 return true;
75
76 } else {
77 return false;
78 }
79 }
80 return false;
81 }
82
setForcePosition(int x,int y)83 bool EditDoor::setForcePosition(int x, int y) {
84 BoardPosition p;
85 p.x=x;
86 p.y=y;
87 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
88 return setForcePosition(p);
89 }
90
91 /*****************************
92 **
93 ** CLASE EditScenary
94 **
95 ******************************/
96
EditScenary()97 EditScenary::EditScenary() : Scenary () {
98 editable = true;
99 }
100
~EditScenary()101 EditScenary::~EditScenary () {
102 unLoad();
103 }
104
setTypeTiled(int t)105 void EditScenary::setTypeTiled(int t) {
106 if ( Missions::GetInstance()->currentLevel->existFile("tile_down.png")
107 && Missions::GetInstance()->currentLevel->existFile("tile_up.png") ) {
108
109 tileRight->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/tile_down.png");
110 tileRightUp->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/tile_up.png");
111 tileLeft->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/tile_down.png");
112 tileLeftUp->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/tile_up.png");
113
114 EditBoard::GetInstance()->getSceneEditGame()->typeTiled->setSensitive(false);
115 EditBoard::GetInstance()->tiledOfLevel = true;
116
117 } else {
118 if (t<BoardInfo::GetInstance()->getValueToInt("NTYPES_TILED")) {
119 typeTiled = t;
120 } else {
121 typeTiled = 0;
122 }
123
124 char tmp[4];
125 sprintf(tmp, "%d", typeTiled);
126
127 tileRight->changeFrameFileFromData(0, "/scenary/tile_"+string(tmp)+"_down.png");
128 tileRightUp->changeFrameFileFromData(0, "/scenary/tile_"+string(tmp)+"_up.png");
129 tileLeft->changeFrameFileFromData(0, "/scenary/tile_"+string(tmp)+"_down.png");
130 tileLeftUp->changeFrameFileFromData(0, "/scenary/tile_"+string(tmp)+"_up.png");
131
132 EditBoard::GetInstance()->getSceneEditGame()->typeTiled->setSensitive(true);
133 EditBoard::GetInstance()->tiledOfLevel = false;
134
135 }
136 }
137
setTypeTerrain(int t)138 void EditScenary::setTypeTerrain(int t) {
139
140 if ( Missions::GetInstance()->currentLevel->existFile("terrain.jpg") ) {
141
142 terrainOpened->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/terrain.jpg");
143
144 EditBoard::GetInstance()->getSceneEditGame()->typeTerrain->setSensitive(false);
145 EditBoard::GetInstance()->terrainOfLevel = true;
146
147 } else {
148 if (t<BoardInfo::GetInstance()->getValueToInt("NTYPES_TERRAIN")) {
149 typeTerrain = t;
150 } else {
151 typeTerrain = 0;
152 }
153
154 char tmp[4];
155 sprintf(tmp, "%d", typeTerrain);
156
157 terrainOpened->changeFrameFileFromData(0, "/scenary/terrain"+string(tmp)+".jpg");
158
159 EditBoard::GetInstance()->getSceneEditGame()->typeTerrain->setSensitive(true);
160 EditBoard::GetInstance()->terrainOfLevel = false;
161
162 }
163 }
164
setTypeWall(int t)165 void EditScenary::setTypeWall(int t) {
166
167 if ( Missions::GetInstance()->currentLevel->existFile("wallscenary.png") ) {
168
169 wallLeft->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/wallscenary.png");
170 wallRight->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath() + "/wallscenary.png");
171 EditBoard::GetInstance()->wallScennaryOfLevel = true;
172
173 } else {
174 if (t<BoardInfo::GetInstance()->getValueToInt("NTYPES_WALLSCENARY")) {
175 typeWall = t;
176 } else {
177 typeWall = 0;
178 }
179
180 char tmp[4];
181 sprintf(tmp, "%d", typeWall);
182
183 wallLeft->changeFrameFileFromData(0, "/scenary/wallscenary"+string(tmp)+".png");
184 wallRight->changeFrameFileFromData(0, "/scenary/wallscenary"+string(tmp)+".png");
185
186 EditBoard::GetInstance()->wallScennaryOfLevel = false;
187
188 }
189 }
190
draw()191 void EditScenary::draw() {
192 if (type==SCENARY_CLOSED) {
193 drawScenaryClosed();
194 } else {
195 drawScenaryOpened();
196 }
197 }
198
drawScenaryClosed()199 void EditScenary::drawScenaryClosed() {
200 wallLeft->draw();
201 wallRight->draw();
202
203 paintTiled();
204
205 shadowWall->draw();
206
207 if (editable && showGuides) {
208 guideLeft->draw();
209 guideRight->draw();
210 }
211
212 for (int i=0; i<(int)objects.size(); i++) {
213 objects[i]->draw();
214 }
215
216 for (int i=0; i<(int)objects.size(); i++) {
217 objects[i]->drawIcons();
218 }
219
220 }
221
drawScenaryOpened()222 void EditScenary::drawScenaryOpened() {
223 terrainOpened->draw();
224
225 if (editable && showGuides) {
226 guideLeft->draw();
227 guideRight->draw();
228 }
229
230 for (int i=0; i<(int)objects.size(); i++) {
231 objects[i]->draw();
232 }
233 paintTiled();
234
235 for (int i=0; i<(int)objects.size(); i++) {
236 objects[i]->drawIcons();
237 }
238 }
239
paintTiled()240 void EditScenary::paintTiled() {
241 int x, y;
242
243 for (y=0; y<nVerticalTiles; y++) {
244 for (x=0; x<EditBoard::GetInstance()->getCols()+1; x++) {
245 if (y==nVerticalTiles-1) {
246 tileRightUp->setX(Plot::GetInstance()->getX(x,0)-1);
247 tileRightUp->setY(Plot::GetInstance()->getY(x,0)+38-(y*separatedTilesClosed));
248 tileRightUp->draw();
249 tileLeftUp->setX(-Plot::GetInstance()->getX(x,0)+1);
250 tileLeftUp->setY(Plot::GetInstance()->getY(x,0)+38-(y*separatedTilesClosed));
251 tileLeftUp->draw();
252 } else {
253 tileRight->setX(Plot::GetInstance()->getX(x,0)-1);
254 tileRight->setY(Plot::GetInstance()->getY(x,0)+38-(y*separatedTilesClosed));
255 tileRight->draw();
256 tileLeft->setX(-Plot::GetInstance()->getX(x,0)+1);
257 tileLeft->setY(Plot::GetInstance()->getY(x,0)+38-(y*separatedTilesClosed));
258 tileLeft->draw();
259 }
260 }
261 }
262 }
263
264 /*****************************
265 **
266 ** CLASE EditBoard
267 **
268 ******************************/
269
270 EditBoard* EditBoard::instance = NULL;
271
EditBoard()272 EditBoard::EditBoard() : Group () {
273 multiLanguage = false;
274 rows = 6;
275 cols = 6;
276 typeFloor = 0;
277 typeWall = 0;
278 typePavement = 0;
279 indexz = 0;
280 posX = World::width/2;
281 posY = POSITION_Y_BOARD;
282 typeSize = BOARD_6X6;
283 hasEnemy1 = false;
284 hasEnemy2 = false;
285 hasEnemy3 = false;
286 hasBlackHole0 = false;
287 hasBlackHole1 = false;
288 hasKey = false;
289 hasTrap = false;
290 directionKey = "right";
291 hasTray = false;
292
293 town.name="";
294 town.province="";
295 town.nickname="";
296
297 helpName = "";
298
299 infoTown.clear();
300
301 typeMusic = -1;
302
303 hasMap = false;
304 fileFromDataMap = "";
305 fileFromLevelMap = "";
306
307 wallsOfLevel = false;
308 terrainOfLevel = false;
309 wallScennaryOfLevel = false;
310 musicOfLevel = false;
311 pavementOfLevel = false;
312 floorOfLevel = false;
313 tiledOfLevel = false;
314
315 }
316
GetInstance()317 EditBoard* EditBoard::GetInstance () {
318 if ( instance == NULL ) {
319 instance = new EditBoard();
320 }
321 return instance;
322 }
323
setTypeWall(int t)324 void EditBoard::setTypeWall(int t) {
325
326 if ( Missions::GetInstance()->currentLevel->existFile("wall_h.png")
327 && Missions::GetInstance()->currentLevel->existFile("wall_v.png") ) {
328
329 wallBottom->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath()+"/wall_h.png");
330 wallRight->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath()+"/wall_v.png");
331 sceneeditgame->typeWall->setSensitive(false);
332 wallsOfLevel = true;
333
334 } else {
335 if (t<BoardInfo::GetInstance()->getValueToInt("NTYPES_WALL")) {
336 typeWall = t;
337 } else {
338 typeWall = 0;
339 }
340
341 char tmp[128];
342
343 sprintf(tmp, "/board/wall_%d_h.png", typeWall);
344 wallBottom->changeFrameFileFromData(0, tmp);
345
346 sprintf(tmp, "/board/wall_%d_v.png", typeWall);
347 wallRight->changeFrameFileFromData(0, tmp);
348
349 sceneeditgame->typeWall->setSensitive(true);
350 wallsOfLevel = false;
351 }
352
353 }
354
setTypeFloor(int t)355 void EditBoard::setTypeFloor(int t) {
356
357 if ( Missions::GetInstance()->currentLevel->existFile("floor0.png")
358 && Missions::GetInstance()->currentLevel->existFile("floor1.png") ) {
359 floor0->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath()+"/floor0.png");
360 floor1->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath()+"/floor1.png");
361
362 sceneeditgame->typeFloor->setSensitive(false);
363 floorOfLevel = true;
364
365 } else {
366 if (t<BoardInfo::GetInstance()->getValueToInt("NTYPES_FLOOR")) {
367 typeFloor = t;
368 } else {
369 typeFloor = 0;
370 }
371
372 floor0->changeFrameFileFromData(0, "/board/floor", "png", typeFloor*2);
373 floor1->changeFrameFileFromData(0, "/board/floor", "png", (typeFloor*2)+1);
374
375 sceneeditgame->typeFloor->setSensitive(true);
376 floorOfLevel = false;
377 }
378
379 }
380
setTypePavement(int t)381 void EditBoard::setTypePavement(int t) {
382
383 if ( Missions::GetInstance()->currentLevel->existFile("pavement_bottom.png")
384 && Missions::GetInstance()->currentLevel->existFile("pavement_top.png") ) {
385
386 pavementTop->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath()+"/pavement_top.png");
387 pavementBottom->changeFrameFile(0, Missions::GetInstance()->currentLevel->getPath()+"/pavement_bottom.png");
388
389 sceneeditgame->typePavement->setSensitive(false);
390 pavementOfLevel = true;
391
392 } else {
393 if (t<BoardInfo::GetInstance()->getValueToInt("NTYPES_PAVEMENT")) {
394 typePavement = t;
395 } else {
396 typePavement = 0;
397 }
398
399 char tmp[128];
400
401 sprintf(tmp, "/board/pavement_%d_top.png", typePavement);
402 pavementTop->changeFrameFileFromData(0, tmp);
403
404 sprintf(tmp, "/board/pavement_%d_bottom.png", typePavement);
405 pavementBottom->changeFrameFileFromData(0, tmp);
406
407 sceneeditgame->typePavement->setSensitive(true);
408 pavementOfLevel = false;
409
410 }
411 }
412
setTypeSize(int t)413 void EditBoard::setTypeSize(int t) {
414 float s = 1.0;
415 typeSize = t;
416 int oldRows = rows;
417 int oldCols = cols;
418 switch(t) {
419 case BOARD_6X6:
420 pavementBottom->setY(179);
421 s = 1.0;
422 BoardScale::GetInstance()->setScale(s);
423 cols = 6;
424 rows = 6;
425 break;
426 case BOARD_7X7:
427 pavementBottom->setY(178);
428 s = 0.86;
429 BoardScale::GetInstance()->setScale(s);
430 cols = 7;
431 rows = 7;
432 break;
433 case BOARD_8X8:
434 pavementBottom->setY(182);
435 s = 0.76;
436 BoardScale::GetInstance()->setScale(s);
437 cols = 8;
438 rows = 8;
439 break;
440 case BOARD_9X9:
441 pavementBottom->setY(177);
442 s = 0.67;
443 BoardScale::GetInstance()->setScale(s);
444 cols = 9;
445 rows = 9;
446 break;
447 case BOARD_10X10:
448 pavementBottom->setY(178);
449 s = 0.61;
450 BoardScale::GetInstance()->setScale(s);
451 cols = 10;
452 rows = 10;
453 break;
454 }
455
456 floor0->setCurrentScale(s);
457 floor1->setCurrentScale(s);
458 trap->setCurrentScale(s);
459
460 scenary->scaleTiles(s);
461
462 wallRight->setCurrentScale(s);
463 wallRight->setScaleHeightElement(s);
464 wallRight->setScaleDisplacementX(s);
465
466 wallBottom->setCurrentScale(s);
467 wallBottom->setScaleHeightElement(s);
468 wallBottom->setScaleDisplacementX(s);
469
470 nimuh->setCurrentScale(s);
471 nimuh->setScaleHeightElement(s);
472
473 BoardPosition p;
474 if (nimuh->getPosition().x>=cols-1) {
475 p.x = cols-1;
476 } else {
477 p.x = nimuh->getPosition().x;
478 }
479 if (nimuh->getPosition().y>=rows-1) {
480 p.y = rows-1;
481 } else {
482 p.y = nimuh->getPosition().y;
483 }
484 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
485 nimuh->setForcePosition(p);
486
487 enemy1->setCurrentScale(s);
488 enemy1->setScaleHeightElement(s);
489
490 if (enemy1->getPosition().x>=cols-1) {
491 p.x = cols-1;
492 } else {
493 p.x = enemy1->getPosition().x;
494 }
495 if (enemy1->getPosition().y>=rows-1) {
496 p.y = rows-1;
497 } else {
498 p.y = enemy1->getPosition().y;
499 }
500 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
501
502 enemy1->setForcePosition(p);
503
504 enemy2->setCurrentScale(s);
505 enemy2->setScaleHeightElement(s);
506
507 if (enemy2->getPosition().x>=cols-1) {
508 p.x = cols-1;
509 } else {
510 p.x = enemy2->getPosition().x;
511 }
512 if (enemy2->getPosition().y>=rows-1) {
513 p.y = rows-1;
514 } else {
515 p.y = enemy2->getPosition().y;
516 }
517 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
518
519 enemy2->setForcePosition(p);
520
521 enemy3->setCurrentScale(s);
522 enemy3->setScaleHeightElement(s);
523
524 if (enemy3->getPosition().x>=cols-1) {
525 p.x = cols-1;
526 } else {
527 p.x = enemy3->getPosition().x;
528 }
529 if (enemy3->getPosition().y>=rows-1) {
530 p.y = rows-1;
531 } else {
532 p.y = enemy3->getPosition().y;
533 }
534 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
535
536 enemy3->setForcePosition(p);
537
538 blackHole0->setCurrentScale(s);
539 blackHole0->setScaleHeightElement(s);
540
541 if (blackHole0->getPosition().x>=cols-1) {
542 p.x = cols-1;
543 } else {
544 p.x = blackHole0->getPosition().x;
545 }
546 if (blackHole0->getPosition().y>=rows-1) {
547 p.y = rows-1;
548 } else {
549 p.y = blackHole0->getPosition().y;
550 }
551 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
552
553 blackHole0->setForcePosition(p);
554
555 blackHole1->setCurrentScale(s);
556 blackHole1->setScaleHeightElement(s);
557
558 if (blackHole1->getPosition().x>=cols-1) {
559 p.x = cols-1;
560 } else {
561 p.x = blackHole1->getPosition().x;
562 }
563 if (blackHole1->getPosition().y>=rows-1) {
564 p.y = rows-1;
565 } else {
566 p.y = blackHole1->getPosition().y;
567 }
568 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
569
570 blackHole1->setForcePosition(p);
571
572 door->setCurrentScale(s);
573 //door->setScaleHeightElement(s);
574
575 if (door->getPosition().x>=oldCols-1) {
576 p.x = cols-1;
577 } else {
578 p.x = door->getPosition().x;
579 }
580 if (door->getPosition().y>=oldRows-1) {
581 p.y = rows-1;
582 } else {
583 p.y = door->getPosition().y;
584 }
585 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
586
587 door->setForcePosition(p);
588
589 key->setCurrentScale(s);
590 key->setScaleHeightElement(s);
591
592 if (key->getPosition().x>=cols-1) {
593 p.x = cols-1;
594 } else {
595 p.x = key->getPosition().x;
596 }
597 if (key->getPosition().y>=rows-1) {
598 p.y = rows-1;
599 } else {
600 p.y = key->getPosition().y;
601 }
602 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
603
604 key->setForcePosition(p);
605
606 doorKeyBottom->setCurrentScale(s);
607 doorKeyBottom->setScaleHeightElement(s);
608
609 if (doorKeyBottom->getPosition().x>=cols-1) {
610 p.x = cols-1;
611 } else {
612 p.x = doorKeyBottom->getPosition().x;
613 }
614 if (doorKeyBottom->getPosition().y>=rows-1) {
615 p.y = rows-1;
616 } else {
617 p.y = doorKeyBottom->getPosition().y;
618 }
619 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
620
621 doorKeyBottom->setForcePosition(p);
622
623 doorKeyRight->setCurrentScale(s);
624 doorKeyRight->setScaleHeightElement(s);
625
626 if (doorKeyRight->getPosition().x>=cols-1) {
627 p.x = cols-1;
628 } else {
629 p.x = doorKeyRight->getPosition().x;
630 }
631 if (doorKeyRight->getPosition().y>=rows-1) {
632 p.y = rows-1;
633 } else {
634 p.y = doorKeyRight->getPosition().y;
635 }
636 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
637
638 doorKeyRight->setForcePosition(p);
639
640 tray->setCurrentScale(s);
641 tray->setScaleHeightElement(s);
642
643 if (tray->getPosition().x>=cols-1) {
644 p.x = cols-1;
645 } else {
646 p.x = tray->getPosition().x;
647 }
648 if (tray->getPosition().y>=rows-1) {
649 p.y = rows-1;
650 } else {
651 p.y = tray->getPosition().y;
652 }
653 p.out = !EditBoard::GetInstance()->positionIsOnBoard(p);
654
655 tray->setForcePosition(p);
656
657 floorOn->setCurrentScale(s);
658 floorOn->setScaleHeightElement(s);
659
660 MouseMapTile::GetInstance()->createMap();
661
662 }
663
loadLevel()664 void EditBoard::loadLevel() {
665
666 clear();
667
668 string f = Hash::getPathData() + "missions/" + Missions::GetInstance()->currentMission->getDirectory() + "/" + Missions::GetInstance()->currentLevel->getDirectory() + "/level.xml";
669
670 parseEditScreenXML((char*)f.c_str());
671
672
673 }
674
save()675 bool EditBoard::save() {
676
677 // verify
678
679 if ( (hasBlackHole0 && !hasBlackHole1) || (!hasBlackHole0 && hasBlackHole1) ) {
680 sceneeditgame->showMessageBox(Language::GetInstance()->getText("info"), Language::GetInstance()->getText("twoblackhole"), SCENE_EDITGAME_MAIN);
681 return false;
682 }
683
684 if (!hasEnemy1 && !hasEnemy2) {
685 sceneeditgame->showMessageBox(Language::GetInstance()->getText("info"), Language::GetInstance()->getText("oneenemy"), SCENE_EDITGAME_MAIN);
686 return false;
687 }
688
689 char tmp_val[128];
690
691 string file = Hash::getPathData() + "missions/" + Missions::GetInstance()->currentMission->getDirectory() + "/" + Missions::GetInstance()->currentLevel->getDirectory() + "/level.xml";
692
693 string chainFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<level>\n";
694
695 if (multiLanguage) {
696 chainFile += "\t<multilanguage value=\"true\" />\n";
697 }
698
699 chainFile += "\t<data>\n";
700
701 chainFile += "\t\t<town name=\"" + town.name + "\" province=\"" + town.province + "\">\n";
702
703 for (int i=0; i<(int)infoTown.size(); i++) {
704 chainFile += "\t\t\t<information button=\"" + infoTown[i].button + "\" title=\"" + infoTown[i].title + "\" text=\"" + WorkingData::GetInstance()->replace(infoTown[i].text, "|", " ") + "\" />\n";
705 }
706
707 chainFile += "\t\t</town>\n";
708
709 if (hasTray) {
710 for (int i=0; i<(int)infoTray.size(); i++) {
711 chainFile += "\t\t<info-tray lang=\"" + infoTray[i].lang + "\" title=\"" + infoTray[i].title + "\" text=\"" + infoTray[i].text + "\" />\n";
712 }
713 }
714
715 chainFile += "\t</data>\n";
716
717 if (hasMap) {
718 if (fileFromDataMap!="") {
719 chainFile += "\t<map file-fromdata=\"" + fileFromDataMap + "\" />\n";
720 } else {
721 chainFile += "\t<map file-fromlevel=\"" + fileFromLevelMap + "\" />\n";
722 }
723 for (int i=0; i<(int)map.size(); i++) {
724 chainFile += "\t\t<texts-map lang=\"" + map[i].lang + "\" title-1=\"" + map[i].title1 + "\" text-1=\"" + map[i].text1 + "\" title-2=\"" + map[i].title2 + "\" text-2=\"" + map[i].text2 + "\" distance-second-text=\"" + map[i].distanceSecondText + "\" />\n";
725 }
726 chainFile += "\t</map>\n";
727 }
728
729 string tsize = "6x6";
730 switch(typeSize) {
731 case BOARD_6X6:
732 tsize = "6x6";
733 break;
734 case BOARD_7X7:
735 tsize = "7x7";
736 break;
737 case BOARD_8X8:
738 tsize = "8x8";
739 break;
740 case BOARD_9X9:
741 tsize = "9x9";
742 break;
743 case BOARD_10X10:
744 tsize = "10x10";
745 break;
746 }
747
748 sprintf (tmp_val, "\t<board type=\"%s\" floor=\"%d\" wall=\"%d\" pavement=\"%d\" />\n", tsize.c_str(), typeFloor, typeWall, typePavement);
749 chainFile += tmp_val;
750
751 if (typeMusic>=0) {
752 sprintf (tmp_val, "\t<music type=\"%d\" />\n", typeMusic);
753 chainFile += tmp_val;
754 }
755
756 if (helpName!="") {
757 chainFile += "\t<help name=\"" + helpName + "\" />\n";
758 }
759
760 chainFile += scenary->toXML();
761
762 chainFile += "\t<objects>\n";
763
764 if (hasBlackHole0) {
765 sprintf (tmp_val, "\t\t<blackhole0 x=\"%d\" y=\"%d\" />\n", blackHole0->getXBoard(), blackHole0->getYBoard());
766 chainFile += tmp_val;
767 }
768 if (hasBlackHole1) {
769 sprintf (tmp_val, "\t\t<blackhole1 x=\"%d\" y=\"%d\" />\n", blackHole1->getXBoard(), blackHole1->getYBoard());
770 chainFile += tmp_val;
771 }
772 if (hasTrap) {
773 sprintf (tmp_val, "\t\t<trap x=\"%d\" y=\"%d\" />\n", posTrap.x, posTrap.y);
774 chainFile += tmp_val;
775 }
776 if (hasTray) {
777 sprintf (tmp_val, "\t\t<tray x=\"%d\" y=\"%d\" />\n", tray->getXBoard(), tray->getYBoard());
778 chainFile += tmp_val;
779 }
780 if (hasKey) {
781 sprintf (tmp_val, "\t\t<key x=\"%d\" y=\"%d\" />\n", key->getXBoard(), key->getYBoard());
782 chainFile += tmp_val;
783 if (directionKey=="right") {
784 sprintf (tmp_val, "\t\t<door-key x=\"%d\" y=\"%d\" direction=\"right\" />\n", doorKeyRight->getXBoard(), doorKeyRight->getYBoard());
785 chainFile += tmp_val;
786 } else {
787 sprintf (tmp_val, "\t\t<door-key x=\"%d\" y=\"%d\" direction=\"bottom\" />\n", doorKeyBottom->getXBoard(), doorKeyBottom->getYBoard());
788 chainFile += tmp_val;
789 }
790 }
791
792 chainFile += "\t</objects>\n";
793
794 chainFile += "\t<position>\n";
795
796 sprintf (tmp_val, "\t\t<exit x=\"%d\" y=\"%d\" />\n", door->getXBoard(), door->getYBoard());
797 chainFile += tmp_val;
798
799 sprintf (tmp_val, "\t\t<player x=\"%d\" y=\"%d\" />\n", nimuh->getXBoard(), nimuh->getYBoard());
800 chainFile += tmp_val;
801
802 if (hasEnemy1) {
803 sprintf (tmp_val, "\t\t<enemy1 x=\"%d\" y=\"%d\" />\n", enemy1->getXBoard(), enemy1->getYBoard());
804 chainFile += tmp_val;
805 }
806
807 if (hasEnemy2) {
808 sprintf (tmp_val, "\t\t<enemy2 x=\"%d\" y=\"%d\" />\n", enemy2->getXBoard(), enemy2->getYBoard());
809 chainFile += tmp_val;
810 }
811
812 if (hasEnemy3) {
813 sprintf (tmp_val, "\t\t<enemy3 x=\"%d\" y=\"%d\" />\n", enemy3->getXBoard(), enemy3->getYBoard());
814 chainFile += tmp_val;
815 }
816
817 chainFile += "\t</position>\n";
818
819 chainFile += "\t<walls>\n";
820
821 int x=0, y=0;
822 string w="";
823 bool todo = false;
824 for (y=0; y<rows; y++) {
825 for (x=0; x<cols; x++) {
826 w="";
827 todo = false;
828 if ( hasWallRight(x, y) ) {
829 w = w + " right=\"true\"";
830 todo = true;
831 }
832 if ( hasWallBottom(x, y) ) {
833 w = w + " bottom=\"true\"";
834 todo = true;
835 }
836 if (todo) {
837 sprintf (tmp_val, "\t\t<wall x=\"%d\" y=\"%d\"%s />\n", x, y, w.c_str());
838 chainFile += tmp_val;
839 }
840 }
841 }
842
843 chainFile += "\t</walls>\n";
844
845 chainFile += "</level>\n";
846
847 return WorkingData::GetInstance()->createFile(file, chainFile, true);
848
849 }
850
clear()851 void EditBoard::clear() {
852
853 hasEnemy1 = false;
854 hasEnemy2 = false;
855 hasEnemy3 = false;
856
857 hasBlackHole0 = false;
858 hasBlackHole1 = false;
859
860 hasKey = false;
861 hasTrap = false;
862 directionKey = "right";
863
864 hasTray = false;
865
866 for (int i=0; i<MAX_TILES_INLINE*MAX_TILES_INLINE; i++) {
867 walls[i].wallBottom = false;
868 walls[i].wallRight = false;
869 }
870 nimuh->setForcePosition(0,0);
871
872 enemy1->setForcePosition(0,0);
873 enemy2->setForcePosition(0,0);
874 enemy3->setForcePosition(0,0);
875 setTypeSize(BOARD_6X6);
876
877 wallsOfLevel = false;
878 wallScennaryOfLevel = false;
879 terrainOfLevel = false;
880 musicOfLevel = false;
881 pavementOfLevel = false;
882 floorOfLevel = false;
883 tiledOfLevel = false;
884
885 }
886
cleanWalls()887 void EditBoard::cleanWalls() {
888 for (int i=0; i<MAX_TILES_INLINE*MAX_TILES_INLINE; i++) {
889 walls[i].wallBottom = false;
890 walls[i].wallRight = false;
891 }
892
893 hasBlackHole0 = false;
894 hasBlackHole1 = false;
895
896 hasKey = false;
897 hasTrap = false;
898 directionKey = "right";
899
900 hasTray = false;
901
902 }
903
cleanScenary()904 void EditBoard::cleanScenary() {
905 scenary->clear();
906 }
907
getPositionPlayer()908 BoardPosition EditBoard::getPositionPlayer() {
909 return nimuh->getPosition();
910 }
911
getPositionEnemy1()912 BoardPosition EditBoard::getPositionEnemy1() {
913 return enemy1->getPosition();
914 }
915
getPositionEnemy2()916 BoardPosition EditBoard::getPositionEnemy2() {
917 return enemy2->getPosition();
918 }
919
getPositionEnemy3()920 BoardPosition EditBoard::getPositionEnemy3() {
921 return enemy3->getPosition();
922 }
923
setBlackHole0(int x,int y)924 void EditBoard::setBlackHole0(int x, int y) {
925 BoardPosition p;
926 p.x = x;
927 p.y = y;
928 p.out = !positionIsOnBoard(p);
929 blackHole0->setForcePosition(p);
930 hasBlackHole0 = true;
931 }
932
setBlackHole1(int x,int y)933 void EditBoard::setBlackHole1(int x, int y) {
934 BoardPosition p;
935 p.x = x;
936 p.y = y;
937 p.out = !positionIsOnBoard(p);
938 blackHole1->setForcePosition(p);
939 hasBlackHole1 = true;
940 }
941
setKey(int x,int y)942 void EditBoard::setKey(int x, int y) {
943 BoardPosition p;
944 p.x = x;
945 p.y = y;
946 p.out = !positionIsOnBoard(p);
947 key->setForcePosition(p);
948 hasKey = true;
949 }
950
setDoorKey(int x,int y,string dk)951 void EditBoard::setDoorKey(int x, int y, string dk) {
952 BoardPosition p;
953 p.x = x;
954 p.y = y;
955 p.out = !positionIsOnBoard(p);
956 doorKeyBottom->setForcePosition(p);
957 doorKeyRight->setForcePosition(p);
958 directionKey = dk;
959 hasKey = true;
960 }
961
setPositionPlayer(int x,int y)962 void EditBoard::setPositionPlayer(int x, int y) {
963 BoardPosition p;
964 p.x = x;
965 p.y = y;
966 p.out = !positionIsOnBoard(p);
967 posBegPlayer = p;
968 nimuh->setForcePosition(p);
969 }
970
setPositionEnemy1(int x,int y)971 void EditBoard::setPositionEnemy1(int x, int y) {
972 BoardPosition p;
973 p.x = x;
974 p.y = y;
975 p.out = !positionIsOnBoard(p);
976 posBegEnemy1 = p;
977 enemy1->setForcePosition(p);
978 hasEnemy1 = true;
979 }
980
setPositionEnemy2(int x,int y)981 void EditBoard::setPositionEnemy2(int x, int y) {
982 BoardPosition p;
983 p.x = x;
984 p.y = y;
985 p.out = !positionIsOnBoard(p);
986 posBegEnemy2 = p;
987 enemy2->setForcePosition(p);
988 hasEnemy2 = true;
989 }
990
setPositionEnemy3(int x,int y)991 void EditBoard::setPositionEnemy3(int x, int y) {
992 BoardPosition p;
993 p.x = x;
994 p.y = y;
995 p.out = !positionIsOnBoard(p);
996 posBegEnemy3 = p;
997 enemy3->setForcePosition(p);
998 hasEnemy3 = true;
999 }
1000
setPositionExit(int x,int y)1001 void EditBoard::setPositionExit(int x, int y) {
1002 BoardPosition p;
1003 p.x = x;
1004 p.y = y;
1005 p.out = !positionIsOnBoard(p);
1006 posExit= p;
1007 door->setForcePosition(p);
1008 }
1009
setPositionTrap(int x,int y)1010 void EditBoard::setPositionTrap(int x, int y) {
1011 posTrap.x = x;
1012 posTrap.y = y;
1013 posTrap.out = !positionIsOnBoard(posTrap);
1014 hasTrap = true;
1015 }
1016
setPositionTray(int x,int y)1017 void EditBoard::setPositionTray(int x, int y) {
1018 BoardPosition p;
1019 p.x = x;
1020 p.y = y;
1021 p.out = !positionIsOnBoard(p);
1022 tray->setInitialPosition(p);
1023 hasTray = true;
1024 sceneeditgame->handTray->setMovementNormalX(165, 500);
1025 sceneeditgame->btHandTray->setSensitive(true);
1026 }
1027
getPositionMouse()1028 BoardPosition EditBoard::getPositionMouse() {
1029
1030 int w = BoardScale::GetInstance()->getWTile();
1031 int h = BoardScale::GetInstance()->getHTile();
1032
1033 int mouse_x, mouse_y;
1034 SDL_PumpEvents();
1035 SDL_GetMouseState(&mouse_x, &mouse_y);
1036
1037 // impares con una columna menos
1038 int ncol = getCols() - (getCols()%2);
1039
1040 int x = ( ( mouse_x - ( (int)getX() - (w/2) - ((w/2)*ncol) ) ) / w ) - ncol/2;
1041
1042 int y = ( mouse_y - (int)getY() ) / h;
1043
1044 int off_x = ( ( mouse_x - ( (int)getX() - (w/2) - ((w/2)*ncol) ) ) % w );
1045
1046 int off_y = ( mouse_y - (int)getY() ) % h;
1047
1048 int off = MouseMapTile::GetInstance()->getPosMouse(off_x,off_y);
1049
1050 int x0 = x+y;
1051
1052 int y0;
1053 if (x==y+1) {
1054 y0 = -1;
1055 } else if (x>y+1) {
1056 y0 = -2;
1057 } else {
1058 y0 = abs(x-y);
1059 }
1060
1061 if (off==TILE_RIGHT) {
1062 x0++;
1063 } else if (off==TILE_LEFT) {
1064 if ( (x0==0) && (y0==0) ) {
1065 BoardPosition p;
1066 p.x = -1;
1067 p.y = -1;
1068 p.out = true;
1069 return p;
1070 }
1071 x0--;
1072 } else if (off==TILE_UP) {
1073 if ( (x0==0) && (y0==0) ) {
1074 BoardPosition p;
1075 p.x = -1;
1076 p.y = -1;
1077 p.out = true;
1078 return p;
1079 }
1080 y0--;
1081 } else if (off==TILE_DOWN) {
1082 y0++;
1083 }
1084
1085 BoardPosition p;
1086 p.x = x0;
1087 p.y = y0;
1088 p.out = !positionIsOnBoard(p);
1089
1090 return p;
1091 }
1092
positionIsOnBoard(BoardPosition p)1093 bool EditBoard::positionIsOnBoard(BoardPosition p) {
1094 if ( (p.x<0) || (p.x>=getRows()) ) {
1095 return false;
1096 }
1097 if ( (p.y<0) || (p.y>=getCols()) ) {
1098 return false;
1099 }
1100 return true;
1101 }
1102
hasWallBetweenCells(BoardPosition p1,BoardPosition p2)1103 bool EditBoard::hasWallBetweenCells(BoardPosition p1, BoardPosition p2) {
1104 if (p1.x+1 == p2.x) { // right
1105 return hasWallRight(p1.x, p1.y);
1106 } else if (p1.x-1 == p2.x) { // left
1107 return hasWallRight(p2.x, p2.y);
1108 } else if (p1.y+1 == p2.y) { // down
1109 return hasWallBottom(p1.x, p1.y);
1110 } else if (p1.y-1 == p2.y) { // up
1111 return hasWallBottom(p2.x, p2.y);
1112 }
1113 return false;
1114 }
1115
load()1116 void EditBoard::load() {
1117
1118 multiLanguage = false;
1119
1120 wallsOfLevel = false;
1121 wallScennaryOfLevel = false;
1122 terrainOfLevel = false;
1123 musicOfLevel = false;
1124 pavementOfLevel = false;
1125 floorOfLevel = false;
1126 tiledOfLevel = false;
1127
1128 town.name="";
1129 town.province="";
1130 town.nickname="";
1131
1132 infoTray.clear();
1133
1134 helpName = "";
1135
1136 hasMap = false;
1137 fileFromDataMap = "";
1138 fileFromLevelMap = "";
1139
1140 map.clear();
1141
1142 infoTown.clear();
1143
1144 floorShadow = new Element();
1145 floorShadow->setY(-50);
1146 floorShadow->setAlign(ALIGN_CENTER);
1147 floorShadow->addFrameFileFromData("/board/floor_shadow.png");
1148 floorShadow->show();
1149 floorShadow->setGroup(this);
1150
1151 floor0 = new Element();
1152 floor0->setAlign(ALIGN_CENTER);
1153 floor0->addFrameFileFromData("/board/floor_0000.png");
1154 floor0->show();
1155 floor0->setGroup(this);
1156
1157 floor1 = new Element();
1158 floor1->setAlign(ALIGN_CENTER);
1159 floor1->addFrameFileFromData("/board/floor_0001.png");
1160 floor1->show();
1161 floor1->setGroup(this);
1162
1163 pavementTop = new Element();
1164 pavementTop->setAlign(ALIGN_CENTER);
1165 pavementTop->setVAlign(VALIGN_BOTTOM);
1166 pavementTop->setY(186);
1167 pavementTop->addFrameFileFromData("/board/pavement_0_top.png");
1168 pavementTop->show();
1169 pavementTop->setGroup(this);
1170
1171 pavementBottom = new Element();
1172 pavementBottom->setAlign(ALIGN_CENTER);
1173 pavementBottom->setY(180);
1174 pavementBottom->addFrameFileFromData("/board/pavement_0_bottom.png");
1175 pavementBottom->show();
1176 pavementBottom->setGroup(this);
1177
1178 trap = new Element();
1179 trap->setAlign(ALIGN_CENTER);
1180 trap->addFrameFileFromData("/board/trap_0003.png");
1181 trap->setGroup(this);
1182
1183 blackHole0 = new ElementIsometric();
1184 blackHole0->setHeightElement(30);
1185 blackHole0->setAlign(ALIGN_CENTER);
1186
1187 blackHole0->addFrameFileFromData("/editgame/blackhole_1.png");
1188
1189 blackHole1 = new ElementIsometric();
1190 blackHole1->setHeightElement(30);
1191 blackHole1->setAlign(ALIGN_CENTER);
1192
1193 blackHole1->addFrameFileFromData("/editgame/blackhole_2.png");
1194
1195 blackHole0->setGroup(this);
1196 blackHole1->setGroup(this);
1197
1198 doorKeyBottom = new ElementIsometric();
1199 doorKeyBottom->addFrameFileFromData("/objects/grate_0000.png");
1200 doorKeyBottom->setAlign(ALIGN_RIGHT);
1201 doorKeyBottom->setHeightElement(60);
1202 doorKeyBottom->setDisplacementX(8);
1203 doorKeyBottom->setGroup(this);
1204
1205 doorKeyRight = new ElementIsometric();
1206 doorKeyRight->setFlip(true);
1207 doorKeyRight->addFrameFileFromData("/objects/grate_0000.png");
1208 doorKeyRight->setHeightElement(60);
1209 doorKeyRight->setDisplacementX(-8);
1210 doorKeyRight->setGroup(this);
1211
1212 key = new ElementIsometric();
1213 key->setHeightElement(20);
1214 key->setAlign(ALIGN_CENTER);
1215 key->addFrameFileFromData("/objects/key.png");
1216 key->setGroup(this);
1217
1218 tray = new ElementIsometric();
1219 tray->setHeightElement(20);
1220 tray->setAlign(ALIGN_CENTER);
1221
1222 tray->addFrameFileFromData("/objects/tray.png");
1223
1224 tray->setGroup(this);
1225
1226 scenary = new EditScenary();
1227
1228 door = new EditDoor();
1229 door->setGroup(this);
1230
1231 wallBottom = new ElementIsometric();
1232 wallBottom->addFrameFileFromData("/board/wall_0_h.png");
1233 wallBottom->setAlign(ALIGN_RIGHT);
1234 //wallTop->setVAlign(VALIGN_BOTTOM);
1235 wallBottom->setHeightElement(25);
1236 wallBottom->setDisplacementX(10.0);
1237 wallBottom->setGroup(this);
1238
1239 wallRight = new ElementIsometric();
1240 wallRight->addFrameFileFromData("/board/wall_0_v.png");
1241 //wallLeft->setVAlign(VALIGN_CENTER);
1242 //wallLeft->setAlign(ALIGN_RIGHT);
1243 wallRight->setHeightElement(25);
1244 wallRight->setDisplacementX(-10.0);
1245 wallRight->setGroup(this);
1246
1247 floorOn = new ElementIsometric();
1248 floorOn->setHeightElement(0);
1249 floorOn->setForcePosition(0,0);
1250 floorOn->setAlign(ALIGN_CENTER);
1251 floorOn->addFrameFileFromData("/editgame/floor_on.png");
1252 floorOn->setGroup(this);
1253
1254 nimuh = new ElementIsometric();
1255 nimuh->setHeightElement(120);
1256 nimuh->setForcePosition(0,0);
1257 nimuh->setAlign(ALIGN_CENTER);
1258 nimuh->addFrameFileFromData("/nimuh/nimuh_0012.png");
1259
1260 ghost = nimuh;
1261
1262 enemy1 = new ElementIsometric();
1263 enemy1->setHeightElement(110);
1264 enemy1->setForcePosition(0,0);
1265 enemy1->setAlign(ALIGN_CENTER);
1266 enemy1->addFrameFileFromData("/enemy1/enemy1_0012.png");
1267
1268 enemy2 = new ElementIsometric();
1269 enemy2->setHeightElement(100);
1270 enemy2->setForcePosition(0,0);
1271 enemy2->setAlign(ALIGN_CENTER);
1272 enemy2->addFrameFileFromData("/enemy2/enemy2_0012.png");
1273
1274 enemy3 = new ElementIsometric();
1275 enemy3->setHeightElement(110);
1276 enemy3->setForcePosition(0,0);
1277 enemy3->setAlign(ALIGN_CENTER);
1278 enemy3->addFrameFileFromData("/enemy3/enemy3_0004.png");
1279
1280 Animation a;
1281 a.setName("stop_right");
1282 a.addFrame(0);
1283 nimuh->addAnimation(a);
1284 enemy1->addAnimation(a);
1285 enemy2->addAnimation(a);
1286 enemy3->addAnimation(a);
1287
1288 nimuh->setGroup(this);
1289 enemy1->setGroup(this);
1290 enemy2->setGroup(this);
1291 enemy3->setGroup(this);
1292
1293
1294 }
1295
verifyPositions(BoardPosition p1,BoardPosition p2)1296 bool EditBoard::verifyPositions(BoardPosition p1, BoardPosition p2) {
1297 if ( (p1.x == p2.x) && (p1.y == p2.y) ) {
1298 return true;
1299 } else {
1300 return false;
1301 }
1302 }
1303
referencePositions(BoardPosition p1,BoardPosition p2)1304 int EditBoard::referencePositions(BoardPosition p1, BoardPosition p2) {
1305 if ( (p1.x-1 == p2.x) && (p1.y == p2.y) ) {
1306 return TILE_LEFT;
1307 } else if ( (p1.x+1 == p2.x) && (p1.y == p2.y) ) {
1308 return TILE_RIGHT;
1309 } else if ( (p1.x == p2.x) && (p1.y-1 == p2.y) ) {
1310 return TILE_UP;
1311 } else if ( (p1.x == p2.x) && (p1.y+1 == p2.y) ) {
1312 return TILE_DOWN;
1313 } else if ( (p1.x == p2.x) && (p1.y == p2.y) ) {
1314 return TILE_CENTER;
1315 } else {
1316 return TILE_OTHER;
1317 }
1318 }
1319
verifyClickOnBoard()1320 void EditBoard::verifyClickOnBoard() {
1321 insertObject(getPositionMouse());
1322 scenary->verifyClick ();
1323 }
1324
verifyUnClickOnBoard()1325 void EditBoard::verifyUnClickOnBoard() {
1326 scenary->removeDnd();
1327 }
1328
verifyMouseOnBoard()1329 void EditBoard::verifyMouseOnBoard() {
1330 scenary->onOver();
1331
1332 bool todoDefaultCursor = true;
1333
1334 BoardPosition p = getPositionMouse();
1335 if (!p.out) {
1336 string obj = sceneeditgame->bNimuh->getRadioButtonActive()->getParameter("object").c_str();
1337
1338 if (obj=="doorkey") {
1339 if (hasKey) {
1340
1341 if (verifyPositions(doorKeyRight->getPosition(), p)) {
1342 todoDefaultCursor = false;
1343 Cursor::GetInstance()->setCursor("rotate");
1344 }
1345
1346 }
1347
1348 }
1349
1350 }
1351
1352 if (todoDefaultCursor) Cursor::GetInstance()->setCursor("default");
1353 }
1354
draw()1355 void EditBoard::draw() {
1356
1357 // scenary
1358
1359 scenary->draw();
1360
1361 pavementTop->draw();
1362
1363 int x, y;
1364
1365
1366 for (y=0; y<rows; y++) {
1367
1368 for (x=0; x<cols; x++) {
1369 int res = 0;
1370 if (y%2==0) {
1371 res = 0;
1372 } else {
1373 res = 1;
1374 }
1375 bool todoFloor = true;
1376 if (hasTrap) {
1377 if ( (posTrap.x == x) && (posTrap.y == y) ) {
1378 trap->setX(Plot::GetInstance()->getX(x, y));
1379 trap->setY(Plot::GetInstance()->getY(x, y)-2);
1380 trap->draw();
1381 todoFloor = false;
1382 }
1383 }
1384 if (todoFloor) {
1385 if (x%2==res) {
1386 floor0->setX(Plot::GetInstance()->getX(x, y));
1387 floor0->setY(Plot::GetInstance()->getY(x, y));
1388 floor0->draw();
1389 } else {
1390 floor1->setX(Plot::GetInstance()->getX(x, y));
1391 floor1->setY(Plot::GetInstance()->getY(x, y));
1392 floor1->draw();
1393 }
1394 }
1395 }
1396
1397 }
1398
1399 floorShadow->draw();
1400
1401 // door
1402 if ( (door->getDoorPosition()==UP) || (door->getDoorPosition()==LEFT) ) {
1403 door->setAlpha(255);
1404 door->draw();
1405 }
1406
1407
1408 // objects
1409
1410 for (int s=0; s<=(rows-1)*2; s++) {
1411 for (int n=0; n<=s; n++) {
1412 x = n;
1413 y = s-n;
1414
1415 if (!(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))) {
1416 // light
1417 BoardPosition bpmouse = getPositionMouse();
1418 if (!bpmouse.out) {
1419 if ( (bpmouse.x == x) && (bpmouse.y == y) ) {
1420 if ( (ghost!=NULL) && (ghost!=door) ) {
1421 ghost->setAlpha(100);
1422 BoardPosition aux = ghost->getPosition();
1423 aux.out = false;
1424 ghost->setForcePosition(bpmouse);
1425 ghost->draw();
1426 ghost->setForcePosition(aux);
1427 ghost->setAlpha(255);
1428 } else {
1429 floorOn->setForcePosition(bpmouse);
1430 floorOn->draw();
1431 }
1432 }
1433 }
1434 }
1435
1436 if (positionIsOnBoard(getPositionFromXY(x,y))) {
1437
1438 if (hasBlackHole0) {
1439 if ( (blackHole0->getXBoard() == x) && (blackHole0->getYBoard() == y) ) {
1440 blackHole0->draw();
1441 }
1442 }
1443
1444 if (hasBlackHole1) {
1445 if ( (blackHole1->getXBoard() == x) && (blackHole1->getYBoard() == y) ) {
1446 blackHole1->draw();
1447 }
1448 }
1449
1450 if ( (nimuh->getXBoard() == x) && (nimuh->getYBoard() == y) ) {
1451 nimuh->setAlpha(255);
1452 nimuh->draw();
1453 }
1454 if ( (enemy1->getXBoard() == x) && (enemy1->getYBoard() == y) && hasEnemy1 ) {
1455 enemy1->setAlpha(255);
1456 enemy1->draw();
1457 }
1458 if ( (enemy2->getXBoard() == x) && (enemy2->getYBoard() == y) && hasEnemy2 ) {
1459 enemy2->draw();
1460 }
1461 if ( (enemy3->getXBoard() == x) && (enemy3->getYBoard() == y) && hasEnemy3 ) {
1462 enemy3->draw();
1463 }
1464
1465 if (hasKey) {
1466 if ( (key->getXBoard() == x) && (key->getYBoard() == y) ) {
1467 key->draw();
1468 }
1469 }
1470
1471 if (hasKey) {
1472
1473 if (directionKey == "right") {
1474 if ( (doorKeyRight->getXBoard() == x) && (doorKeyRight->getYBoard() == y) ) {
1475 doorKeyRight->draw();
1476 }
1477 } else {
1478 if ( (doorKeyBottom->getXBoard() == x) && (doorKeyBottom->getYBoard() == y) ) {
1479 doorKeyBottom->draw();
1480 }
1481 }
1482 }
1483
1484 if (hasTray) {
1485 if ( (tray->getXBoard() == x) && (tray->getYBoard() == y) ) {
1486 tray->draw();
1487 }
1488 }
1489
1490 // right wall
1491 if ( ( hasWallRight(x, y) ) && (x<getCols()) ) {
1492 BoardPosition bp;
1493 bp.x = x;
1494 bp.y = y;
1495 bp.out = !EditBoard::GetInstance()->positionIsOnBoard(bp);
1496 wallRight->setForcePosition(bp);
1497 wallRight->setAlpha(255);
1498 wallRight->draw();
1499 }
1500
1501 // bottom wall
1502 if ( ( hasWallBottom(x, y) ) && (y<getRows()) ) {
1503 BoardPosition bp;
1504 bp.x = x;
1505 bp.y = y;
1506 bp.out = !EditBoard::GetInstance()->positionIsOnBoard(bp);
1507 wallBottom->setForcePosition(bp);
1508 wallBottom->setAlpha(255);
1509 wallBottom->draw();
1510 }
1511
1512 }
1513
1514 }
1515 } // final objects
1516
1517
1518 pavementBottom->draw();
1519
1520 // door
1521 if ( (door->getDoorPosition()==DOWN) || (door->getDoorPosition()==RIGHT) ) {
1522 door->setAlpha(255);
1523 door->draw();
1524 }
1525
1526
1527 }
1528
insertObject(BoardPosition p)1529 void EditBoard::insertObject(BoardPosition p) {
1530 if (!p.out) {
1531 string obj = sceneeditgame->bNimuh->getRadioButtonActive()->getParameter("object").c_str();
1532
1533 if (obj=="nimuh") {
1534
1535 if (!verifyHasObject(obj, p)) nimuh->setForcePosition(p);
1536 }
1537
1538 if (obj=="enemy1") {
1539
1540 if (hasEnemy1) {
1541 if ( (enemy1->getXBoard() == p.x) && (enemy1->getYBoard() == p.y) ) {
1542 hasEnemy1 = false;
1543 }
1544 } else {
1545 hasEnemy1 = true;
1546 }
1547
1548 if (!verifyHasObject(obj, p)) enemy1->setForcePosition(p);
1549 }
1550
1551 if (obj=="enemy2") {
1552 if (hasEnemy2) {
1553 if ( (enemy2->getXBoard() == p.x) && (enemy2->getYBoard() == p.y) ) {
1554 hasEnemy2 = false;
1555 }
1556 } else {
1557 hasEnemy2 = true;
1558 }
1559
1560 if (!verifyHasObject(obj, p)) enemy2->setForcePosition(p);
1561 }
1562
1563 if (obj=="enemy3") {
1564 if (hasEnemy3) {
1565 if ( (enemy3->getXBoard() == p.x) && (enemy3->getYBoard() == p.y) ) {
1566 hasEnemy3 = false;
1567 }
1568 } else {
1569 hasEnemy3 = true;
1570 }
1571
1572 if (!verifyHasObject(obj, p)) enemy3->setForcePosition(p);
1573 }
1574
1575 if (obj=="wallbottom") {
1576 if (hasWallBottom(p.x, p.y))
1577 setWallBottom( p.x, p.y, false);
1578 else
1579 setWallBottom( p.x, p.y, true);
1580 }
1581
1582 if (obj=="wallright") {
1583 if (hasWallRight(p.x, p.y))
1584 setWallRight( p.x, p.y, false);
1585 else
1586 setWallRight( p.x, p.y, true);
1587 }
1588
1589 if (obj=="door") {
1590 door->setForcePosition(p);
1591 }
1592
1593 if (obj=="trap") {
1594 if (hasTrap) {
1595 if ( (posTrap.x == p.x) && (posTrap.y == p.y) ) {
1596 hasTrap = false;
1597 }
1598 } else {
1599 hasTrap = true;
1600 }
1601
1602 posTrap = p;
1603 }
1604
1605 if (obj=="tray") {
1606 if (hasTray) {
1607 if ( (tray->getXBoard() == p.x) && (tray->getYBoard() == p.y) ) {
1608 hasTray = false;
1609 sceneeditgame->handTray->setMovementNormalX(0, 500);
1610 sceneeditgame->btHandTray->setSensitive(false);
1611 infoTray.clear();
1612 }
1613 } else {
1614 hasTray = true;
1615 sceneeditgame->handTray->setMovementNormalX(165, 500);
1616 sceneeditgame->btHandTray->setSensitive(true);
1617 InfoTray it;
1618 it.title = "Titulo comida";
1619 it.text = "Coloca aqui el texto de la comida";
1620 infoTray.push_back(it);
1621 }
1622
1623 if (!verifyHasObject(obj, p)) tray->setForcePosition(p);
1624 }
1625
1626 if (obj=="blackhole1") {
1627 if (hasBlackHole0) {
1628 if ( (blackHole0->getXBoard() == p.x) && (blackHole0->getYBoard() == p.y) ) {
1629 hasBlackHole0 = false;
1630 }
1631 } else {
1632 hasBlackHole0 = true;
1633 }
1634
1635 if (!verifyHasObject(obj, p)) blackHole0->setForcePosition(p);
1636 }
1637
1638 if (obj=="blackhole2") {
1639 if (hasBlackHole1) {
1640 if ( (blackHole1->getXBoard() == p.x) && (blackHole1->getYBoard() == p.y) ) {
1641 hasBlackHole1 = false;
1642 }
1643 } else {
1644 hasBlackHole1 = true;
1645 }
1646
1647 if (!verifyHasObject(obj, p)) blackHole1->setForcePosition(p);
1648 }
1649
1650 if (obj=="key") {
1651 if (hasKey) {
1652 if ( (key->getXBoard() == p.x) && (key->getYBoard() == p.y) ) {
1653 hasKey = false;
1654 }
1655 } else {
1656 hasKey = true;
1657 }
1658
1659 if (!verifyHasObject(obj, p)) key->setForcePosition(p);
1660 }
1661
1662 if (obj=="doorkey") {
1663 if (hasKey) {
1664 if (directionKey=="right") {
1665 if ( (doorKeyRight->getXBoard() == p.x) && (doorKeyRight->getYBoard() == p.y) ) {
1666 directionKey = "bottom";
1667 ghost = doorKeyBottom;
1668 }
1669 } else {
1670 if ( (doorKeyBottom->getXBoard() == p.x) && (doorKeyBottom->getYBoard() == p.y) ) {
1671 directionKey = "right";
1672 ghost = doorKeyRight;
1673 }
1674 }
1675 doorKeyRight->setForcePosition(p);
1676 doorKeyBottom->setForcePosition(p);
1677 }
1678
1679 }
1680
1681 }
1682 }
1683
verifyHasObject(string obj,BoardPosition p)1684 bool EditBoard::verifyHasObject(string obj, BoardPosition p) {
1685
1686 if (obj != "nimuh") {
1687 if (verifyPositions(nimuh->getPosition(), p)) return true;
1688 }
1689
1690 if (obj != "enemy1") {
1691 if (hasEnemy1 && verifyPositions(enemy1->getPosition(), p)) return true;
1692 }
1693
1694 if (obj != "enemy2") {
1695 if (hasEnemy2 && verifyPositions(enemy2->getPosition(), p)) return true;
1696 }
1697
1698 if (obj != "enemy3") {
1699 if (hasEnemy3 && verifyPositions(enemy3->getPosition(), p)) return true;
1700 }
1701
1702 if (obj != "blackhole1") {
1703 if (hasBlackHole0 && verifyPositions(blackHole0->getPosition(), p)) return true;
1704 }
1705
1706 if (obj != "blackhole2") {
1707 if (hasBlackHole1 && verifyPositions(blackHole1->getPosition(), p)) return true;
1708 }
1709
1710 if (obj != "key") {
1711 if (hasKey && verifyPositions(key->getPosition(), p)) return true;
1712 }
1713
1714 if (obj != "tray") {
1715 if (hasTray && verifyPositions(tray->getPosition(), p)) return true;
1716 }
1717
1718 return false;
1719 }
1720
changeGhost()1721 void EditBoard::changeGhost() {
1722 string obj = sceneeditgame->bNimuh->getRadioButtonActive()->getParameter("object").c_str();
1723 bool hasObject = false;
1724 if (obj=="nimuh") {
1725 ghost = nimuh;
1726 hasObject = true;
1727 }
1728
1729 if (obj=="enemy1") {
1730 ghost = enemy1;
1731 hasObject = true;
1732 }
1733
1734 if (obj=="enemy2") {
1735 ghost = enemy2;
1736 hasObject = true;
1737 }
1738
1739 if (obj=="enemy3") {
1740 ghost = enemy3;
1741 hasObject = true;
1742 }
1743
1744 if (obj=="wallbottom") {
1745 ghost = wallBottom;
1746 hasObject = true;
1747 }
1748
1749 if (obj=="wallright") {
1750 ghost = wallRight;
1751 hasObject = true;
1752 }
1753
1754 if (obj=="door") {
1755 ghost = door;
1756 hasObject = true;
1757 }
1758
1759 if (obj=="blackhole1") {
1760 ghost = blackHole0;
1761 hasObject = true;
1762 }
1763
1764 if (obj=="blackhole2") {
1765 ghost = blackHole1;
1766 hasObject = true;
1767 }
1768
1769 if (obj=="key") {
1770 ghost = key;
1771 hasObject = true;
1772 }
1773
1774 if (obj=="tray") {
1775 ghost = tray;
1776 hasObject = true;
1777 }
1778
1779 if (obj=="doorkey") {
1780 if (directionKey == "right") {
1781 ghost = doorKeyRight;
1782 } else {
1783 ghost = doorKeyBottom;
1784 }
1785 hasObject = true;
1786 }
1787
1788 if (!hasObject) ghost = NULL;
1789 }
1790
unLoad()1791 void EditBoard::unLoad() {
1792
1793 delete door;
1794 delete scenary;
1795 delete floor0;
1796 delete floor1;
1797 delete wallBottom;
1798 delete wallRight;
1799 delete nimuh;
1800 delete enemy1;
1801 delete enemy2;
1802 delete enemy3;
1803
1804 delete blackHole0;
1805 delete blackHole1;
1806 delete doorKeyBottom;
1807 delete doorKeyRight;
1808 delete key;
1809 delete floorShadow;
1810
1811 delete pavementTop;
1812 delete pavementBottom;
1813
1814 delete floorOn;
1815
1816 }
1817
1818 /*****************************
1819 **
1820 ** FUNCIONES PARA TRABAJAR
1821 ** CON ARCHIVO XML
1822 **
1823 ******************************/
1824
1825
1826 /*****************************
1827 ** FUNCIONES PARA CARGAR SCREEN
1828 ******************************/
1829
1830
1831 typedef struct
1832 {
1833 int x, y;
1834 bool bottom, right;
1835 string direction;
1836 } DataEditScreenXML;
1837
1838
initDataEditScreenXML(DataEditScreenXML * dataScreen)1839 void initDataEditScreenXML(DataEditScreenXML *dataScreen) {
1840 dataScreen->x = 0;
1841 dataScreen->y = 0;
1842 dataScreen->bottom = false;
1843 dataScreen->right = false;
1844 }
1845
startEditScreenXML(void * userData,const char * el,const char ** attr)1846 static void startEditScreenXML(void *userData, const char *el, const char **attr) {
1847
1848 DataEditScreenXML* dataScreen = (DataEditScreenXML*)userData;
1849 int i;
1850
1851 //printf("el: %s\n", el);
1852
1853 if (strcmp(el, "multilanguage") == 0) {
1854 for (i = 0; attr[i]; i += 2) {
1855 if ( (strcmp(attr[i], "value") == 0) && (strcmp(attr[i+1], "true") == 0) ) {
1856 EditBoard::GetInstance()->multiLanguage = true;
1857 }
1858 }
1859 } else if (strcmp(el, "player") == 0) {
1860 for (i = 0; attr[i]; i += 2) {
1861 if (strcmp(attr[i], "x") == 0) {
1862 dataScreen->x = atoi(attr[i+1]);
1863 } else if (strcmp(attr[i], "y") == 0) {
1864 dataScreen->y = atoi(attr[i+1]);
1865 }
1866 }
1867 } else if (strcmp(el, "enemy1") == 0) {
1868 for (i = 0; attr[i]; i += 2) {
1869 if (strcmp(attr[i], "x") == 0) {
1870 dataScreen->x = atoi(attr[i+1]);
1871 } else if (strcmp(attr[i], "y") == 0) {
1872 dataScreen->y = atoi(attr[i+1]);
1873 }
1874 }
1875 } else if (strcmp(el, "enemy2") == 0) {
1876 for (i = 0; attr[i]; i += 2) {
1877 if (strcmp(attr[i], "x") == 0) {
1878 dataScreen->x = atoi(attr[i+1]);
1879 } else if (strcmp(attr[i], "y") == 0) {
1880 dataScreen->y = atoi(attr[i+1]);
1881 }
1882 }
1883 } else if (strcmp(el, "enemy3") == 0) {
1884 for (i = 0; attr[i]; i += 2) {
1885 if (strcmp(attr[i], "x") == 0) {
1886 dataScreen->x = atoi(attr[i+1]);
1887 } else if (strcmp(attr[i], "y") == 0) {
1888 dataScreen->y = atoi(attr[i+1]);
1889 }
1890 }
1891 } else if (strcmp(el, "exit") == 0) {
1892 for (i = 0; attr[i]; i += 2) {
1893 if (strcmp(attr[i], "x") == 0) {
1894 dataScreen->x = atoi(attr[i+1]);
1895 } else if (strcmp(attr[i], "y") == 0) {
1896 dataScreen->y = atoi(attr[i+1]);
1897 }
1898 }
1899 } else if (strcmp(el, "blackhole0") == 0) {
1900 for (i = 0; attr[i]; i += 2) {
1901 if (strcmp(attr[i], "x") == 0) {
1902 dataScreen->x = atoi(attr[i+1]);
1903 } else if (strcmp(attr[i], "y") == 0) {
1904 dataScreen->y = atoi(attr[i+1]);
1905 }
1906 }
1907 } else if (strcmp(el, "blackhole1") == 0) {
1908 for (i = 0; attr[i]; i += 2) {
1909 if (strcmp(attr[i], "x") == 0) {
1910 dataScreen->x = atoi(attr[i+1]);
1911 } else if (strcmp(attr[i], "y") == 0) {
1912 dataScreen->y = atoi(attr[i+1]);
1913 }
1914 }
1915 } else if (strcmp(el, "key") == 0) {
1916 for (i = 0; attr[i]; i += 2) {
1917 if (strcmp(attr[i], "x") == 0) {
1918 dataScreen->x = atoi(attr[i+1]);
1919 } else if (strcmp(attr[i], "y") == 0) {
1920 dataScreen->y = atoi(attr[i+1]);
1921 }
1922 }
1923 } else if (strcmp(el, "trap") == 0) {
1924 for (i = 0; attr[i]; i += 2) {
1925 if (strcmp(attr[i], "x") == 0) {
1926 dataScreen->x = atoi(attr[i+1]);
1927 } else if (strcmp(attr[i], "y") == 0) {
1928 dataScreen->y = atoi(attr[i+1]);
1929 }
1930 }
1931 } else if (strcmp(el, "tray") == 0) {
1932 for (i = 0; attr[i]; i += 2) {
1933 if (strcmp(attr[i], "x") == 0) {
1934 dataScreen->x = atoi(attr[i+1]);
1935 } else if (strcmp(attr[i], "y") == 0) {
1936 dataScreen->y = atoi(attr[i+1]);
1937 }
1938 }
1939 } else if (strcmp(el, "door-key") == 0) {
1940 for (i = 0; attr[i]; i += 2) {
1941 if (strcmp(attr[i], "x") == 0) {
1942 dataScreen->x = atoi(attr[i+1]);
1943 } else if (strcmp(attr[i], "y") == 0) {
1944 dataScreen->y = atoi(attr[i+1]);
1945 } else if (strcmp(attr[i], "direction") == 0) {
1946 dataScreen->direction = attr[i+1];
1947 }
1948 }
1949 } else if (strcmp(el, "town") == 0) {
1950 for (i = 0; attr[i]; i += 2) {
1951 if (strcmp(attr[i], "name") == 0) {
1952 EditBoard::GetInstance()->town.name = attr[i+1];
1953 } else if (strcmp(attr[i], "province") == 0) {
1954 EditBoard::GetInstance()->town.province = attr[i+1];
1955 } else if (strcmp(attr[i], "nickname") == 0) {
1956 EditBoard::GetInstance()->town.nickname = attr[i+1];
1957 }
1958 }
1959 } else if (strcmp(el, "info-tray") == 0) {
1960 InfoTray it;
1961 for (i = 0; attr[i]; i += 2) {
1962 if (strcmp(attr[i], "title") == 0) {
1963 it.title = attr[i+1];
1964 } else if (strcmp(attr[i], "text") == 0) {
1965 it.text = attr[i+1];
1966 } else if (strcmp(attr[i], "lang") == 0) {
1967 it.lang = attr[i+1];
1968 }
1969 }
1970 EditBoard::GetInstance()->infoTray.push_back(it);
1971 } else if (strcmp(el, "information") == 0) {
1972 InformationTown it;
1973 for (i = 0; attr[i]; i += 2) {
1974 if (strcmp(attr[i], "title") == 0) {
1975 it.title = attr[i+1];
1976 } else if (strcmp(attr[i], "text") == 0) {
1977 it.text = attr[i+1];
1978 } else if (strcmp(attr[i], "button") == 0) {
1979 it.button = attr[i+1];
1980 }
1981 }
1982 EditBoard::GetInstance()->getSceneEditGame()->addInfoTown(it);
1983 } else if (strcmp(el, "help") == 0) {
1984 for (i = 0; attr[i]; i += 2) {
1985 if (strcmp(attr[i], "name") == 0) {
1986 EditBoard::GetInstance()->helpName = attr[i+1];
1987 }
1988 }
1989 } else if (strcmp(el, "map") == 0) {
1990 EditBoard::GetInstance()->hasMap = true;
1991 for (i = 0; attr[i]; i += 2) {
1992 if (strcmp(attr[i], "file-fromdata") == 0) {
1993 EditBoard::GetInstance()->fileFromDataMap = attr[i+1];
1994 }
1995 if (strcmp(attr[i], "file-fromlevel") == 0) {
1996 EditBoard::GetInstance()->fileFromLevelMap = attr[i+1];
1997 }
1998 }
1999 } else if (strcmp(el, "texts-map") == 0) {
2000 EditMap em;
2001 for (i = 0; attr[i]; i += 2) {
2002 if (strcmp(attr[i], "title-1") == 0) {
2003 em.title1 = attr[i+1];
2004 } else if (strcmp(attr[i], "text-1") == 0) {
2005 em.text1 = attr[i+1];
2006 } else if (strcmp(attr[i], "title-2") == 0) {
2007 em.title2 = attr[i+1];
2008 } else if (strcmp(attr[i], "text-2") == 0) {
2009 em.text2 = attr[i+1];
2010 } else if (strcmp(attr[i], "lang") == 0) {
2011 em.lang = attr[i+1];
2012 } else if (strcmp(attr[i], "distance-second-text") == 0) {
2013 em.distanceSecondText = attr[i+1];
2014 }
2015 }
2016 EditBoard::GetInstance()->map.push_back(em);
2017 } else if (strcmp(el, "music") == 0) {
2018 for (i = 0; attr[i]; i += 2) {
2019 if (strcmp(attr[i], "type") == 0) {
2020 int music = atoi(attr[i+1]);
2021 EditBoard::GetInstance()->setTypeMusic(music);
2022 switch (music) {
2023 case 0:
2024 EditBoard::GetInstance()->getSceneEditGame()->radMusic0->setActive(true);
2025 break;
2026 case 1:
2027 EditBoard::GetInstance()->getSceneEditGame()->radMusic1->setActive(true);
2028 break;
2029 case 2:
2030 EditBoard::GetInstance()->getSceneEditGame()->radMusic2->setActive(true);
2031 break;
2032 case 3:
2033 EditBoard::GetInstance()->getSceneEditGame()->radMusic3->setActive(true);
2034 break;
2035 }
2036 }
2037 }
2038 } else if (strcmp(el, "board") == 0) {
2039 bool tb = false;
2040 for (i = 0; attr[i]; i += 2) {
2041 if ( (strcmp(attr[i], "type") == 0) && (strcmp(attr[i+1], "6x6") == 0) ) {
2042 EditBoard::GetInstance()->setTypeSize(BOARD_6X6);
2043 tb = true;
2044 }
2045 if ( (strcmp(attr[i], "type") == 0) && (strcmp(attr[i+1], "7x7") == 0) ) {
2046 EditBoard::GetInstance()->setTypeSize(BOARD_7X7);
2047 tb = true;
2048 }
2049 if ( (strcmp(attr[i], "type") == 0) && (strcmp(attr[i+1], "8x8") == 0) ) {
2050 EditBoard::GetInstance()->setTypeSize(BOARD_8X8);
2051 tb = true;
2052 }
2053 if ( (strcmp(attr[i], "type") == 0) && (strcmp(attr[i+1], "9x9") == 0) ) {
2054 EditBoard::GetInstance()->setTypeSize(BOARD_9X9);
2055 tb = true;
2056 }
2057 if ( (strcmp(attr[i], "type") == 0) && (strcmp(attr[i+1], "10x10") == 0) ) {
2058 EditBoard::GetInstance()->setTypeSize(BOARD_10X10);
2059 tb = true;
2060 }
2061 if (strcmp(attr[i], "floor") == 0) {
2062 EditBoard::GetInstance()->setTypeFloor(atoi(attr[i+1]));
2063 EditBoard::GetInstance()->getSceneEditGame()->typeFloor->setFrame(atoi(attr[i+1]));
2064 }
2065 if (strcmp(attr[i], "wall") == 0) {
2066 EditBoard::GetInstance()->setTypeWall(atoi(attr[i+1]));
2067 EditBoard::GetInstance()->getSceneEditGame()->typeWall->setFrame(atoi(attr[i+1]));
2068 }
2069 if (strcmp(attr[i], "pavement") == 0) {
2070 EditBoard::GetInstance()->setTypePavement(atoi(attr[i+1]));
2071 EditBoard::GetInstance()->getSceneEditGame()->typePavement->setFrame(atoi(attr[i+1]));
2072 }
2073 }
2074 if (!tb) EditBoard::GetInstance()->setTypeSize(BOARD_6X6);
2075 EditBoard::GetInstance()->getSceneEditGame()->typeBoard->setFrame(EditBoard::GetInstance()->getTypeSize());
2076 } else if (strcmp(el, "wall") == 0) {
2077 for (i = 0; attr[i]; i += 2) {
2078 if (strcmp(attr[i], "x") == 0) {
2079 dataScreen->x = atoi(attr[i+1]);
2080 } else if (strcmp(attr[i], "y") == 0) {
2081 dataScreen->y = atoi(attr[i+1]);
2082 } else if (strcmp(attr[i], "right") == 0) {
2083 if (strcmp(attr[i+1], "true")==0) {
2084 dataScreen->right = true;
2085 }
2086 } else if (strcmp(attr[i], "bottom") == 0) {
2087 if (strcmp(attr[i+1], "true")==0) {
2088 dataScreen->bottom = true;
2089 }
2090 }
2091 }
2092 } else if (strcmp(el, "scenary") == 0) {
2093 int r = 255, g = 255, b = 255, ntiles = 0, ttiled = 0, tterrain = 0, twallscenary = 0;
2094 for (i = 0; attr[i]; i += 2) {
2095 if (strcmp(attr[i], "type") == 0) {
2096 if (strcmp(attr[i+1], "opened") == 0) {
2097 EditBoard::GetInstance()->getScenary()->setType(SCENARY_OPENED);
2098 } else {
2099 EditBoard::GetInstance()->getScenary()->setType(SCENARY_CLOSED);
2100 }
2101 }
2102 if (strcmp(attr[i], "red") == 0) {
2103 r = atoi(attr[i+1]);
2104 }
2105 if (strcmp(attr[i], "green") == 0) {
2106 g = atoi(attr[i+1]);
2107 }
2108 if (strcmp(attr[i], "blue") == 0) {
2109 b = atoi(attr[i+1]);
2110 }
2111 if (strcmp(attr[i], "ntiles") == 0) {
2112 ntiles = atoi(attr[i+1]);
2113 }
2114 if (strcmp(attr[i], "type-tiled") == 0) {
2115 ttiled = atoi(attr[i+1]);
2116 }
2117 if (strcmp(attr[i], "type-terrain") == 0) {
2118 tterrain = atoi(attr[i+1]);
2119 }
2120 if (strcmp(attr[i], "type-wall") == 0) {
2121 twallscenary = atoi(attr[i+1]);
2122 }
2123 }
2124 if (EditBoard::GetInstance()->getScenary()->getType() == SCENARY_CLOSED) {
2125 EditBoard::GetInstance()->getScenary()->setColorInWalls(r, g, b);
2126 EditBoard::GetInstance()->getSceneEditGame()->colorWall->setFrame( EditBoard::GetInstance()->getSceneEditGame()->vcolorsWall->getIndexColor(r, g, b) );
2127 EditBoard::GetInstance()->getScenary()->setNVerticalTiles(ntiles);
2128 EditBoard::GetInstance()->getSceneEditGame()->nTilesClosed->setFrame(ntiles);
2129 EditBoard::GetInstance()->getScenary()->setTypeTiled(ttiled);
2130 EditBoard::GetInstance()->getSceneEditGame()->typeTiled->setFrame(ttiled);
2131 EditBoard::GetInstance()->getScenary()->setTypeWall(twallscenary);
2132 EditBoard::GetInstance()->getSceneEditGame()->typeWallScenary->setFrame(twallscenary);
2133 } else {
2134 EditBoard::GetInstance()->getScenary()->setNVerticalTiles(ntiles);
2135 EditBoard::GetInstance()->getSceneEditGame()->nTilesClosed->setFrame(ntiles);
2136 EditBoard::GetInstance()->getScenary()->setTypeTiled(ttiled);
2137 EditBoard::GetInstance()->getSceneEditGame()->typeTiled->setFrame(ttiled);
2138 EditBoard::GetInstance()->getScenary()->setTypeTerrain(tterrain);
2139 EditBoard::GetInstance()->getSceneEditGame()->typeTerrain->setFrame(tterrain);
2140 }
2141 } else if (strcmp(el, "object") == 0) {
2142 char name[32];
2143 int x = 30;
2144 int y = 0;
2145 int type = TYPEOBJECT_3D;
2146 float scale = 1.0;
2147 bool flip = false;
2148 bool lock = false;
2149 int origen = ORIGENOBJECT_GAME;
2150 string text = "";
2151 string font = "";
2152 int r = 255, g = 255, b = 255;
2153 int align = ALIGN_CENTER;
2154
2155 for (i = 0; attr[i]; i += 2) {
2156 if (strcmp(attr[i], "name") == 0) {
2157 strcpy(name, attr[i+1]);
2158 }
2159 if (strcmp(attr[i], "x") == 0) {
2160 x = atoi(attr[i+1]);
2161 }
2162 if (strcmp(attr[i], "y") == 0) {
2163 y = atoi(attr[i+1]);
2164 }
2165 if (strcmp(attr[i], "scale") == 0) {
2166 scale = atof(attr[i+1]);
2167 }
2168 if ( (strcmp(attr[i], "flip") == 0) && (strcmp(attr[i+1], "true") == 0) ) {
2169 flip = true;
2170 }
2171 if ( (strcmp(attr[i], "lock") == 0) && (strcmp(attr[i+1], "true") == 0) ) {
2172 lock = true;
2173 }
2174 if ( (strcmp(attr[i], "origen") == 0) && (strcmp(attr[i+1], "personal") == 0) ) {
2175 origen = ORIGENOBJECT_PERSONAL;
2176 }
2177 if (strcmp(attr[i], "text") == 0) {
2178 text = attr[i+1];
2179 }
2180 if (strcmp(attr[i], "font") == 0) {
2181 font = attr[i+1];
2182 }
2183 if (strcmp(attr[i], "align") == 0) {
2184 align = atoi(attr[i+1]);
2185 }
2186 if (strcmp(attr[i], "r") == 0) {
2187 r = atoi(attr[i+1]);
2188 }
2189 if (strcmp(attr[i], "g") == 0) {
2190 g = atoi(attr[i+1]);
2191 }
2192 if (strcmp(attr[i], "b") == 0) {
2193 b = atoi(attr[i+1]);
2194 }
2195 if (strcmp(attr[i], "type") == 0) {
2196 if (strcmp(attr[i+1], "2d") == 0) {
2197 type = TYPEOBJECT_2D;
2198 } else if (strcmp(attr[i+1], "3d") == 0) {
2199 type = TYPEOBJECT_3D;
2200 } else if (strcmp(attr[i+1], "text") == 0) {
2201 type = TYPEOBJECT_TEXT;
2202 }
2203 }
2204 }
2205 if (type == TYPEOBJECT_TEXT) {
2206 Color c;
2207 c.r = r;
2208 c.g = g;
2209 c.b = b;
2210 EditBoard::GetInstance()->getScenary()->addTextObject(text, font, align, c, x, y, scale, flip, lock);
2211 } else {
2212 EditBoard::GetInstance()->getScenary()->addObject(type, origen, name, x, y, scale, flip, lock);
2213 }
2214 }
2215
2216 }
2217
endEditScreenXML(void * userData,const char * el)2218 static void endEditScreenXML(void *userData, const char *el)
2219 {
2220 DataEditScreenXML* dataScreen = (DataEditScreenXML*)userData;
2221
2222 if (strcmp(el, "player") == 0) {
2223 EditBoard::GetInstance()->setPositionPlayer(dataScreen->x, dataScreen->y);
2224 initDataEditScreenXML(dataScreen);
2225 } else if (strcmp(el, "enemy1") == 0) {
2226 EditBoard::GetInstance()->setPositionEnemy1(dataScreen->x, dataScreen->y);
2227 initDataEditScreenXML(dataScreen);
2228 } else if (strcmp(el, "enemy2") == 0) {
2229 EditBoard::GetInstance()->setPositionEnemy2(dataScreen->x, dataScreen->y);
2230 initDataEditScreenXML(dataScreen);
2231 } else if (strcmp(el, "enemy3") == 0) {
2232 EditBoard::GetInstance()->setPositionEnemy3(dataScreen->x, dataScreen->y);
2233 initDataEditScreenXML(dataScreen);
2234 } else if (strcmp(el, "exit") == 0) {
2235 EditBoard::GetInstance()->setPositionExit(dataScreen->x, dataScreen->y);
2236 initDataEditScreenXML(dataScreen);
2237 } else if (strcmp(el, "blackhole0") == 0) {
2238 EditBoard::GetInstance()->setBlackHole0(dataScreen->x, dataScreen->y);
2239 initDataEditScreenXML(dataScreen);
2240 } else if (strcmp(el, "blackhole1") == 0) {
2241 EditBoard::GetInstance()->setBlackHole1(dataScreen->x, dataScreen->y);
2242 initDataEditScreenXML(dataScreen);
2243 } else if (strcmp(el, "key") == 0) {
2244 EditBoard::GetInstance()->setKey(dataScreen->x, dataScreen->y);
2245 initDataEditScreenXML(dataScreen);
2246 } else if (strcmp(el, "trap") == 0) {
2247 EditBoard::GetInstance()->setPositionTrap(dataScreen->x, dataScreen->y);
2248 initDataEditScreenXML(dataScreen);
2249 } else if (strcmp(el, "tray") == 0) {
2250 EditBoard::GetInstance()->setPositionTray(dataScreen->x, dataScreen->y);
2251 initDataEditScreenXML(dataScreen);
2252 } else if (strcmp(el, "door-key") == 0) {
2253 EditBoard::GetInstance()->setDoorKey(dataScreen->x, dataScreen->y, dataScreen->direction);
2254 initDataEditScreenXML(dataScreen);
2255 } else if (strcmp(el, "wall") == 0) {
2256 if (dataScreen->bottom) {
2257 EditBoard::GetInstance()->setWallBottom( dataScreen->x, dataScreen->y, true);
2258 }
2259 if (dataScreen->right) {
2260 EditBoard::GetInstance()->setWallRight( dataScreen->x, dataScreen->y, true);
2261 }
2262 initDataEditScreenXML(dataScreen);
2263 }
2264
2265
2266 }
2267
parseEditScreenXML(char fileXML[128])2268 void parseEditScreenXML(char fileXML[128]) {
2269 char buffer[8192];
2270 int done;
2271
2272 DataEditScreenXML dataScreen;
2273 initDataEditScreenXML(&dataScreen);
2274
2275 XML_Parser p = XML_ParserCreate(NULL);
2276 if (! p) {
2277 printf("Podra no tener suficiente memoria para el parser\n");
2278 }
2279
2280 XML_SetUserData(p, &dataScreen);
2281 XML_SetElementHandler(p, startEditScreenXML, endEditScreenXML);
2282
2283 FILE *file = fopen(fileXML, "r");
2284 if(!file)
2285 printf("Error abriendo archivo XML\n");
2286
2287 do
2288 {
2289 size_t len = fread(buffer, 1, sizeof(buffer), file);
2290 done = len < sizeof(buffer);
2291 //printf("%s\n", buffer);
2292 if(!XML_Parse(p, buffer, len, done)){
2293 printf("Error realizando el parse\n");
2294 }
2295 //parse_error(&data, XML_ErrorString(XML_GetErrorCode(data.parser)));
2296 }
2297 while(!done);
2298 fclose(file);
2299 }
2300