⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worm.java

📁 thq 发布的《worms》 motorola 源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.util.Random;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

public class Worm
{

    private int ammunitionCurrent[] = {
        0, 0, 0, 0, 0
    };
    private final int ammunitionInitial[] = {
        0, 2, 4, 2, 1
    };
    protected final int STATE_IDLE_LEFT = 0;
    protected final int STATE_IDLE_RIGHT = 1;
    protected final int STATE_WALK_LEFT = 2;
    protected final int STATE_WALK_RIGHT = 3;
    protected final int STATE_AIM_UP = 4;
    protected final int STATE_AIM_DOWN = 5;
    protected final int STATE_FIRE_VELOCITY = 6;
    protected final int STATE_FIRE = 7;
    public final int STATE_DEAD = 8;
    protected final int STATE_DIRECTION_LEFT = 0;
    protected final int STATE_DIRECTION_RIGHT = 1;
    private final int MAX_VELOCITY = 100;
    protected int direction;
    protected boolean pointerVisible;
    public int positionX;
    public int positionY;
    public static Imp walk;
    public static Imp medic;
    public static Imp bazooka;
    public static Imp arrow;
    public static Imp crosshair;
    public static Imp rip;
    protected int state;
    public int health;
    public int healthCountDown;
    public long healthCountDownLastTime;
    protected Game game;
    protected boolean adjustCrosshair;
    private int pointerDir;
    private int pointerPos;
    public static long turnStartTime;
    protected boolean turnKeyPressed;
    protected boolean pointerActive;
    private boolean active;
    protected int angle;
    protected Landscape landscape;
    protected long fireVelocityTime;
    protected int activeWeapon;
    protected boolean falling;
    private boolean landed;
    private boolean fireMode;
    public boolean redTeam;
    protected Random random;
    protected boolean wormObstructed;
    protected int myTeamNo;
    protected long healthCountStartTime;
    private boolean computer;
    private int tag_cx;
    private int tag_cy;
    private int tag_cw;
    private int tag_ch;

    public Worm(boolean flag, int i, boolean flag1)
    {
        pointerVisible = true;
        angle = 90;
        wormObstructed = false;
        computer = flag1;
        myTeamNo = i;
        random = new Random();
        redTeam = flag;
        Worm _tmp = this;
        arrow = arrow;
        Worm _tmp1 = this;
        crosshair = crosshair;
        Worm _tmp2 = this;
        medic = medic;
        Worm _tmp3 = this;
        walk = walk;
        Worm _tmp4 = this;
        bazooka = bazooka;
        Worm _tmp5 = this;
        rip = rip;
        if(!flag)
            crosshair.setFrame(1);
        else
            crosshair.setFrame(0);
    }

    public void reset(Game game1, Landscape landscape1, int i)
    {
    	
        game = game1;
        landscape = landscape1;
        healthCountDown = -1;
        health = 100;
        falling = false;
        activeWeapon = 0;
        active = false;
        pointerActive = false;
        turnStartTime = -1L;
        
        direction = 0;
        state = 0;
        angle = 140;
        if(i < 150)
        {
        	System.out.println("=====worm===reset===1===");
            direction = 1;
            state = 1;
            angle = 40;
        } else {
        	System.out.println("=====worm===reset===2===");
        }
        positionX = i;
        positionY = 150 - landscape1.get_currentHeight(positionX, 1) - 11;
        for(byte byte0 = 0; byte0 < 5; byte0++)
            ammunitionCurrent[byte0] = ammunitionInitial[byte0];

    }

    public void activate()
    {
        healthCountDownLastTime = -1L;
        turnStartTime = Worms.getTime();
//System.out.println("=======worm====activate===turnStartTime=="+turnStartTime);
        game.LastGetTime = turnStartTime;
        active = true;
        turnKeyPressed = false;
        pointerActive = true;
        fireMode = false;
        fireVelocityTime = -1L;
        landscape.center(positionX, positionY);
    }

    public void setIdle()
    {
        if(state == 8)
            return;
        if(direction == 0)
            state = 0;
        else
            state = 1;
    }

    public int getActiveWeapon()
    {
        return activeWeapon;
    }

    public int getHealth()
    {
        return health;
    }

    public void setActiveWeapon(int i)
    {
        activeWeapon = i;
    }

    protected void endTurn()
    {
        active = false;
        pointerActive = false;
        turnStartTime = -1L;
    }

    protected int calcVelocity()
    {
        long l = Worms.getTime() - fireVelocityTime;
        l /= 10L;
        if(l > 100L)
            l = 100L;
        return (int)l;
    }

