-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSLevel.cpp
executable file
·150 lines (127 loc) · 3.55 KB
/
PSLevel.cpp
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
#include "stdafx.h"
#include "PSMapMaker.h"
#include "PSLevel.h"
#include "mathFP.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CPSLevel::CPSLevel():
m_nCurMap(0)
{
m_map->SetAt(0, 0, BLOC_EXIT);
}
CPSLevel::~CPSLevel()
{
}
void
CPSLevel::MoveNextMap()
{
int curAngle= m_map[m_nCurMap].m_curAngle;
int curX= m_map[m_nCurMap].m_curX, curY= m_map[m_nCurMap].m_curY;
if(m_nCurMap == (NB_MAPS-1)){
return;
}
++m_nCurMap;
m_map[m_nCurMap].m_curAngle= curAngle;
m_map[m_nCurMap].SetAt(curX, curY, BLOC_VIDE);
}
void
CPSLevel::MovePreviousMap()
{
int curAngle= m_map[m_nCurMap].m_curAngle;
int curX= m_map[m_nCurMap].m_curX, curY= m_map[m_nCurMap].m_curY;
if(m_nCurMap == 0){
return;
}
--m_nCurMap;
m_map[m_nCurMap].m_curAngle= curAngle;
m_map[m_nCurMap].SetAt(curX, curY, BLOC_VIDE);
}
void
CPSLevel::MoveWalkingForward()
{
CPSBloc* pBloc= m_map[m_nCurMap].GetAt( m_map[m_nCurMap].m_curX, m_map[m_nCurMap].m_curY);
switch(m_map[m_nCurMap].m_curAngle){
case 0: pBloc->m_bWall&= ~DIR_RIGHT;break;
case 64: pBloc->m_bWall&= ~DIR_DOWN; break;
case 128: pBloc->m_bWall&= ~DIR_LEFT; break;
case 192: pBloc->m_bWall&= ~DIR_UP; break;
}
m_map[m_nCurMap].SetAt( m_map[m_nCurMap].m_curX + (Cos(m_map[m_nCurMap].m_curAngle)>>8),
m_map[m_nCurMap].m_curY + (Sin(m_map[m_nCurMap].m_curAngle)>>8),
BLOC_VIDE);
pBloc= m_map[m_nCurMap].GetAt( m_map[m_nCurMap].m_curX, m_map[m_nCurMap].m_curY);
switch(m_map[m_nCurMap].m_curAngle){
case 0: pBloc->m_bWall&= ~DIR_LEFT; break;
case 64: pBloc->m_bWall&= ~DIR_UP; break;
case 128: pBloc->m_bWall&= ~DIR_RIGHT;break;
case 192: pBloc->m_bWall&= ~DIR_DOWN; break;
}
}
void
CPSLevel::MoveWalkingBackward()
{
CPSBloc* pBloc= m_map[m_nCurMap].GetAt( m_map[m_nCurMap].m_curX, m_map[m_nCurMap].m_curY);
switch(m_map[m_nCurMap].m_curAngle){
case 0: pBloc->m_bWall&= ~DIR_LEFT; break;
case 64: pBloc->m_bWall&= ~DIR_UP; break;
case 128: pBloc->m_bWall&= ~DIR_RIGHT;break;
case 192: pBloc->m_bWall&= ~DIR_DOWN; break;
}
m_map[m_nCurMap].SetAt( m_map[m_nCurMap].m_curX - (Cos(m_map[m_nCurMap].m_curAngle)>>8),
m_map[m_nCurMap].m_curY - (Sin(m_map[m_nCurMap].m_curAngle)>>8),
BLOC_VIDE);
pBloc= m_map[m_nCurMap].GetAt( m_map[m_nCurMap].m_curX, m_map[m_nCurMap].m_curY);
switch(m_map[m_nCurMap].m_curAngle){
case 0: pBloc->m_bWall&= ~DIR_RIGHT;break;
case 64: pBloc->m_bWall&= ~DIR_DOWN; break;
case 128: pBloc->m_bWall&= ~DIR_LEFT; break;
case 192: pBloc->m_bWall&= ~DIR_UP; break;
}
}
CPSMap::CPSMap():
m_nBlocsUse(0),
m_minX(1000),
m_maxX(-1000),
m_minY(1000),
m_maxY(-1000),
m_curAngle(192)
{
memset(m_blocs, 0x0, sizeof(CPSBloc)*NB_BLOCS);
};
void
CPSMap::SetAt(int p_x, int p_y, int p_type)
{
int i;
m_curX= p_x;
m_curY= p_y;
for(i= 0; i < m_nBlocsUse; ++i){
if((m_blocs[i].m_posX == p_x) &&
(m_blocs[i].m_posY == p_y)){
if(p_type > m_blocs[i].m_type)
m_blocs[i].m_type= p_type;
return;
}
}
m_blocs[m_nBlocsUse].m_posX= p_x;
m_blocs[m_nBlocsUse].m_posY= p_y;
if(p_type > m_blocs[m_nBlocsUse].m_type) m_blocs[m_nBlocsUse].m_type= p_type;
if(p_x < m_minX) m_minX= p_x;
if(p_x >=m_maxX) m_maxX= p_x+1;
if(p_y < m_minY) m_minY= p_y;
if(p_y >=m_maxY) m_maxY= p_y+1;
++m_nBlocsUse;
}
CPSBloc*
CPSMap::GetAt(int p_x, int p_y)
{
int i;
for(i= 0; i < m_nBlocsUse; ++i){
if((m_blocs[i].m_posX == p_x) &&
(m_blocs[i].m_posY == p_y))
return m_blocs+i;
}
return 0;
}