ulfben

Collision pairs

Feb 27th, 2017
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×