    protected void fire()
    {
    	System.out.println("===fire==183===");
        state = 7;
        fireMode = true;
        Game _tmp = game;
        Weapon.fire(game, landscape, this, activeWeapon, positionX, positionY, Game.windFactor, calcVelocity() / 2, angle, true);
    }

    public void keyReleased(int i)
    {
        if(!active)
            return;
        if(falling)
            return;
        if(healthCountDown > 0)
            return;
        if(Worms.checkKey(i, Worms.KEY_ENTER) && activeWeapon == 4)
        {
        	//System.out.println("==worm====keyReleased==200==");
            if(ammunitionCurrent[activeWeapon] > 0)
            {
            	//System.out.println("==worm====keyReleased==203==");
                fire();
                ammunitionCurrent[activeWeapon]--;
            }
            //System.out.println("=worm====199==direction==="+direction);
            if(direction == 0)
                state = 0;
            else
                state = 1;
        }
        if(state == 6 && Worms.checkKey(i, Worms.KEY_ENTER))
        {
            fire();
            if(direction == 0)
                state = 0;
            else
                state = 1;
        }
        if(Worms.checkKey(i, Worms.KEY_LEFT))
            setIdle();
        if(Worms.checkKey(i, Worms.KEY_RIGHT))
            setIdle();
        if(Worms.checkKey(i, Worms.KEY_UP))
            adjustCrosshair = false;
        if(Worms.checkKey(i, Worms.KEY_DOWN))
            adjustCrosshair = false;
    }

    public void keyPressed(int i)
    {
        if(!active)
            return;
        if(falling)
            return;
        if(healthCountDown > 0)
            return;
        if(state == 6)
            return;
        turnKeyPressed = true;
        pointerActive = false;
        if(Worms.checkKey(i, Worms.KEY_LEFT_SOFTKEY) && !Weapon.isDynamiteActive()) {
        	System.out.println("===worm===Worms.KEY_LEFT_SOFTKEY==");
            if(getActiveWeapon() < 4)
                setActiveWeapon(getActiveWeapon() + 1);
            else
                setActiveWeapon(0);
        }
        if(!fireMode)
        {
            if(Worms.checkKey(i, Worms.KEY_DOWN))
            {
                if(direction == 0)
                    state = 4;
                else
                    state = 5;
                adjustCrosshair = true;
            }
            if(Worms.checkKey(i, Worms.KEY_UP))
            {
                if(direction == 1)
                    state = 4;
                else
                    state = 5;
                adjustCrosshair = true;
            }
        }
        if(Worms.checkKey(i, Worms.KEY_LEFT))
        {
            state = 2;
            if(direction == 1)
                angle = 120;
            direction = 0;
        }
        if(Worms.checkKey(i, Worms.KEY_RIGHT))
        {
            state = 3;
            if(direction == 0)
                angle = 60;
            direction = 1;
        }
        if(Worms.checkKey(i, Worms.KEY_ENTER) && !fireMode && (state == 4 || state == 5) && (ammunitionCurrent[activeWeapon] > 0 || activeWeapon == 0) && activeWeapon != 4)
        {
        	//System.out.println("==worm====keyPressed==281==");
            state = 6;
            fireVelocityTime = Worms.getTime();
            if(activeWeapon > 0)
                ammunitionCurrent[activeWeapon]--;
        }
    }

    public boolean areaBlocked(int i)
    {
        return landscape.earthCollision(positionX + i, positionY, false, null);
    }

    public boolean runFrame()
    {
        random.nextInt();
        if(state == 8)
            return false;
        falling = false;
        if(!landscape.earthCollision(positionX, positionY + 12, false, null))
        {
            positionY += 3;
            landscape.center(positionX, positionY);
            landed = false;
            falling = true;
            if(positionY > 150)
            {
                state = 8;
                healthCountDown = 0;
                health = 0;
                if(Menu.soundEnabled()) {
                	//Game.sound.close();
                	Game.sound.getPlayer(3);
                	Game.sound.start();
//                	try
//                    {
//                        Thread.sleep(500L);
//                    }
//                    catch(Exception exception) { }
                	//Game.sound.close();
                	//Game.sound.getPlayer(2);
                    /*try
                    {
                        Game.sound_BYEBYE.start();
                    }
                    catch(MediaException mediaexception) { }*/
                }
                	
               /* if(Menu.vibratorEnabled())
                {
//                    DeviceControl.getDefaultDeviceControl().setDeviceActive(4, true);//yue add 1
                    try
                    {
                        Thread.sleep(500L);

⌨️ 快捷键说明

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