Advertisement
ulfben

Collision pairs

Feb 27th, 2017
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.ArrayList;
  2. public class Collision {
  3.     private static ArrayList<Collision> POOL = new ArrayList<Collision>();
  4.     public GameObject mA;
  5.     public GameObject mB;        
  6.    
  7.     public static Collision init(GameObject a, GameObject b) {
  8.         if (POOL.isEmpty()) {
  9.             return new Collision(a, b); //added to the pool on release
  10.         }
  11.         Collision c = POOL.remove(0);
  12.         c.mA = a;
  13.         c.mB = b;
  14.         return c;
  15.     }
  16.  
  17.     public static void release(Collision c) {
  18.         c.mA = null;
  19.         c.mB = null;
  20.         POOL.add(c);
  21.     }
  22.    
  23.     public boolean equals(Collision c) {
  24.         return (mA == c.mA && mB == c.mB) || (mA == c.mB && mB == c.mA);
  25.     }
  26.    
  27.     public Collision(GameObject a, GameObject b) {
  28.         mA = a;
  29.         mB = b;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement