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

📄 bonus.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
字号:
package com.j2medev.chapter5;
import javax.microedition.lcdui.*;

public class Bonus implements MyGameInterface {

  private byte bonusType = BONUS_SHOE;
  private Image imgBonus;
  private int bonusX = 0, bonusY = 0;
  private int tmpBonusX = 0;
  private byte isCatched = 0;


  /**
   * 构造函数
   */
  public Bonus(Image imgBonus, byte bonusType, int bonusX, int bonusY) {
    this.imgBonus = imgBonus;
    this.bonusType = bonusType;
    this.tmpBonusX = bonusX * 16;
    this.bonusX = this.tmpBonusX;
    this.bonusY = bonusY * 16;
  }


  /**
   * 得到X值
   * @return int
   */
  public int getBonusX() {
    return bonusX;
  }

  public int getTmpBonusX() {
    return tmpBonusX;
  }


  /**
   * 设置X值
   * @param bonusX int
   */
  public void setBonusX(int bonusX) {
    this.bonusX = bonusX;
  }

  public void setTmpBonusX(int tmpBonusX) {
    this.tmpBonusX = tmpBonusX;
  }


  /**
   * 得到Y值
   * @return int
   */
  public int getBonusY() {
    return bonusY;
  }


  /**
   * 设置Y值
   * @param bonusY int
   */
  public void setBonusY(int bonusY) {
    this.bonusY = bonusY;
  }


  /**
   * 得到宽度
   * @return int
   */
  public int getBonusWidth() {
    return imgBonus.getWidth();
  }


  /**
   * 得到高度
   * @return int
   */
  public int getBonusHeight() {
    return imgBonus.getHeight();
  }


  /**
   * 得到奖品的类型
   * @return int
   */
  public byte getBonusType() {
    return bonusType;
  }


  /**
   * 得到是否被拿到的状态
   * @return boolean
   */
  public byte getIsCatched() {
    return isCatched;
  }

  public void setIsCatched(byte isCatched) {
    this.isCatched = isCatched;
  }


  /**
   * paint函数
   * @param g Graphics
   * @param offsetX int
   */
  int i;
  public void paint(Graphics g, int offsetX) {
    if (i == 0) {
      i = 1;
    } else {
      i = 0;
    }
    g.drawImage(imgBonus, tmpBonusX + offsetX, bonusY + i,
                Graphics.TOP | Graphics.LEFT);
    bonusX = tmpBonusX + offsetX;
  }
}

⌨️ 快捷键说明

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