📄 movingobject.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2005-4-9 12:51:46
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: MovingObject.java
package girl60;
import com.nokia.mid.ui.DirectGraphics;
import com.nokia.mid.ui.DirectUtils;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
// Referenced classes of package AfterDark:
// Rectangle, GameConstant, Room
public class MovingObject
implements GameConstant
{
public MovingObject(int objType, int locX, int locY, int width, int height)
{
DEFAULT_HIT_POWER = 1;
hitPower = DEFAULT_HIT_POWER;
speedX = 3;
speedY = 3;
stage = 0;
direction = 1;
moveDis = 0;
destroy = false;
canAttack = false;
type = 0;
curLoc = new Rectangle();
type = objType;
curLoc.SetBounds(locX, locY, width, height);
destroy = false;
hitPower = DEFAULT_HIT_POWER;
speedX = 3;
speedY = 3;
stage = 0;
try
{
if(weaponImg == null)
weaponImg = Image.createImage("/AfterDark/Images/Player/weapon.png");
}
catch(Exception ioe)
{
return;
}
}
public void Initial(int objType, int hitPow, int speedX, int speedY, int locX, int locY, int width,
int height)
{
type = objType;
curLoc.SetBounds(locX, locY, width, height);
DEFAULT_HIT_POWER = hitPow;
hitPower = hitPow;
this.speedX = speedX;
this.speedY = speedY;
stage = 0;
destroy = false;
canAttack = false;
if(Math.abs(speedX) > Math.abs(speedY))
direction = speedX <= 0 ? 2 : 3;
else
direction = speedY <= 0 ? 0 : 1;
moveDis = Math.abs(speedX + speedY);
}
public void Run()
{
if(!IsDestroy())
{
int absDis = Math.abs(speedX + speedY);
if(moveDis < absDis)
SetDestroy(true);
else
moveDis = MoveToDirection(absDis);
}
}
public void Reset()
{
curLoc.SetLocation(0, 0);
destroy = false;
hitPower = DEFAULT_HIT_POWER;
speedX = 3;
speedY = 3;
stage = 0;
moveDis = 0;
direction = 1;
destroy = false;
canAttack = false;
}
public int GetType()
{
return type;
}
public void SetType(int objType)
{
type = objType;
}
public void SetLocation(int x, int y)
{
curLoc.SetX(x);
curLoc.SetY(y);
}
public int GetLocationX()
{
return curLoc.GetX();
}
public int GetLocationY()
{
return curLoc.GetY();
}
public void SetWidth(int width)
{
curLoc.SetWidth(width);
}
public int GetWidth()
{
return curLoc.GetWidth();
}
public void SetHeight(int height)
{
curLoc.SetHeight(height);
}
public int GetHeight()
{
return curLoc.GetHeight();
}
public Rectangle GetBounds()
{
return curLoc;
}
public int GetCenterLocationX()
{
return GetLocationX() + GetWidth() / 2;
}
public int GetCenterLocationY()
{
return GetLocationY() + GetHeight() / 2;
}
public void SetDirection(int newDir)
{
direction = newDir;
}
public int GetDirection()
{
return direction;
}
public void SetDestroy(boolean isDestroy)
{
destroy = isDestroy;
}
public boolean CanAttack()
{
return canAttack;
}
public boolean IsDestroy()
{
return destroy;
}
public int GetHitPower()
{
return hitPower;
}
public void SetHitPower(int newPower)
{
hitPower = newPower;
}
public int GetSpeedX()
{
return speedX;
}
public void SetSpeedX(int speed)
{
speedX = speed;
}
public int GetSpeedY()
{
return speedY;
}
public void SetSpeedY(int speed)
{
speedY = speed;
}
public void MoveX(int moveoffset)
{
curLoc.MoveX(moveoffset);
}
public void MoveY(int moveoffset)
{
curLoc.MoveY(moveoffset);
}
public void Move(int moveoffsetX, int moveoffsetY)
{
curLoc.MoveX(moveoffsetX);
curLoc.MoveY(moveoffsetY);
}
public int MoveToDirection(int dis)
{
int canMoveDis = 0;
switch(direction)
{
case 0: // '\0'
canMoveDis = CheckCollision(dis, 0);
MoveY(-canMoveDis);
return canMoveDis;
case 1: // '\001'
canMoveDis = CheckCollision(dis, 1);
MoveY(canMoveDis);
return canMoveDis;
case 2: // '\002'
canMoveDis = CheckCollision(dis, 2);
MoveX(-canMoveDis);
return canMoveDis;
case 3: // '\003'
canMoveDis = CheckCollision(dis, 3);
MoveX(canMoveDis);
return canMoveDis;
}
return -1;
}
public int CheckCollision(int moveOffset, int direct)
{
int widthOffset = curLoc.GetWidth() / 2;
int curPosX = GetCenterLocationX();
int curPosY = GetCenterLocationY();
try
{
switch(direct)
{
default:
break;
case 0: // '\0'
{
int minX = curPosX - widthOffset;
int maxX = curPosX + widthOffset;
int leftPosX = minX / 30;
int rightPosX = maxX / 30;
int posY1 = curPosY / 30;
int leftRoomData = Room.GetObjectId(leftPosX, posY1);
int rightRoomData = Room.GetObjectId(rightPosX, posY1);
int objPosY = (posY1 + 1) * 30;
int leftDisY = objPosY - Room.GetObstructionDistance(leftRoomData, direct);
int rightDisY = objPosY - Room.GetObstructionDistance(rightRoomData, direct);
int moveTo = curPosY - moveOffset;
if(moveTo <= rightDisY && curPosY >= rightDisY && rightRoomData != -1)
{
int objPosX = Room.GetObstructionDistance(rightRoomData, 3);
int lWidth = 30 - Room.GetObstructionDistance(rightRoomData, 2);
int rWidth = objPosX;
int width = lWidth - rWidth;
if(width > 0)
{
objPosX += rightPosX * 30;
int leftBound = objPosX;
int rightBound = objPosX + width;
if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
return curPosY - rightDisY;
}
}
if(moveTo <= leftDisY && curPosY >= leftDisY && leftPosX != rightPosX && leftRoomData != -1)
{
int objPosX = Room.GetObstructionDistance(leftRoomData, 3);
int lWidth = Room.GetObstructionDistance(leftRoomData, 2);
int rWidth = 30 - objPosX;
int width = rWidth - lWidth;
if(width > 0)
{
objPosX += leftPosX * 30;
int leftBound = objPosX;
int rightBound = objPosX + width;
if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
return curPosY - leftDisY;
}
}
int posY2 = moveTo / 30;
if(posY1 != posY2)
while(--posY1 >= posY2)
{
leftRoomData = Room.GetObjectId(leftPosX, posY1);
rightRoomData = Room.GetObjectId(rightPosX, posY1);
leftDisY = (objPosY -= 30) - Room.GetObstructionDistance(leftRoomData, direct);
rightDisY = objPosY - Room.GetObstructionDistance(rightRoomData, direct);
if(rightRoomData != -1)
{
int objPosX = Room.GetObstructionDistance(rightRoomData, 3);
int lWidth = 30 - Room.GetObstructionDistance(rightRoomData, 2);
int rWidth = objPosX;
int width = lWidth - rWidth;
if(width > 0)
{
objPosX += rightPosX * 30;
int leftBound = objPosX;
int rightBound = objPosX + width;
if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
return curPosY < rightDisY || moveTo > rightDisY ? moveOffset : curPosY - rightDisY;
}
}
if(leftPosX != rightPosX && leftRoomData != -1)
{
int objPosX = Room.GetObstructionDistance(leftRoomData, 3);
int lWidth = Room.GetObstructionDistance(leftRoomData, 2);
int rWidth = 30 - objPosX;
int width = rWidth - lWidth;
if(width > 0)
{
objPosX += leftPosX * 30;
int leftBound = objPosX;
int rightBound = objPosX + width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -