📄 mappy.java
字号:
}
/**
* Returns the total width of the Map, in blocks. <br>
* <br>
* @return the width of the Map.
* @see #getMapHeightBlocks()
**/
public int getMapWidthBlocks() {
return m_intMapWidth;
}
/**
* Returns the total height of the Map, in blocks. <br>
* <br>
* @return the width of the Map.
* @see #getMapWidthBlocks()
**/
public int getMapHeightBlocks() {
return m_intMapHeight;
}
/**
* Returns the total width of the Map, in pixels. <br>
* <br>
* @return the width of the Map.
* @see #getMapHeight()
**/
public int getMapWidth() {
if (m_intBlockStaggerX != 0 || m_intBlockStaggerY != 0) return ((m_intMapWidth-1) * m_intBlockGapX);
return (m_intMapWidth * m_intBlockGapX)-m_intBlockStaggerX;
}
/**
* Returns the total height of the Map, in pixels. <br>
* <br>
* @return the height of the Map.
* @see #getMapWidth()
**/
public int getMapHeight() {
if (m_intBlockStaggerX != 0 || m_intBlockStaggerY != 0) return ((m_intMapHeight-2)/2) * m_intBlockGapY;
else return (m_intMapHeight * m_intBlockGapY);
}
/**
* Returns the width of a Block, in pixels. <br>
* <br>
* @return the width of a Block.
* @see #getBlockHeight()
**/
public int getBlockWidth() {
return m_intBlockWidth;
}
/**
* Returns the height of a Block, in pixels. <br>
* <br>
* @return the height of a Block.
* @see #getBlockWidth()
**/
public int getBlockHeight() {
return m_intBlockHeight;
}
//______________________________________________________________________________
//------------------------------------------------------------------------------
// Public Functions : Screen Attributes
//______________________________________________________________________________
//------------------------------------------------------------------------------
/**
* Sets the screen dimensions. The rectangle denotes the area of the screen
* where the map is drawn. <br>
* <br>
* The default dimensions equivalent to <code>new Rectangle(0, 0, 640, 480)
* </code>. <br>
* <br>
* @param rectangle the new screen dimensions.
* @see #getScreenDimensions()
**/
public void setScreenDimensions(Rectangle rectangle) {
m_intScreenOffsetX = rectangle.x;
m_intScreenOffsetY = rectangle.y;
m_intScreenWidth = rectangle.width;
m_intScreenHeight = rectangle.height;
}
/**
* A helper method that sets the screen dimensions. The parameters denote
* the area of the screen where the map is drawn. <br>
* <br>
* The default dimensions are equivalent to <code>new Rectangle(0, 0, 640, 480)
* </code>. <br>
* <br>
* @param intX the X coordinate of the screen drawing area
* @param intY the Y coordinate of the screen drawing area
* @param intWidth the width of the screen drawing area
* @param intHeight the height of the screen drawing area
* @see #getScreenDimensions()
**/
public void setScreenDimensions(int intX, int intY, int intWidth, int intHeight) {
m_intScreenOffsetX = intX;
m_intScreenOffsetY = intY;
m_intScreenWidth = intWidth;
m_intScreenHeight = intHeight;
}
/**
* Returns the screen dimensions. The rectangle denotes the area of the
* screen where the map is drawn. <br>
* <br>
* The <code>rectangle</code> returned is an independant object, e.g.
* altering the rectangle does not affect the Mappy class. <br>
* <br>
* @return the screen dimensions.
**/
public Rectangle getScreenDimensions() {
Rectangle rectangle;
// build up the rectangle dimensions
rectangle = new Rectangle();
rectangle.x = m_intScreenOffsetX;
rectangle.y = m_intScreenOffsetY;
rectangle.width = m_intScreenWidth;
rectangle.height= m_intScreenHeight;
// return the rectangle
return rectangle;
}
//______________________________________________________________________________
//------------------------------------------------------------------------------
// Public Functions : Map Coordinates
//______________________________________________________________________________
//------------------------------------------------------------------------------
/**
* Sets the current Map layer. This layer is used implicitly in all the map
* specific functions (e.g. <code>drawBackground()</code>), so it is
* important that this is set first. <br>
* <br>
* A valid Map always has layer "0" and may have up to 7 more. If you try
* to set the Map layer to a layer that doesn't exist then the current Map
* layer remains unchanged. <br>
* <br>
* @param intMapLayer the new current Map layer.
* @see #getCurrentMapLayer()
* @see #setX(int)
* @see #addX(int)
* @see #getX()
* @see #setY(int)
* @see #addY(int)
* @see #getY()
* @see #getBlockX()
* @see #getBlockY()
**/
public void setCurrentMapLayer(int intMapLayer) {
if (!validateMapLayer(intMapLayer, "setCurrentMapLayer()")) {
return;
}
m_intCurrentMapLayer = intMapLayer;
}
/**
* Returns the current Map layer. This layer is used implicitly in all the
* map specific functions (e.g. <code>drawBackground()</code>), so it is
* important that this is set first. <br>
* <br>
* A valid Map always has layer "0" and may have up to 7 more. <br>
* <br>
* @return the current Map layer.
* @see #setCurrentMapLayer(int)
* @see #setX(int)
* @see #addX(int)
* @see #getX()
* @see #setY(int)
* @see #addY(int)
* @see #getY()
* @see #getBlockX()
* @see #getBlockY()
**/
public int getCurrentMapLayer() {
return m_intCurrentMapLayer;
}
/**
* Sets the X coordinate of the current Map layer, in pixels. <br>
* <br>
* The new X coordinate is clipped, so that it is always greater than zero
* and less than the Map's pixel width minus the current screenwidth. This
* ensures that whatever the X coordinate is set to, a complete portion of
* the Map can be displayed.
* <br>
* @param intNewX the new X coordinate of the current Map layer in pixels.
* @see #addX(int)
* @see #getX()
**/
public void setX(int intNewX) {
if (intNewX < 0) {
intNewX = 0;
}
if (intNewX > (getMapWidth() - m_intScreenWidth)) {
intNewX = getMapWidth() - m_intScreenWidth;
}
m_intX[m_intCurrentMapLayer] = intNewX;
}
/**
* Increments the X coordinate of the current Map layer by the given amount
* (in pixels). <br>
* <br>
* This helper method effectivly just calls <code>setX()</code> so the same
* clipping rules apply. <br>
* <br>
* @param intIncX what to increment the X coordinate of the current Map
* layer by, in pixels (may be negative).
* @see #setX(int)
* @see #getX()
**/
public void addX(int intIncX) {
setX(m_intX[m_intCurrentMapLayer] + intIncX);
}
/**
* Returns the X coordinate of the current Map layer, in pixels. <br>
* <br>
* I'm thinking of renaming this method to <code>getPixelX()</code>
* to be more in line with <code>getBlockX()</code>.
* <br>
* @return the X coordinate of the current Map layer, in pixels.
* @see #addX(int)
* @see #setX(int)
* @see #getBlockX()
**/
public int getX() {
return m_intX[m_intCurrentMapLayer];
}
/**
* Sets the Y coordinate of the current Map layer, in pixels. <br>
* <br>
* The new Y coordinate is clipped, so that it is always greater than zero
* and less than the Map's pixel height minus the current screenheight. This
* ensures that whatever the Y coordinate is set to, a complete portion of
* the Map can be displayed.
* <br>
* @param intNewY the new Y coordinate of the current Map layer in pixels.
* @see #addY(int)
* @see #getY()
**/
public void setY(int intNewY) {
if (intNewY < 0) {
intNewY = 0;
}
if (intNewY > (getMapHeight() - m_intScreenHeight)) {
intNewY = getMapHeight() - m_intScreenHeight;
}
m_intY[m_intCurrentMapLayer] = intNewY;
}
/**
* Increments the Y coordinate of the current Map layer by the given amount
* (in pixels). <br>
* <br>
* This helper method effectivly just calls <code>setY()</code> so the same
* clipping rules apply. <br>
* <br>
* @param intIncY what to increment the Y coordinate of the current Map
* layer by, in pixels (may be negative).
* @see #setY(int)
* @see #getY()
**/
public void addY(int intIncY) {
setY(m_intY[m_intCurrentMapLayer] + intIncY);
}
/**
* Returns the Y coordinate of the current Map layer, in pixels. <br>
* <br>
* I'm thinking of renaming this method to <code>getPixelY()</code>
* to be more in line with <code>getBlockY()</code>.
* <br>
* @return the Y coordinate of the current Map layer, in pixels.
* @see #addY(int)
* @see #setY(int)
**/
public int getY() {
return m_intY[m_intCurrentMapLayer];
}
/**
* Returns the X coordinate of the current Map layer, in Blocks. <br>
* <br>
* This is effectively <code>getX() / getBlockWidth()</code>.
* <br>
* @return the X coordinate of the current Map layer, in Blocks.
* @see #getX()
* @see #getBlockWidth()
* @see #getBlock(int, int)
**/
public int getBlockX() {
return (m_intX[m_intCurrentMapLayer] / m_intBlockGapX);
}
/**
* Returns the Y coordinate of the current Map layer, in Blocks. <br>
* <br>
* This is effectively <code>getY() / getBlockHeight()</code>.
* <br>
* @return the Y coordinate of the current Map layer, in Blocks.
* @see #getY()
* @see #getBlockHeight()
* @see #getBlock(int, int)
**/
public int getBlockY() {
return (m_intY[m_intCurrentMapLayer] / m_intBlockGapY);
}
//______________________________________________________________________________
//------------------------------------------------------------------------------
// Public Functions : Main
//______________________________________________________________________________
//------------------------------------------------------------------------------
/**
* Animates all the animation block structures. <br>
**/
public void animateBlocks() {
AnimStructure animBlock;
int intIndex;
if (!m_blnMapLoaded) {
log.warn("animateBlocks() - A map hasn't been loaded yet!");
return;
}
if (m_clsMapAniStrPt == null) return;
for (intIndex = 0; intIndex < m_clsMapAniStrPt.length; intIndex++) {
animBlock = m_clsMapAniStrPt[intIndex];
animBlock.ancount--;
if (animBlock.ancount < 0) {
animBlock.ancount = animBlock.andelay;
if (animBlock.antype == animBlock.AN_LOOPF) {
animBlock.ancurframe++;
if (animBlock.ancurframe > animBlock.annumframes)
animBlock.ancurframe = 1;
}
}
}
}
/**
* Draws the Blocks' background of the current Map layer. <br>
* <br>
* @param gfx the <code>Graphics</code> object that the Map is to drawn on.
* @param blnTransparency whether or not the background is to be drawn
* with transparency or not.
* @see #drawForeground(Graphics, int)
* @see #setCurrentMapLayer(int)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -