20 package net.sf.gridarta.model.gameobject;
22 import java.awt.Point;
23 import javax.swing.Icon;
24 import javax.swing.ImageIcon;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
55 public static final String
Z =
"z";
61 public static final String
LAYER =
"layer";
91 public static final String
ALIGN =
"align";
97 public static final String
ZOOM =
"zoom";
103 public static final String
ALPHA =
"alpha";
109 public static final String
ROTATE =
"rotate";
155 private final Point
point =
new Point();
176 super(archetype, faceObjectProviders, animationObjects);
182 return getAttributeInt(IS_TURNABLE) != 0 || getAttributeInt(IS_ANIMATED) != 0;
189 transDoubleFace = null;
190 stretchedFace = null;
191 super.setObjectFace();
200 if (transFace == null) {
201 transFace = faceObjectProviders.
getTrans(
this);
212 if (doubleFace == null) {
213 doubleFace = faceObjectProviders.
getDouble(
this);
224 if (transDoubleFace == null) {
235 return getAttributeInt(LAYER) > 1 ? getAttributeInt(Z) : 0;
247 if (mapSquare == null) {
251 point.x = mapSquare.
getMapX() + dx;
252 point.y = mapSquare.
getMapY() + dy;
256 if (gameObject.getAttributeInt(LAYER) == 1 && gameObject.getAttributeInt(SUB_LAYER) == getAttributeInt(SUB_LAYER)) {
257 return gameObject.getAttributeInt(Z);
260 }
catch (
final IndexOutOfBoundsException ignored) {
272 stretchFactorIsValid =
false;
273 stretchedFace = null;
283 if (stretchFactorIsValid) {
329 int top = Math.max(wHeight, nwHeight);
330 top = Math.max(top, nHeight);
331 top = Math.max(top, myHeight);
333 int bottom = Math.max(sHeight, seHeight);
334 bottom = Math.max(bottom, eHeight);
335 bottom = Math.max(bottom, myHeight);
337 int right = Math.max(nHeight, neHeight);
338 right = Math.max(right, eHeight);
339 right = Math.max(right, myHeight);
341 int left = Math.max(wHeight, swHeight);
342 left = Math.max(left, sHeight);
343 left = Math.max(left, myHeight);
345 int minHt = Math.min(top, bottom);
346 minHt = Math.min(minHt, left);
347 minHt = Math.min(minHt, right);
348 minHt = Math.min(minHt, myHeight);
350 if (myHeight < 0 && left == 0 && right == 0 && top == 0 && bottom == 0) {
351 int top2 = Math.min(wHeight, nwHeight);
352 top2 = Math.min(top2, nHeight);
353 top2 = Math.min(top2, myHeight);
355 int bottom2 = Math.min(sHeight, seHeight);
356 bottom2 = Math.min(bottom2, eHeight);
357 bottom2 = Math.min(bottom2, myHeight);
359 int right2 = Math.min(nHeight, neHeight);
360 right2 = Math.min(right2, eHeight);
361 right2 = Math.min(right2, myHeight);
363 int left2 = Math.min(wHeight, swHeight);
364 left2 = Math.min(left2, sHeight);
365 left2 = Math.min(left2, myHeight);
368 bottom = bottom2 - bottom;
369 right = right2 - right;
372 minHt = Math.min(top, bottom);
373 minHt = Math.min(minHt, left);
374 minHt = Math.min(minHt, right);
375 minHt = Math.min(minHt, myHeight);
377 minHt = Math.abs(minHt);
379 bottom = Math.abs(bottom);
380 left = Math.abs(left);
381 right = Math.abs(right);
389 top = Math.abs(Math.min(255, top));
390 bottom = Math.abs(Math.min(255, bottom));
391 left = Math.abs(Math.min(255, left));
392 right = Math.abs(Math.min(255, right));
394 stretchFactor = bottom + (left << 8) + (right << 16) + (top << 24);
395 stretchFactorIsValid =
true;
405 if (stretchedFace == null) {
406 stretchedFace = faceObjectProviders.
getStretched(
this, stretchFactor);
417 public abstract boolean isDrawDouble(
boolean drawDoubleFaces);
425 public abstract boolean isStretched(
boolean tileStretching);
429 @SuppressWarnings(
"unchecked")
433 return clone.getThis();
438 return super.isEqual(gameObject);
449 super.facesReloaded();
R archetype
The Archetype of this game object.
static final int MAX_STRETCH
int getMapX()
Returns the x coordinate on the map.
abstract boolean isStretched(boolean tileStretching)
Returns whether to draw this game object with stretching transformation.
static final String SYS_OBJECT
The name of the "sys_object" attribute.
Abstract base class of GameObject implementations.
ImageIcon getTransDouble(@NotNull final GameObject<?, ?, ?> gameObject)
Returns the transparent double face for a GameObject as an ImageIcon.
final int getYOffset()
Acquire Y offset of the object for rendering purposes.
final long getStretchFactor()
Acquire stretch factor of the object.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
long stretchFactor
Calculated stretch factor.
static final String ZOOM
The name of the "zoom" attribute.
static final String LAYER
The name of the "layer" attribute.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
static final String ALPHA
The name of the "alpha" attribute.
DefaultIsoGameObject(@NotNull final R archetype, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new instance.
static final String GLOW_RADIUS
The name of the "glow_radius" attribute.
ImageIcon transDoubleFace
The transparent double face.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Icon getTransparentDoubleImage()
Returns a transparent variant of the face for this GameObject.
Icon getTransparentImage()
Returns a transparent variant of the face for this GameObject.
abstract boolean isDrawDouble(boolean drawDoubleFaces)
Returns whether to draw this game object with double height.
static final String SUB_LAYER
The name of the "sub_layer" attribute.
ImageIcon transFace
The transparent face.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
AnimationObjects is a container for AnimationObjects.
static final String Z
The name of the "z" attribute.
ImageIcon stretchedFace
The stretched floor face.
boolean isEqual(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
ImageIcon getTrans(@NotNull final GameObject<?, ?, ?> gameObject)
Returns the transparent face for a GameObject as an ImageIcon.
Icon getStretchedImage(final long stretchFactor)
Returns a stretched variant of the face for this floor-type GameObject.
static final String ROTATE
The name of the "rotate" attribute.
Provider for faces of GameObjects and Archetypes.
final transient FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
int getYFloorOffset(final int dx, final int dy)
Acquire Y offset at the specified coordinates, relative to the game object's coordinates and its sub-...
The face is the appearance of an object.
boolean stretchFactorIsValid
If true, the stored stretchFactor is valid and can be used in getStretchFactor() instead of calculati...
static final String DRAW_DOUBLE_ALWAYS
The name of the "draw_double_always" attribute.
static final int MAX_STRETCH_DIAGONAL
final Point point
Cached point to avoid unnecessary allocations.
ImageIcon doubleFace
The double face.
Icon getDoubleImage()
Returns a double variant of the face for this GameObject.
Default implementation for GameObject implementing classes.
static final int MAX_SUB_LAYERS
ImageIcon getDouble(@NotNull final GameObject<?, ?, ?> gameObject)
Returns the double face for a GameObject as an ImageIcon.
static final String ALIGN
The name of the "align" attribute.
static final String DRAW_DOUBLE
The name of the "draw_double" attribute.
MapSquare< G, A, R > getMapSquare()
int getMapY()
Returns the y coordinate on the map.
ImageIcon getStretched(@NotNull final GameObject<?, ?, ?> gameObject, final long stretch)
Returns the stretched face for a GameObject as an ImageIcon.
Interface for MapArchObjects.
final void refreshStretchFactor()
Invalidates stretch factor value calculated by getStretchFactor() and clears the stored stretched fac...
static final long serialVersionUID
The serial version UID.