-
Notifications
You must be signed in to change notification settings - Fork 0
/
door.c
147 lines (123 loc) · 4.16 KB
/
door.c
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
/*****************************************************/
/* Ultimate Blocks */
/* Copyright (c) An Ly 2000, Owen Rudge 2001, 2008 */
/*****************************************************/
#include <allegro.h>
#include "blocks3.h"
int map_backup[20][15][2];
void Door(void)
{
int i, j, k;
for (k = 0; k < 2; k++)
for (j = 0; j < 15; j++)
for (i = 0; i < 20; i++)
map_backup[i][j][k] = map_door[i][j][k];
for (i = 0; i < switches_count; i++)
{
if (map[switches[i].x][switches[i].y][switches[i].z] & SWITCH)
map[switches[i].x][switches[i].y][switches[i].z] = 0;
}
i = 0;
while (((switches[i].c != RED) ||
(map[switches[i].x][switches[i].y][switches[i].z]) ||
(Player_On(switches[i].x, switches[i].y, 0)) ||
(Player_On(switches[i].x, switches[i].y, 1))) &&
(i < switches_count))
{
i++;
}
if (i == switches_count)
Open_Doors(RED);
else
Close_Doors(RED);
i = 0;
while (((switches[i].c != GREEN) ||
(map[switches[i].x][switches[i].y][switches[i].z]) ||
(Player_On(switches[i].x, switches[i].y, 0)) ||
(Player_On(switches[i].x, switches[i].y, 1))) &&
(i < switches_count))
{
i++;
}
if (i == switches_count)
Open_Doors(GREEN);
else
Close_Doors(GREEN);
i = 0;
while (((switches[i].c != BLUE) ||
(map[switches[i].x][switches[i].y][switches[i].z]) ||
(Player_On(switches[i].x, switches[i].y, 0)) ||
(Player_On(switches[i].x, switches[i].y, 1))) &&
(i < switches_count))
{
i++;
}
if (i == switches_count)
Open_Doors(BLUE);
else
Close_Doors(BLUE);
for (k = 0; k < 2; k++)
{
for (j = 0; j < 15; j++)
{
for (i = 0; i < 20; i++)
{
if (map_backup[i][j][k] != map_door[i][j][k])
{
if (map_door[i][j][k] == 0) DirtyList(i*_block_width, j*_block_height, k*_block_depth, _block_width, _block_height+_block_depth, blank);
if (map_door[i][j][k] == RED) DirtyList(i*_block_width, j*_block_height, k*_block_depth, _block_width, _block_height+_block_depth, door_pic[0]);
if (map_door[i][j][k] == GREEN) DirtyList(i*_block_width, j*_block_height, k*_block_depth, _block_width, _block_height+_block_depth, door_pic[1]);
if (map_door[i][j][k] == BLUE) DirtyList(i*_block_width, j*_block_height, k*_block_depth, _block_width, _block_height+_block_depth, door_pic[2]);
}
}
}
}
for (i = 0; i < switches_count; i++)
{
if (map[switches[i].x][switches[i].y][switches[i].z] == 0)
{
map[switches[i].x][switches[i].y][switches[i].z] = switches[i].c + SWITCH;
DirtyList(switches[i].x*_block_width, switches[i].y*_block_height, switches[i].z*_block_depth, _block_width, _block_height+_block_depth, blank);
}
}
}
void Open_Doors(int c)
{
int i;
for (i = 0; i < door_count; i++)
{
if ((door[i].c == c) && (map[door[i].x][door[i].y][door[i].z] & DOOR))
{
map[door[i].x][door[i].y][door[i].z] = 0;
map_door[door[i].x][door[i].y][door[i].z] = 0;
}
}
}
void Close_Doors(int c)
{
int i;
for (i = 0; i < door_count; i++)
{
if ((door[i].c == c) && (map[door[i].x][door[i].y][door[i].z] == 0))
{
map[door[i].x][door[i].y][door[i].z] = DOOR+CLOSE+FULL+c;
map_door[door[i].x][door[i].y][door[i].z] = c;
}
}
}
int Player_On(int x, int y, int p_no)
{
int i;
if ((ply[p_no].x/_block_width == x) && (ply[p_no].y/_block_height == y)) return 1;
if (((ply[p_no].x + (_block_width-1))/_block_width == x) && (ply[p_no].y/_block_height == y)) return 1;
if ((ply[p_no].x/_block_width == x) && ((ply[p_no].y + (_block_height-1))/_block_height == y)) return 1;
if (((ply[p_no].x/_block_width + (_block_width-1)) == x) && ((ply[p_no].y + (_block_height-1))/_block_height == y)) return 1;
for (i = 0; i < mon_count; i++)
{
if ((mon[i].x/_block_width == x) && (mon[i].y/_block_height == y)) return 1;
if (((mon[i].x + (_block_width-1))/_block_width == x) && (mon[i].y/_block_height == y)) return 1;
if ((mon[i].x/_block_width == x) && ((mon[i].y + (_block_height-1))/_block_height == y)) return 1;
if (((mon[i].x/_block_width + (_block_width-1)) == x) && ((mon[i].y + (_block_height-1))/_block_height == y)) return 1;
}
return 0;
}