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

📄 human.java

📁 以传奇中的人物和怪物作为角色
💻 JAVA
字号:
package com.liuwan.j2me.monster;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 * <p>Title: Develop game research</p>
 *
 * <p>Description: Develop game research</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: Liuwan studio</p>
 *
 * @author Liuwan
 * @version 1.0
 */
public class Human extends Sprite implements Runnable{
    private int x;
    private int y;
    private int life = 30;
    private boolean onBeat = false;
    private Graphics graphics;
    private MonsterCanvas gameCanvas;


    public Human(Image image) {
        super(image);
    }

    public Human(Image image, int frameWidth, int frameHeight) {
        super(image, frameWidth, frameHeight);
    }

    public Human(Sprite s) {
        super(s);
    }
    public void start(){
        Thread t = new Thread(this);
        t.start();
    }
    public void run(){
        while(true){
            if(onBeat){
                beat();
            }
        }
    }

    public void beat() {
        int currentFrame = 0;
        while (currentFrame < 6) {
            this.setFrame(currentFrame++);
            this.setPosition(this.getX(), this.getY());
            try {
                Thread.sleep(100);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            this.paint(graphics);
            gameCanvas.draw(graphics);
        }
        try {
            Thread.sleep(500);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        Monster monster = gameCanvas.getMonster();
        monster.setLife(monster.getLife() - 2);
        this.setFrame(0);
        this.setPosition(this.getX(), this.getY());
        this.paint(graphics);
        gameCanvas.draw(graphics);
    }
    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public void setOnBeat(boolean onBeat) {
        this.onBeat = onBeat;
    }

    public void setGraphics(Graphics graphics) {
        this.graphics = graphics;
    }

    public void setGameCanvas(MonsterCanvas gameCanvas) {
        this.gameCanvas = gameCanvas;
    }

    public int getLife() {
        return life;
    }

    public boolean isOnBeat() {
        return onBeat;
    }

    public Graphics getGraphics() {
        return graphics;
    }

    public MonsterCanvas getGameCanvas() {
        return gameCanvas;
    }


}

⌨️ 快捷键说明

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