Advertisement
Guest User

Legend.java

a guest
May 19th, 2011
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public class Legend {
  2.     // The coordinates for the blocks that form a piece are stored in block[][]
  3.     // x,y positions are stored in the 4 keys.
  4.     int block[][] = new int[4][2];
  5.     // The 3 red, green, blue colors for the piece.
  6.     int color[] = new int[3];
  7.  
  8.     public Legend(int x0, int y0, int x1, int y1, int x2, int y2, /**/ int c0, int c1, int c2) {
  9.         color[0] = c0;
  10.         color[1] = c1;
  11.         color[2] = c2;
  12.  
  13.         block[0][0] = 0;
  14.         block[0][1] = 0;
  15.  
  16.         block[1][0] = x0;
  17.         block[1][1] = y0;
  18.  
  19.         block[2][0] = x1;
  20.         block[2][1] = y1;
  21.  
  22.         block[3][0] = x2;
  23.         block[3][1] = y2;
  24.     }
  25.  
  26.     // Fetch data for the main class
  27.     // the block number, x or y pos, amount rotation (in quarters)
  28.     public int fetch(int i, int a, int rotate) {
  29.         // Too complex to explain. It basically swaps the values and negativity depending
  30.         // if it's the x or y position that is requested
  31.         int a_rot = 1;
  32.         int b_rot = 0;
  33.         int neg_a = 1;
  34.         int neg_b = -1;
  35.  
  36.         if (a == 1) {
  37.             a_rot = 0;
  38.             b_rot = 1;
  39.             neg_a = -1;
  40.             neg_b = 1;
  41.         }
  42.         // Return the x or y coordinate that corresponds to the amount of rotation
  43.         switch (rotate) {
  44.             case 1:
  45.                 return neg_a*block[i][a_rot];
  46.             case 2:
  47.                 return neg_a*neg_b*block[i][b_rot];
  48.             case 3:
  49.                 return neg_b*block[i][a_rot];
  50.         }
  51.         return block[i][a];
  52.     }
  53.  
  54.     // Fetch the color. R, G or B.
  55.     public int fetchColor(int i) {
  56.         return color[i];
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement