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

📄 player.java

📁 JVAV手机游戏单机版 连连看
💻 JAVA
字号:
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
public class Player extends Sprite
{
    public boolean isAlive;
    private boolean isSpeedUp = false;
    private int count=0;
    private static final int LEFT = 2;
    private static final int RIGHT = 5;
    private static final int UP = 1;
    private static final int DOWN = 6;
    private int SPEED =4;
    private int frameWidth, frameHeight;
    private int CanvasWidth, CanvasHeight;
    public Player(Image image, int frameWidth, int frameHeight)
    {
        super(image, frameWidth, frameHeight);
        this.frameWidth = frameWidth;
        this.frameHeight = frameHeight;
        defineReferencePixel(frameWidth / 2, frameHeight / 2);
      //  reset();
    }
    public void draw(Graphics g)
    {
        if (!isAlive)
            return ;
        paint(g);
    }
    public void setCanvasSize(int CanvasWidth, int CanvasHeight)
    {
        this.CanvasWidth = CanvasWidth;
        this.CanvasHeight = CanvasHeight;
    }
    public void setAlive(boolean isAlive)
    {
        this.isAlive = isAlive;
        if(isAlive)setPosition(CanvasWidth/2,CanvasHeight-frameHeight-5);
    }
    public boolean isAlive()
    {
        return isAlive;
    }
    public void move(int direction)
    {
        if (direction == UP)
        {
            move(0,  - SPEED);
            if (getY() < 0)
                setPosition(getX(), 0);

        }
        if (direction == DOWN)
        {
            move(0, SPEED);
            if (getY() > CanvasHeight - frameHeight)
                setPosition(getX(), CanvasHeight - frameHeight);

        }
        if (direction == LEFT)
        {
            move( - SPEED, 0);
            if (getX() < 0)
                setPosition(0, getY());

        }
        if (direction == RIGHT)
        {
            move(SPEED, 0);
            if (getX() > CanvasWidth - frameWidth)
                setPosition(CanvasWidth - frameWidth, getY());

        }

    }
    public void speedup(){
    	SPEED = 6;
    	isSpeedUp = true;
    	count=0;
    }
    public void tick()
    {
        if(isSpeedUp == true){
          count++;
        }
        if(count==15){
          SPEED = 4;
          isSpeedUp = false;
          count=0;
        }
    }
    public void init()
    {
       isSpeedUp = false;
       SPEED =4;
       count=0;
       setAlive(true);
       
    }

}

⌨️ 快捷键说明

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