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

📄 playersprite.java

📁 一个经典的手机游戏原代码
💻 JAVA
字号:
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class playerSprite extends Sprite {
  public static final int MOVE = 3;
  private int frameWidth, frameHeight;
  private int scnWidth, scnHeight;
  public int liveNum;
  public int jumpNum;
  public boolean isDead;
  public boolean isVisible;
  public boolean isDown;
  public int iUpNum;
  public int iStick;
  public boolean isMove;

  public playerSprite(Image img,
                      int frameWidth, int frameHeight,
                      int scnWidth, int scnHeight) throws Exception{
    super(img, frameWidth, frameHeight);
    this.scnWidth = scnWidth;
    this.scnHeight = scnHeight;
    this.frameWidth = frameWidth;
    this.frameHeight = frameHeight;
    init();
  }

  public void init() {
    setFrame(12);
    liveNum = 12;
    jumpNum = 0;
    isVisible = true;
    setVisible(true);
    isDown = false;
    iUpNum = 0;
    iStick = 0;
    isMove = false;
  }

  public void moveLeft(int iMove) {
    if (getX() - iMove - 3 > 0)
      move(iMove * -1, 0);
  }

  public void moveLeft() {
    moveLeft(MOVE);
    isMove = true;
    switch (getFrame()) {
      case 0:
        nextFrame();
        break;
      case 1:
        nextFrame();
        break;
      case 2:
        setFrame(0);
        break;
      default:
        setFrame(1);
        break;
    }
  }

  public void moveRight(int iMove) {
    if (getX() + iMove + getWidth() + 3 < scnWidth)
      move(iMove, 0);
  }

  public void moveRight() {
    moveRight(MOVE);
    isMove = true;
    switch (getFrame()) {
      case 6:
        nextFrame();
        break;
      case 7:
        nextFrame();
        break;
      case 8:
        setFrame(6);
        break;
      default:
        setFrame(7);
        break;
    }
  }

  public boolean moveUp(int iMove) {
    if (getY() - iMove - 1> 0) {
      move(0, iMove * -1);
      return true;
    }
    return false;
  }

  public boolean moveUp() {
    return moveUp(MOVE);
  }

  public void moveDown(int iMove) {
//    if (getY() + iMove + getHeight() < scnHeight) {
      move(0, iMove);
      switch (getFrame()) {
        case 12:
          nextFrame();
          break;
        case 13:
          setFrame(12);
          break;
        default:
          setFrame(13);
          break;
      }
//    }
  }

  public void moveDown() {
    moveDown(MOVE+1);
  }

  public void setLive(int live) {
    liveNum = live;
  }

  public int getLive() {
    return liveNum;
  }

  public void decreaseLive() {
    if (liveNum > 0)
      liveNum--;
  }

  public void addLive() {
    if (liveNum < 12)
      liveNum++;
  }

  public void setDead() {
    liveNum = 0;
  }

  public void setAlive() {
    liveNum = 12;
  }

  public boolean isAlive() {
    if (liveNum > 0)
      return true;
    else
      return false;
  }
}

⌨️ 快捷键说明

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