• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.replica.replicaisland;
18 
19 import com.replica.replicaisland.CollisionParameters.HitType;
20 
21 /**
22  * CollisionVolume describes a volume (rectangle, sphere, etc) used for dynamic collision detection.
23  * Volumes can be tested for intersection against other volumes, and can be grown to contain a set
24  * of other volumes.  The volume itself is stored in object-relative space (in terms of offsets from
25  * some origin); when used with game objects the position of the parent object must be passed to
26  * a parameter of the intersection test.  This means that a single instance of a CollisionVolume and
27  * its derivatives is safe to share amongst many game object instances.
28  */
29 public abstract class CollisionVolume extends AllocationGuard {
30     // TODO: does this really belong here?
31     // When used as an attack volume, mHitType specifies the type of hit that the volume deals.
32     // When used as a vulnerability volume, it specifies which type the volume is vulernable to
33     // (invalid = all types).
34     public int mHitType;
35 
CollisionVolume()36     public CollisionVolume() {
37         super();
38         mHitType = HitType.INVALID;
39     }
40 
CollisionVolume(int type)41     public CollisionVolume(int type) {
42         super();
43         mHitType = type;
44     }
45 
setHitType(int type)46     public void setHitType(int type) {
47         mHitType = type;
48     }
49 
getHitType()50     public int getHitType() {
51         return mHitType;
52     }
53 
54 
intersects(Vector2 position, FlipInfo flip, CollisionVolume other, Vector2 otherPosition, FlipInfo otherFlip)55     public abstract boolean intersects(Vector2 position, FlipInfo flip, CollisionVolume other,
56             Vector2 otherPosition, FlipInfo otherFlip);
57 
getMinXPosition(FlipInfo flip)58     public float getMinXPosition(FlipInfo flip) {
59         float value = 0;
60         if (flip != null && flip.flipX) {
61             final float maxX = getMaxX();
62             value = flip.parentWidth - maxX;
63         } else {
64             value = getMinX();
65         }
66         return value;
67     }
68 
getMaxXPosition(FlipInfo flip)69     public float getMaxXPosition(FlipInfo flip) {
70         float value = 0;
71         if (flip != null && flip.flipX) {
72             final float minX = getMinX();
73             value = flip.parentWidth - minX;
74         } else {
75             value = getMaxX();
76         }
77         return value;
78     }
79 
getMinYPosition(FlipInfo flip)80     public float getMinYPosition(FlipInfo flip) {
81         float value = 0;
82         if (flip != null && flip.flipY) {
83             final float maxY = getMaxY();
84             value = flip.parentHeight - maxY;
85         } else {
86             value = getMinY();
87         }
88         return value;
89     }
90 
getMaxYPosition(FlipInfo flip)91     public float getMaxYPosition(FlipInfo flip) {
92         float value = 0;
93         if (flip != null && flip.flipY) {
94             final float minY = getMinY();
95             value = flip.parentHeight - minY;
96         } else {
97             value = getMaxY();
98         }
99         return value;
100     }
101 
getMinX()102     protected abstract float getMinX();
getMaxX()103     protected abstract float getMaxX();
getMinY()104     protected abstract float getMinY();
getMaxY()105     protected abstract float getMaxY();
106 
107 
108     public static class FlipInfo {
109         public boolean flipX;
110         public boolean flipY;
111         public float parentWidth;
112         public float parentHeight;
113     }
114 }
115