Gridarta Editor
MultiPositionEntry.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.gameobject;
21 
22 import java.awt.Dimension;
23 import org.jetbrains.annotations.NotNull;
24 
29 public class MultiPositionEntry {
30 
34  private static final int X_DIM = 32;
35 
39  private final int width;
40 
44  private final int height;
45 
49  @NotNull
50  private final int[] data;
51 
55  private final int yLen;
56 
62  public MultiPositionEntry(@NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final Dimension size) {
63  final int sum = size.width + size.height;
64  width = sum * isoMapSquareInfo.getXLen2();
65  height = sum * isoMapSquareInfo.getYLen2();
66  data = new int[width * height];
67  int index = 0;
68  for (int y = 0; y < size.height; y++) {
69  for (int x = 0; x < size.width; x++) {
70  data[index++] = (x + size.height - y - 1) * isoMapSquareInfo.getXLen2();
71  data[index++] = (x + y) * isoMapSquareInfo.getYLen2();
72  }
73  }
74  yLen = isoMapSquareInfo.getYLen();
75  }
76 
84  public int getXOffset(final int positionID) {
85  return data[positionID * 2];
86  }
87 
95  public int getYOffset(final int positionID) {
96  return height - yLen - data[1 + positionID * 2];
97  }
98 
103  public int getWidth() {
104  return width;
105  }
106 
111  public int getHeight() {
112  return height;
113  }
114 
115 }
int getWidth()
Returns the total width of a multi-square image.
MultiPositionEntry(@NotNull final IsoMapSquareInfo isoMapSquareInfo, @NotNull final Dimension size)
Creates a new instance.
static final int X_DIM
Number of columns in the array.
final int yLen
The vertical size of a square.
Encapsulated information about a multi-square image.
int getHeight()
Returns the total height of a multi-square image.
int getXOffset(final int positionID)
Returns the x offset from the left-most pixel of the multi-square image and the default x position...
final int [] data
Array with position data.
Provides information about isometric map squares.
int getYOffset(final int positionID)
Returns the y offset from the left-most pixel of the multi-square image and the default y position...
final int width
The total width of the multi-square image in pixels.
final int height
The total height of the multi-square image in pixels.