-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmap.cpp
More file actions
111 lines (93 loc) · 3.03 KB
/
Copy pathcmap.cpp
File metadata and controls
111 lines (93 loc) · 3.03 KB
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
#include "cmap.h"
#include <QtGui>
#include "citem.h"
cMap::cMap()
{
}
bool cMap::loadMap(QString path){
m_mapPath = path;
//load file
//file structure:
// name;info;width;backround;item_1;item_2;...item_n;
QFile file(m_mapPath);
int i;
QList <QString> itemsInStr, members, bgInStr,membersInItems;
QString data, filePath;
//control if can work with file
if(!file.open(QFile::ReadOnly | QFile::Text))
return false;
data = file.readAll();
file.close();
members = data.split(";");
//control basics
if(members[0] == "")
return false;
m_mapName = members[0];
m_info = members[1];
//width
bool ok;
m_sceneWidth = members[2].toInt(&ok , 10);
if(!ok)
return false;
//background
bgInStr = members[3].split(",");
m_bgPath = bgInStr[0];
m_bgRepeat = bgInStr[1].toInt(&ok, 10);
//get all items
i = 4;
while(members[i] != ""){
itemsInStr.append(members[i++]);
}
m_itemsPath.clear();
for(i = 0 ; i < itemsInStr.count() ; i++){
membersInItems = itemsInStr[i].split(",");
m_itemsPath.append(membersInItems[0]);
m_itemsX.append(membersInItems[1].toInt(&ok, 10));
m_itemsY.append(membersInItems[2].toInt(&ok, 10));
m_itemsZ.append(membersInItems[3].toInt(&ok, 10));
}
filePath = m_mapPath;
QString imageFolderPath = filePath.remove(".map",Qt::CaseSensitive);
imageFolderPath.append("_images/");
QDir imageFolder;
filePath.remove(filePath.split("/").last());
filePath = filePath.left(filePath.count()-1);
if(imageFolder.cd(imageFolderPath)){
if(!m_bgPath.startsWith(":/images/",Qt::CaseSensitive)){
m_bgPath = filePath + m_bgPath;
}
for(i = 0; i < m_itemsPath.count(); i++ ){
if(!m_itemsPath[i].startsWith(":/images/",Qt::CaseSensitive)){
m_itemsPath[i] = filePath + m_itemsPath[i];
}
}
}
return true;
}
bool cMap::mapToScene(){
extern CScene *scene;
QPixmap bg;
bg.load(m_bgPath);
int bgWidth = bg.width(), sceneWidth = scene->width(), bgRepeatCount = 0;
//***************************
//Tohle je zakomentované z důvodu kolize Hero s ostatnímy objekty na mapě
//Nutnost zabezpečit kolizi pouze s objekty v stejné Z hodnotě
//Kvůli pozadí pak hero zmizí ze scény úplně až se vyřeší kolize může se
//pozadí zobrazit odkomentováním téhle části
//***************************
/*for(int i = 0; i < sceneWidth; i+= bgWidth)
bgRepeatCount++;
CItem *background;
background = new CItem[bgRepeatCount];
if(m_bgRepeat == true){
for(int i = 0, ii = 0; i < sceneWidth; i+= bgWidth, ii++)
background[ii].SetItem(m_bgPath, i, 0, 1,BACKGROUND);
}
else
background[0].SetItem(m_bgPath, 0, 0, 1, BACKGROUND);*/
const int itemsCount = m_itemsPath.count();
CItem *item;
item = new CItem[itemsCount];
for(int i = 0; i < itemsCount; i++)
item[i].SetItem(m_itemsPath[i], m_itemsX[i], m_itemsY[i],m_itemsZ[i]);
}