-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap_Level_4.cpp
More file actions
217 lines (191 loc) · 7.42 KB
/
Copy pathMap_Level_4.cpp
File metadata and controls
217 lines (191 loc) · 7.42 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
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
#include "Map_Level_4.h"
Map_Level_4::Map_Level_4(): QObject(nullptr), Level_Map_Impl()
{
//初始化地图元素
level_4_Scene = new QGraphicsScene;
filePath = "../Map/level_4.txt";
map_4 = InitByFile(filePath);
//添加背景
QPixmap backgroundImage(":/back/img/background/level_4_back.jpg");
QGraphicsPixmapItem* backgroundItem = new QGraphicsPixmapItem(backgroundImage);
backgroundItem->setPos(0, 0);
level_4_Scene->addItem(backgroundItem);
int tileSize = 50;
for(int row = 0;row< map_4.size() ;++row)
{
for(int col = 0;col<map_4[static_cast<std::vector<int>::size_type>(row)].size();++col)
{
QGraphicsRectItem *tile = new QGraphicsRectItem(col * tileSize, row * tileSize, tileSize, tileSize);
switch (map_4[static_cast<std::vector<int>::size_type>(row)][static_cast<std::vector<int>::size_type>(col)])
{
case Magma:
{
QPixmap pixmap(":/level_4/img/block/Magma.jpg");
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(col*tileSize,row*tileSize);
level_4_Scene->addItem(pixmapItem);
break;
}
case Magma_dont_allow :
{
QPixmap pixmap(":/level_4/img/block/Magma.jpg");
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(col*tileSize,row*tileSize);
level_4_Scene->addItem(pixmapItem);
break;
}
case Weird_Fungus_Rock:
{
QPixmap pixmap(":/level_4/img/block/Weird_Fungus_Rock.jpg");
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(col*tileSize,row*tileSize);
level_4_Scene->addItem(pixmapItem);
break;
}
case TransmitBlockBack:
{
QPixmap pixmap(":/level_4/img/block/TransmitBlock.png");
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(col*tileSize,row*tileSize);
level_4_Scene->addItem(pixmapItem);
break;
}
case Netherrack:
{
QPixmap pixmap(":/level_4/img/block/Netherrack.jpg");
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(col*tileSize,row*tileSize);
level_4_Scene->addItem(pixmapItem);
break;
}
}
}
}
//Steve在地图三的初始化
m_Steve.setX(100);
m_Steve.setY(800);
level_4_Scene->addItem(&m_Steve);
m_Steve.setMap(this); // 设置Steve的地图指针
// 添加血量UI到场景
if (m_Steve.getHealthUI())
{
level_4_Scene->addItem(m_Steve.getHealthUI());
m_Steve.getHealthUI()->setPos(20, 20); // 设置血量UI的位置
}
//Enderman初始化
m_Enderman.setX(1700);
m_Enderman.setY(700);
level_4_Scene->addItem(&m_Enderman);
m_Enderman.setSteve(&m_Steve); // 设置Steve指针
m_Enderman.setScene(level_4_Scene); // 设置场景,用于添加血条UI
}
Map_Level_4::~Map_Level_4()
{
delete level_4_Scene;
}
void Map_Level_4::checkMagmaDamage(int x, int y)
{
const int col = x / 50;
const int row = y / 50;
// 检查是否在Magma方块上
if (row >= 0 && row < map_4.size() && col >= 0 && col < map_4[row].size())
{
if (map_4[row][col] == Magma || map_4[row][col] == Magma_dont_allow)
{
// 如果玩家站在Magma方块上,每0.5秒扣除3点生命值
m_Steve.takeDamage(3);
}
}
}
bool Map_Level_4::isRoad(int x, int y) const
{
const int col = x / 50;
const int row = y / 50;
if (row < 0 || row >= map_4.size() || col < 0 || col >= map_4[row].size())
{
return false;
}
const int blockType = map_4[row][col];
// 只在Magma方块上时进行伤害检测
if (blockType == Magma || blockType == Magma_dont_allow)
{
const_cast<Map_Level_4*>(this)->checkMagmaDamage(x, y);
}
return (blockType == 1 || blockType == 15 || blockType == 29);
}
bool Map_Level_4::isLadder(int x, int y) const
{
int col = x / 50; // assuming tileSize is 50
int row = y / 50;
if (row >= 0 && row < map_4.size() && col >= 0 && col < map_4[static_cast<std::vector<int>::size_type>(row)].size())
{
return map_4[static_cast<std::vector<int>::size_type>(row)][static_cast<std::vector<int>::size_type>(col)] ==22; // 修改为检查 map_1[row][col] 是否为 梯子
}
return false;
}
bool Map_Level_4::isTransmit(int x, int y) const
{
int col = x / 50; // assuming tileSize is 50
int row = y / 50;
if (row >= 0 && row < map_4.size() && col >= 0 && col < map_4[row].size()) {
return map_4[row][col] == 9; // 修改为检查 map_4[row][col] 是否为 9
}
return false;
}
bool Map_Level_4::isTransmitBack(int x, int y) const
{
int col = x / 50; // assuming tileSize is 50
int row = y / 50;
if (row >= 0 && static_cast<std::vector<int>::size_type>(row) < map_4.size() && col >= 0 && col < map_4[static_cast<std::vector<int>::size_type>(row)].size())
{
return map_4[static_cast<std::vector<int>::size_type>(row)][col] == 15; // 修改为检查 map_1[row][col] 是否为 15
}
return false;
}
bool Map_Level_4::isInteractive(int x, int y) const
{
//空实现
}
bool Map_Level_4::isTrigger(int x, int y) const
{
int col = x / 50;
int row = y / 50;
if (row >= 0 && static_cast<std::vector<int>::size_type>(row) < map_4.size() && col >= 0 && col < map_4[static_cast<std::vector<int>::size_type>(row)].size())
{
return map_4[static_cast<std::vector<int>::size_type>(row)][col] == Trigger;
}
return false;
}
void Map_Level_4::removeTrigger(int x, int y)
{
int col = x / 50;
int row = y / 50;
if (row >= 0 && static_cast<std::vector<int>::size_type>(row) < map_4.size() && col >= 0 && col < map_4[static_cast<std::vector<int>::size_type>(row)].size())
{
if (map_4[static_cast<std::vector<int>::size_type>(row)][col] == Trigger) {
map_4[static_cast<std::vector<int>::size_type>(row)][col] = Road;
QGraphicsPixmapItem* roadItem = new QGraphicsPixmapItem(QPixmap(":/level_4/img/block/Road.png"));
roadItem->setPos(col * 50, row * 50);
level_4_Scene->addItem(roadItem);
}
}
}
void Map_Level_4::setTrigger(int x, int y)
{
int col = x / 50;
int row = y / 50;
if (row >= 0 && row < map_4.size() && col >= 0 && col < map_4[row].size())
{
// 先检查该位置是否已经有Trigger
if (map_4[row][col] != Trigger)
{
map_4[row][col] = Trigger;
// 添加Trigger图片
QPixmap pixmap(":/level_4/img/block/Trigger.png");
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
pixmapItem->setPos(col * 50, row * 50);
pixmapItem->setData(0, "trigger"); // 设置标识符
level_4_Scene->addItem(pixmapItem);
}
}
}