2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Graphics function DoCollision()
8 #include <graphics/rastport.h>
9 #include <graphics/gels.h>
11 /*****************************************************************************
14 #include <proto/graphics.h>
16 AROS_LH1(void, DoCollision
,
19 AROS_LHA(struct RastPort
*, rp
, A1
),
22 struct GfxBase
*, GfxBase
, 18, Graphics
)
25 Tests each gel in gel list for boundary and gel-to-gel collisions.
26 If a collision happens the collision handling routine is called.
27 The gel list must be sorted by y,x order.
30 rp - pointer to RastPort
47 ******************************************************************************/
51 struct VSprite
* CurVSprite
, * _CurVSprite
;
54 if (NULL
!= rp
->GelsInfo
)
56 CurVSprite
= rp
->GelsInfo
->gelHead
->NextVSprite
;
57 if (CurVSprite
->Flags
& VSPRITE
)
62 while (NULL
!= CurVSprite
->NextVSprite
)
64 _CurVSprite
= CurVSprite
->NextVSprite
;
67 * As long as they can overlap vertically..
69 while (NULL
!= _CurVSprite
&&
70 (CurVSprite
->Y
+ CurVSprite
->Height
- 1) >= _CurVSprite
->Y
)
73 * Do these two overlap horizontally ???
75 if (_CurVSprite
->Flags
& VSPRITE
)
81 ((CurVSprite
->X
>_CurVSprite
->X
+(_CurVSprite
->Width
<<_shift
)-1) ||
82 (CurVSprite
->X
+(CurVSprite
->Width
<<shift
)-1<_CurVSprite
->X
))
86 * Must test the collision masks!!
87 * Phew, this is not going to be easy.
89 int collision
= FALSE
;
90 int dy
= _CurVSprite
->Y
- CurVSprite
->Y
;
91 UWORD
* collmask
= CurVSprite
->CollMask
;
92 UWORD
* _collmask
= _CurVSprite
->CollMask
;
93 unsigned short wordsperline
;
94 unsigned short _wordsperline
;
96 int offset
, _offset
= 0;
100 * I will hold the CurVSprite's collision mask still
101 * and adjust/shift the collision mask of _CurVSprite.
102 * If any and'ing results with non-zero, there is a
105 if (CurVSprite
->Flags
& VSPRITE
)
106 wordsperline
= CurVSprite
->Width
>> 4; // should be 1
108 wordsperline
= CurVSprite
->Width
;
110 if (_CurVSprite
->Flags
& VSPRITE
)
111 _wordsperline
= _CurVSprite
->Width
>> 4; // should be 1
113 _wordsperline
= _CurVSprite
->Width
;
118 * _CurVSprite is lower than CurVSprite
120 i
= wordsperline
* dy
;
121 line
= _CurVSprite
->Y
;
125 _i
= _wordsperline
* dy
;
126 line
= CurVSprite
->Y
;
129 offset
= _CurVSprite
->X
- CurVSprite
->X
;
132 _offset
= (-offset
) >> 4;
133 _scroll
= (-offset
) & 0xf;
139 * _CurVSprite is further to the right than
142 _scroll
= -(offset
& 0xf);
147 * _scroll > 0 means shift the bits to the RIGHT!
149 while ((line
< ( CurVSprite
->Height
+ CurVSprite
->Y
)) &&
150 (line
< (_CurVSprite
->Height
+_CurVSprite
->Y
)) )
152 int curindex
= offset
;
153 int _curindex
= _offset
;
154 while ( curindex
< wordsperline
&&
155 _curindex
< _wordsperline
)
159 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] >> _scroll
) )
165 if (curindex
> wordsperline
)
168 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] << (16-_scroll
)))
178 if (collmask
[curindex
+i
] & _collmask
[_curindex
+_i
])
188 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] << (-_scroll
)))
194 if (_curindex
> _wordsperline
)
197 if (collmask
[curindex
+i
] & (_collmask
[_curindex
+_i
] >> (16+_scroll
)))
212 UWORD mask
= CurVSprite
->MeMask
& _CurVSprite
->HitMask
;
214 while (i
< 16 && 0 != mask
)
218 if (rp
->GelsInfo
->collHandler
&&
219 rp
->GelsInfo
->collHandler
->collPtrs
[i
])
220 rp
->GelsInfo
->collHandler
->collPtrs
[i
]( CurVSprite
,
229 _CurVSprite
= _CurVSprite
->NextVSprite
;
231 CurVSprite
= CurVSprite
->NextVSprite
;