1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef G1_MAP_COLLISION_HH
|
---|
10 | #define G1_MAP_COLLISION_HH
|
---|
11 |
|
---|
12 | // make this work in the editor, too
|
---|
13 | class g1_collision_map_class
|
---|
14 | {
|
---|
15 | protected:
|
---|
16 | w8 *map;
|
---|
17 | w16 wx,wy;
|
---|
18 | w16 bwx;
|
---|
19 | public:
|
---|
20 | w16 width() const { return wx; }
|
---|
21 | w16 height() const { return wy; }
|
---|
22 |
|
---|
23 | g1_collision_map_class() : map(0) {}
|
---|
24 | g1_collision_map_class(w16 _wx, w16 _wy) { init(_wy,_wy); }
|
---|
25 |
|
---|
26 | void init(w16 _wx, w16 _wy)
|
---|
27 | {
|
---|
28 | uninit();
|
---|
29 | wx = _wx; wy = _wy;
|
---|
30 | bwx = (wx+7)/8;
|
---|
31 | map = (w8 *)i4_malloc(bwx*wy, "collision_map");
|
---|
32 | I4_ASSERT(map, "No block map allocated");
|
---|
33 | }
|
---|
34 |
|
---|
35 | void uninit()
|
---|
36 | {
|
---|
37 | if (map)
|
---|
38 | i4_free(map);
|
---|
39 | map=0;
|
---|
40 | }
|
---|
41 |
|
---|
42 | ~g1_collision_map_class()
|
---|
43 | {
|
---|
44 | uninit();
|
---|
45 | }
|
---|
46 |
|
---|
47 | void clear()
|
---|
48 | {
|
---|
49 | memset(map, 0, bwx*wy);
|
---|
50 | }
|
---|
51 |
|
---|
52 | i4_bool is_blocked(w16 x, w16 y) const
|
---|
53 | {
|
---|
54 | w8 mask = 1<<(x&7);
|
---|
55 | x /= 8;
|
---|
56 | return (map[y*bwx+x] & mask)!=0;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void set_blocking(w16 x, w16 y, i4_bool flag)
|
---|
60 | {
|
---|
61 | w8 mask = 1<<(x&7), bit = flag<<(x&7);
|
---|
62 | x /= 8;
|
---|
63 | map[y*bwx+x] = (map[y*bwx+x]&~mask)|bit;
|
---|
64 | }
|
---|
65 | };
|
---|
66 |
|
---|
67 | #endif
|
---|