/+junk/invaders_vala

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/invaders_vala
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
/* Author: Gustav Hartvigsson
 * e-mail: gustav.hartvigsson <at> gmail.com
 * -----------------------------------------
 * This is a helper library for game development in SDL, using only SDL
 * standard types. (At the moment..)
 */

using SDL;

namespace GameHelper{
  
  public class SDLHelper{
    public static bool RectCollition(ref SDL.Rect rectA, ref SDL.Rect rectB){
      /**RectCollition
       * Detects if two Rects (rectA and rectB) are overlapping.
       */
      int rectATop = rectA.y;
      int rectALeft = rectA.x;
      int rectABottom = rectA.y + rectA.h;
      int rectARight = rectA.x + rectA.w;
      
      int rectBTop = rectB.y;
      int rectBLeft = rectB.x;
      int rectBBottom = rectB.y + rectB.h;
      int rectBRight = rectB.x + rectB.w;
      
      if ( rectABottom >= rectBTop ){
        return true;
      }
      
      if ( rectALeft >= rectBRight ){
        return true;
      }
      
      if ( rectATop <= rectBBottom ){
        return true;
      }
      
      if ( rectARight >= rectBLeft ){
        return true;
      }
      
      return false;
    }
    
    public static bool CircCollition(ref SDL.Rect rectA, ref SDL.Rect rectB){
      /**CircCollition
       * Detects the _circular_ collition of two rects.
       */
      int rectARadius, rectBRadius;
      int dX, dY, R, RSqr, SumDelta;
      
      rectARadius = ( ( rectA.w / 2 ) + ( rectA.h / 2 ) / 2 );// Get mean 
      rectBRadius = ( ( rectB.w / 2 ) + ( rectB.h / 2 ) / 2 );// Radius..
      
      dX = (rectA.x + rectARadius) - (rectB.x + rectBRadius);
      dY = (rectA.y + rectARadius) - (rectB.y + rectBRadius);
      
      R = rectARadius + rectBRadius;
      RSqr = R * R;
      
      SumDelta = (dX * dX) + (dY * dY);
      
      if(RSqr > SumDelta){
        return true;
      } else {
        return false;
      }
    }
    /*
    public static SDL.Surface LoadeImage (string fileName){
      
    }
    */
  }
}