📄 entity.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: Entity.java
package mobileRPG.client;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
// Referenced classes of package mobileRPG.client:
// ConfigFile, ImageSet, EntityPath, MapCanvas
public class Entity
{
public static int DIR_UP = -1;
public static int DIR_DOWN = -2;
public static int DIR_LEFT = -3;
public static int DIR_RIGHT = -4;
private int xSize;
private int ySize;
private int xPosition;
private int yPosition;
private EntityPath path;
private Image image[];
private int imageIndex;
private int xVelocity;
private int yVelocity;
private int xTarget;
private int yTarget;
private int distanceCount;
private MapCanvas map;
public Entity(int xSize, int ySize, int xPosition, int yPosition, ImageSet imageset, String file, MapCanvas map)
{
this.xSize = xSize;
this.ySize = ySize;
this.map = map;
setXPosition(xPosition);
setYPosition(yPosition);
loadImages(imageset, file);
path = null;
xVelocity = 0;
yVelocity = 0;
xTarget = xPosition;
yTarget = yPosition;
distanceCount = 0;
}
public int getXSize()
{
return xSize;
}
public int getYSize()
{
return ySize;
}
public int getXPosition()
{
return xPosition;
}
public int getYPosition()
{
return yPosition;
}
public void setXPosition(int xPosition)
{
this.xPosition = xPosition;
}
public void setYPosition(int yPosition)
{
this.yPosition = yPosition;
}
public boolean loadImages(ImageSet imageset, String file)
{
ConfigFile cf = new ConfigFile(file);
image = new Image[8];
for(int n = 0; n < image.length; n++)
image[n] = imageset.getImage(cf.readIntLine());
imageIndex = 0;
return true;
}
public void paint(Graphics g)
{
g.drawImage(image[imageIndex], xPosition, yPosition, 20);
}
public void addEntityPath(int x, int y)
{
path = new EntityPath(x, y, path);
}
public synchronized void move(int dirCode)
{
EntityPath e = path;
int xVector = 0;
int yVector = 0;
if(dirCode == DIR_UP)
yVector = -1 * ySize;
else
if(dirCode == DIR_DOWN)
yVector = ySize;
else
if(dirCode == DIR_LEFT)
xVector = -1 * xSize;
else
if(dirCode == DIR_RIGHT)
xVector = xSize;
if(e == null)
addEntityPath(xPosition + xVector, yPosition + yVector);
else
addEntityPath(e.getXTarget() + xVector, e.getYTarget() + yVector);
}
public void run()
{
if(xTarget == xPosition && yTarget == yPosition)
{
xVelocity = 0;
yVelocity = 0;
distanceCount = xSize / 4;
EntityPath e = path;
if(e != null)
e = e.getLast();
if(e != null && !e.isCompleted())
{
e.setCompleted();
xTarget = e.getXTarget();
yTarget = e.getYTarget();
if(yTarget < yPosition)
{
yVelocity = -1;
imageIndex = 2;
} else
if(yTarget > yPosition)
{
yVelocity = 1;
imageIndex = 0;
} else
if(xTarget < xPosition)
{
xVelocity = -1;
imageIndex = 1;
} else
if(xTarget > xPosition)
{
xVelocity = 1;
imageIndex = 3;
}
}
}
int x = xPosition / 16;
int y = yPosition / 16;
map.setNeedsRefresh(x, y);
map.setNeedsRefresh(x + Math.abs(xVelocity), y + Math.abs(yVelocity));
xPosition += xVelocity;
yPosition += yVelocity;
distanceCount += Math.abs(xVelocity) + Math.abs(yVelocity);
if(distanceCount >= xSize / 2)
{
if(imageIndex > 3)
imageIndex -= 4;
else
imageIndex += 4;
distanceCount = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -