human.java

来自「又是一款j2me 游戏」· Java 代码 · 共 1,780 行 · 第 1/5 页

JAVA
1,780
字号
// 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:   Human.java

package girl60;

import com.nokia.mid.ui.DirectGraphics;
import com.nokia.mid.ui.DirectUtils;
import javax.microedition.lcdui.*;

// Referenced classes of package AfterDark:
//            MovingObject, Rectangle, Room, Map,
//            GameManager

public class Human extends MovingObject
{

    public Human(int objType, int locX, int locY, int width, int height)
    {
        super(objType, locX, locY, width, height);
        MAX_HP = 100;
        DEFAULT_ATT_POWER = 5;
        DEFAULT_DEF_POWER = 4;
        img = null;
        hp = 10;
        actionId = 0;
        drawImgId = 0;
        actionScript = 0;
        actionScriptLength = 0;
        dalayAction = 2;
        bodyOffsetX = 0;
        curPosY = 0;
        actionImgWidth = 0;
        isMoving = true;
        isKeyHold = false;
        invisible = 0;
        attWidth = 34;
        attHeight = 25;
        attArea = null;
        legArea = null;
        attPower = DEFAULT_ATT_POWER;
        defPower = DEFAULT_DEF_POWER;
        damage = 0;
        explosionStage = 0;
        numWeapon = 0;
        weaponId = 0;
        gauge = 0;
        newItem = -1;
        itemStock = null;
        canMoveUp = true;
        canMoveDown = true;
        canMoveLeft = true;
        canMoveRight = true;
        oldDirection = -1;
        msgTimer = 0;
        msg = null;
        super.speedX = 4;
        super.speedY = 4;
        curPosY = super.curLoc.GetY() + super.curLoc.GetHeight();
        int bodyWidth = super.curLoc.GetWidth();
        itemStock = new int[18];
        for(int i = 0; i < itemStock.length; i++)
            itemStock[i] = -1;

        itemStock[0] = 0;
        numWeapon = 1;
        SetWeaponId(0);
    }

    public void Initial(String name, int objType, String imgURL, int maxHP, int actImgWidth)
    {
        try
        {
            img = Image.createImage(imgURL);
        }
        catch(Exception ioe)
        {
            return;
        }
        Initial(name, objType, img, maxHP, actImgWidth);
    }

    public void Initial(String name, int objType, Image playerImg, int maxHP, int actImgWidth)
    {
        this.name = name;
        SetType(objType);
        SetMaxHP(maxHP);
        SetHP(maxHP);
        actionImgWidth = actImgWidth;
        bodyOffsetX = (super.curLoc.GetWidth() - actionImgWidth) / 2;
        super.direction = 1;
        SetAction(0);
        if(GetType() == 20 || GetType() == 22)
        {
            attWidth = 34;
            attHeight = 25;
            attArea = new Rectangle(GetLocationX(), GetLocationY(), attWidth, attHeight);
        } else
        {
            attWidth = 30;
            attHeight = 30;
            attArea = new Rectangle(GetLocationX(), GetLocationY(), attWidth, attHeight);
        }
        legArea = new Rectangle();
        SetLocation(super.curLoc.GetX(), super.curLoc.GetY());
        int bodyWidth = super.curLoc.GetWidth();
        legArea.SetWidth(bodyWidth);
        legArea.SetHeight(bodyWidth);
        try
        {
            img = playerImg;
            if(MovingObject.weaponImg == null)
                MovingObject.weaponImg = Image.createImage("/AfterDark/Images/Player/menu.png");
        }
        catch(Exception ioe)
        {
            return;
        }
    }

    public void Run()
    {
        if(gauge > 0)
            gauge--;
        if(GetHP() <= 0 && GetAction() != 7)
        {
            SetAction(7);
        } else
        {
            if(IsDead())
                return;
            if(invisible > 0)
                invisible--;
        }
        isMoving = false;
        switch(actionId)
        {
        case 0: // '\0'
        default:
            break;

        case 1: // '\001'
            if(--dalayAction <= 0)
                if(++actionScript > actionScriptLength)
                {
                    if(isKeyHold)
                        SetAction(1);
                    else
                        ChangeAction(0);
                } else
                {
                    if(actionScript == 2)
                        drawImgId = 2;
                    else
                        drawImgId = 0;
                    dalayAction = 2;
                }
            super.moveDis = MoveToDirection(super.speedX, true);
            break;

        case 2: // '\002'
            if(--dalayAction <= 0)
                if(++actionScript > actionScriptLength)
                {
                    if(isKeyHold)
                        SetAction(2);
                    else
                        ChangeAction(0);
                } else
                {
                    if(actionScript == 2)
                        drawImgId = 2;
                    else
                        drawImgId = 0;
                    dalayAction = 1;
                }
            super.moveDis = MoveToDirection(super.speedX + 2, true);
            break;

        case 3: // '\003'
            if(--dalayAction > 0)
                break;
            if(++actionScript > actionScriptLength)
            {
                if(isKeyHold)
                    SetAction(3);
                else
                    ChangeAction(0);
            } else
            {
                drawImgId++;
                dalayAction = GetType() != 21 || drawImgId != 5 ? 2 : 4;
            }
            break;

        case 5: // '\005'
            if(--dalayAction > 0)
                break;
            if(++actionScript > actionScriptLength)
                ChangeAction(0);
            else
                dalayAction = 20;
            break;

        case 4: // '\004'
            if(--dalayAction <= 0)
                ChangeAction(0);
            else
                super.moveDis = MoveToDirection(8, true);
            break;

        case 6: // '\006'
            if(--dalayAction <= 0)
            {
                if(++actionScript > actionScriptLength)
                {
                    invisible = 20;
                    ChangeAction(0);
                } else
                {
                    drawImgId = 1;
                    dalayAction = 2;
                }
            } else
            {
                super.moveDis = MoveOppositeDirection(GetType() != 22 ? 2 + dalayAction * 3 : 2 + dalayAction * 4, false);
            }
            break;

        case 7: // '\007'
            if(--dalayAction <= 0)
            {
                if(++actionScript > actionScriptLength)
                {
                    super.destroy = true;
                } else
                {
                    drawImgId = 1;
                    dalayAction = 7;
                }
                break;
            }
            if(actionScript <= 0)
                super.moveDis = MoveOppositeDirection(2 + dalayAction * 3, false);
            break;

        case 8: // '\b'
            if(--dalayAction <= 0)
                if(++actionScript > actionScriptLength)
                    ChangeAction(0);
                else
                if(actionScript < 4)
                {
                    drawImgId++;
                    dalayAction = drawImgId != 5 ? 6 : 25;
                } else
                {
                    drawImgId--;
                    dalayAction = 3;
                }
            if(drawImgId == 5)
                super.moveDis = MoveToDirection(super.speedX * 2, true);
            break;

        case 9: // '\t'
        case 10: // '\n'
            if(--dalayAction > 0)
                break;
            if(++actionScript > actionScriptLength)
            {
                ChangeAction(0);
                newItem = -1;
            } else
            {
                dalayAction = 4;
            }
            break;
        }
    }

    public void Reset()
    {
        super.Reset();
        super.destroy = false;
        isKeyHold = false;
        hp = 10;
        actionId = 0;
        actionScript = 0;
        actionScriptLength = 0;
        drawImgId = 0;
        dalayAction = 0;
        curPosY = 0;
        invisible = 0;
        damage = 0;
        explosionStage = 0;
        gauge = 0;
        canMoveUp = true;
        canMoveDown = true;
        canMoveLeft = true;
        canMoveRight = true;
        oldDirection = -1;
        isMoving = true;
        for(int i = 0; i < itemStock.length; i++)
            itemStock[i] = -1;

        itemStock[0] = 0;
        numWeapon = 1;
        SetWeaponId(0);
    }

    public void SetLocation(int locX, int locY)
    {
        super.curLoc.SetLocation(locX, locY);
        curPosY = (super.curLoc.GetY() + super.curLoc.GetHeight()) - 3;
        legArea.SetLocation(super.curLoc.GetX(), curPosY - super.curLoc.GetWidth() / 2 - 6);
    }

    public boolean IsMoving()
    {
        return isMoving;
    }

    public boolean IsInvisible()
    {
        return invisible > 0;
    }

    public boolean IsDead()
    {
        return IsDestroy();
    }

    public boolean IsAttack()
    {
        if(GetType() == 20)
        {
            if(actionId == 3 && drawImgId == 4)
                return true;
        } else
        if(GetType() == 21)
        {
            if(actionId == 3 && drawImgId == 5)
                return true;
        } else
        if(actionId == 3 && drawImgId == 4)
            return true;
        return false;
    }

    public Rectangle GetAttackArea()
    {
        return attArea;
    }

    public Rectangle GetLegArea()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?