Advertisement
iamcreasy

Untitled

Jul 8th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. package Game;
  2.  
  3. import Core.GameResource;
  4.  
  5. import java.awt.*;
  6.  
  7. public class PhysicsEngine implements GameResource{
  8.     Box b1, b2;
  9.  
  10.     public PhysicsEngine(Box b1, Box b2) {
  11.         this.b1 = b1;
  12.         this.b2 = b2;
  13.     }
  14.  
  15.  
  16.     @Override
  17.     public void update(float tpf, Graphics2D g) {
  18.         g.drawString(checkCollision() ? "Collision Detected" : "No Collision",0, 10);
  19.     }
  20.  
  21.     boolean checkCollision(){
  22.         if(!(b1.locX+b1.width >= b2.locX && b1.locX <= b2.locX+b2.width))
  23.             return false;
  24.  
  25.         if(!(b1.locY+b1.height >= b2.locY && b1.locY < b2.locY+b2.height))
  26.             return false;
  27.  
  28.         return true;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement