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..)
12
public class SDLHelper{
13
public static bool RectCollition(ref SDL.Rect rectA, ref SDL.Rect rectB){
15
* Detects if two Rects (rectA and rectB) are overlapping.
17
int rectATop = rectA.y;
18
int rectALeft = rectA.x;
19
int rectABottom = rectA.y + rectA.h;
20
int rectARight = rectA.x + rectA.w;
22
int rectBTop = rectB.y;
23
int rectBLeft = rectB.x;
24
int rectBBottom = rectB.y + rectB.h;
25
int rectBRight = rectB.x + rectB.w;
27
if ( rectABottom >= rectBTop ){
31
if ( rectALeft >= rectBRight ){
35
if ( rectATop <= rectBBottom ){
39
if ( rectARight >= rectBLeft ){
46
public static bool CircCollition(ref SDL.Rect rectA, ref SDL.Rect rectB){
48
* Detects the _circular_ collition of two rects.
50
int rectARadius, rectBRadius;
51
int dX, dY, R, RSqr, SumDelta;
53
rectARadius = ( ( rectA.w / 2 ) + ( rectA.h / 2 ) / 2 );// Get mean
54
rectBRadius = ( ( rectB.w / 2 ) + ( rectB.h / 2 ) / 2 );// Radius..
56
dX = (rectA.x + rectARadius) - (rectB.x + rectBRadius);
57
dY = (rectA.y + rectARadius) - (rectB.y + rectBRadius);
59
R = rectARadius + rectBRadius;
62
SumDelta = (dX * dX) + (dY * dY);
71
public static SDL.Surface LoadeImage (string fileName){