Advertisement
heroofhyla

XYCoords

Apr 15th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package com.aezart.darkmaze;
  2.  
  3. public final class XYCoords {
  4.     private final int x;
  5.     private final int y;
  6.    
  7.     public XYCoords(int x, int y){
  8.         this.x = x;
  9.         this.y = y;
  10.     }
  11.    
  12.     public XYCoords(int xTile, int yTile, int xOffset, int yOffset){
  13.         this.x = xTile*32 + xOffset;
  14.         this.y = yTile*32 + yOffset;
  15.     }
  16.    
  17.    
  18.     public final int x(){
  19.         return x;
  20.     }
  21.    
  22.     public final int y(){
  23.         return y;
  24.     }
  25.    
  26.     public final XYCoords plus(int x, int y){
  27.         return new XYCoords(this.x+x, this.y+y);
  28.     }
  29.     public final int xTile(){
  30.         return x/32;
  31.     }
  32.    
  33.     public final int yTile(){
  34.         return y/32;
  35.     }
  36.    
  37.     public final boolean equalsTile(XYCoords xy){
  38.         if (xy == null){
  39.             return false;
  40.         }
  41.  
  42.         return this.xTile() == xy.xTile() && this.yTile() == xy.yTile();
  43.     }
  44.    
  45.     @Override
  46.     public final boolean equals(Object xy){
  47.         if (xy == null){
  48.             return false;
  49.         }
  50.         if (! (xy instanceof XYCoords)){
  51.             return false;
  52.         }
  53.         return this.x() == ((XYCoords)xy).x() && this.y() == ((XYCoords)xy).y();
  54.     }
  55.    
  56.     @Override
  57.     public final int hashCode(){
  58.         return ((x * y) + 29)*37;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement