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

📄 enemy.java

📁 手机RPG游戏
💻 JAVA
字号:
package com.xiaoyu.rpggame;import javax.microedition.lcdui.Image;import javax.microedition.lcdui.Graphics;public class Enemy {	int mp, hp;	int at;	int def;	int md;	// 本轮战斗是否已经结束	boolean hasAction;	// 当前动作	byte curAction[];	// 当前的播放的动画索引	byte curAniIndex;	// 怪物数组索引	byte inArrayIndex;	int goSteps;	// 坐标	int fx, fy;	int by;	// 怪物图片得长,宽	int enemyWidth, enemyHeight;	// 动画图片	Image img = null;	// 屏幕对象	GameView m_View;	public Enemy(GameView view, int x, int y, byte i, byte t) {		try {			img = Image.createImage("/enemy" + t + ".png");		} catch (Exception e) {			e.printStackTrace();		}		enemyWidth = img.getWidth() / 4;		enemyHeight = img.getHeight() / 4;		fx = x;		fy = y;		by = y;		inArrayIndex = i;		goSteps = Const.MOVE_STEPS;		mp = Const.ENEMY_MP;		hp = Const.ENEMY_HP;		at = Const.ENEMY_AT * t;		def = 4 * t;		md = 3 * t;		this.m_View = view;		curAction = Const.ENEMY_RIGHT_FRAME;	}	/**	 * 绘制怪物动画	 * 	 * @param g	 *            Graphics	 */	public void drawAnimation(Graphics g) {		curAniIndex = ++curAniIndex >= curAction.length ? 0 : curAniIndex;		// m_View.drawClipImg(x, y, playerWidth, playerHeight,		// curAction[curAniIndex]%3*playerWidth,		// curAction[curAniIndex]/3*playerHeight, pest, g);		m_View.drawClipImg(fx, fy, enemyWidth, enemyHeight,				curAction[curAniIndex] % 4 * enemyWidth, curAction[curAniIndex]						/ 4 * enemyHeight, img, g);		g.setColor(0);		g.drawRect(fx, fy - 6, enemyWidth, 3);		g.setColor(0xff0000);		g.fillRect(fx, fy - 6, enemyWidth * hp / 100, 3);		g.setColor(0xffffff);		g.drawRect(fx, fy - 3, enemyWidth, 3);		g.setColor(0x00ff00);		g.fillRect(fx, fy - 3, enemyWidth * mp / 100, 3);	}	// 攻击后返回	public boolean BackHome() {		this.fx -= Const.MOVE_STEP_X;		if (this.by > Const.HERO_Y) {			this.fy += Const.MOVE_STEP_Y;		} else if (this.by < Const.HERO_Y) {			this.fy -= Const.MOVE_STEP_Y;		}		goSteps--;		if (goSteps <= 0) {			goSteps = Const.MOVE_STEPS;			this.curAction = Const.ENEMY_RIGHT_FRAME;			return true;		}		return false;	}		// 战斗时寻找主角	public boolean FindHero() {		this.fx += Const.MOVE_STEP_X;		if (this.fy < Const.HERO_Y) {			this.fy += Const.MOVE_STEP_Y;		} else if (this.fy > Const.HERO_Y) {			this.fy -= Const.MOVE_STEP_Y;		}		goSteps--;		if (goSteps <= 0) {			goSteps = Const.MOVE_STEPS;			this.curAction = Const.ENEMY_LEFT_FRAME;			return true;		}		return false;	}}

⌨️ 快捷键说明

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