bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/invaders_vala
|
8
by Gusatv Hartvigsson
* Started to work on a helper library (Under LGPL) |
1 |
/* Author: Gustav Hartvigsson
|
2 |
* e-mail: gustav.hartvigsson <at> gmail.com
|
|
3 |
* -----------------------------------------
|
|
4 |
* This is a helper library for game development in SDL, using only SDL
|
|
5 |
* standard types. (At the moment..)
|
|
6 |
*/
|
|
7 |
||
8 |
using SDL; |
|
9 |
||
10 |
namespace GameHelper{ |
|
11 |
|
|
12 |
public class SDLHelper{ |
|
13 |
public static bool RectCollition(ref SDL.Rect rectA, ref SDL.Rect rectB){ |
|
14 |
/**RectCollition |
|
15 |
* Detects if two Rects (rectA and rectB) are overlapping.
|
|
16 |
*/
|
|
17 |
int rectATop = rectA.y; |
|
18 |
int rectALeft = rectA.x; |
|
19 |
int rectABottom = rectA.y + rectA.h; |
|
20 |
int rectARight = rectA.x + rectA.w; |
|
21 |
|
|
22 |
int rectBTop = rectB.y; |
|
23 |
int rectBLeft = rectB.x; |
|
24 |
int rectBBottom = rectB.y + rectB.h; |
|
25 |
int rectBRight = rectB.x + rectB.w; |
|
26 |
|
|
27 |
if ( rectABottom >= rectBTop ){ |
|
28 |
return true; |
|
29 |
} |
|
30 |
|
|
31 |
if ( rectALeft >= rectBRight ){ |
|
32 |
return true; |
|
33 |
} |
|
34 |
|
|
35 |
if ( rectATop <= rectBBottom ){ |
|
36 |
return true; |
|
37 |
} |
|
38 |
|
|
39 |
if ( rectARight >= rectBLeft ){ |
|
40 |
return true; |
|
41 |
} |
|
42 |
|
|
43 |
return false; |
|
44 |
} |
|
45 |
|
|
46 |
public static bool CircCollition(ref SDL.Rect rectA, ref SDL.Rect rectB){ |
|
47 |
/**CircCollition |
|
48 |
* Detects the _circular_ collition of two rects.
|
|
49 |
*/
|
|
50 |
int rectARadius, rectBRadius; |
|
51 |
int dX, dY, R, RSqr, SumDelta; |
|
52 |
|
|
53 |
rectARadius = ( ( rectA.w / 2 ) + ( rectA.h / 2 ) / 2 );// Get mean |
|
54 |
rectBRadius = ( ( rectB.w / 2 ) + ( rectB.h / 2 ) / 2 );// Radius.. |
|
55 |
|
|
56 |
dX = (rectA.x + rectARadius) - (rectB.x + rectBRadius); |
|
57 |
dY = (rectA.y + rectARadius) - (rectB.y + rectBRadius); |
|
58 |
|
|
59 |
R = rectARadius + rectBRadius; |
|
60 |
RSqr = R * R; |
|
61 |
|
|
62 |
SumDelta = (dX * dX) + (dY * dY); |
|
63 |
|
|
64 |
if(RSqr > SumDelta){ |
|
65 |
return true; |
|
66 |
} else { |
|
67 |
return false; |
|
68 |
} |
|
69 |
} |
|
70 |
/* |
|
71 |
public static SDL.Surface LoadeImage (string fileName){
|
|
72 |
|
|
73 |
}
|
|
74 |
*/
|
|
75 |
} |
|
76 |
}
|