package com.xiaoyu.rpggame;
import javax.microedition.lcdui.*;
import java.io.*;
import java.util.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.game.Sprite;
public class GameView extends Canvas implements Runnable {
// ========地图数据=========
// 地图数据
byte mapData[][];
// 地图块尺寸
final static byte MAP_TILE_SIZE = 24;
// 地图的最大长和宽
int maxWidth, maxHeight;
// 当前地图编号
byte mapID = 0;
byte mapTrigger[];// 地图切换点
boolean loadOver;// 当前读取是否完毕
// ========END=========
// ========图片数据=========
Image imgMap = null;
Image bgMap = null;
Image imgLogoBack = null;
Image imgLogoTitle = null;
Image gameOver = null;
int logoWidth, logoHeight;
// ========END=========
// ========文字========
Font f;
int fontWidth, fontHeight;
int fontMargin = 4;// 文字间隔
// ========END=========
int curIndex;// 当前得菜单选项
// 当前的按键
int curKey;
// 人物对象
Hero player;
int exp;
//对话框的位置
int dx,dy, wy;
// 怪物数组
Vector enemys;
// 当前屏幕状态
byte curScreenState;
// 动画播放时间
byte splashTime = 10;
byte alertTime = -1;
// 是否暂停,用于处理中断
boolean isPause = false;
int enemyIndex = 0;
Enemy e = null;
Sound sound;
Random r = new Random();
//记录名称
String RMS_NAME;
String[] Dialog;
static String[] save = {"无记录", "无记录", "无记录"};
public GameView() {
// 设置全屏
this.setFullScreenMode(true);
// 图片初始化
try {
imgLogoBack = Image.createImage("/bg7.jpg");
imgLogoTitle = Image.createImage("/menu.png");
bufImage = Image.createImage(Const.SCREEN_WIDTH,
Const.SCREEN_HEIGHT);
sound = new Sound("/bg1.mid");
} catch (IOException e) {
System.out.println("图片读取失败!请检测地图相关路径是否准确!");
e.printStackTrace();
}
sound.playSound();
logoWidth = imgLogoTitle.getWidth();
logoHeight = imgLogoTitle.getHeight();
// 画笔初始化
bufGraphics = bufImage.getGraphics();
// Dialog = Const.PLAYER_DIALOGS[0];
// 字体初始化
f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
fontHeight = f.getHeight();
fontWidth = f.stringWidth("攻");
// 地图数据静态初始化
mapData = Const.MAP_DATA[mapID];
//地图切换点初始化
mapTrigger = Const.MAP_TRIGGER[mapID];
curScreenState = Const.GAME_LOGO;
RMS_NAME = Const.RMS_NAME;
dx = 20;
dy = 120;
wy = dy + 30;
Thread t = new Thread(this);
t.start();
}
/**
* 读取地图数据
*/
public void LoadMapData(byte mapID) {
}
public void run() {
while (true) {
repaint();
EventCheck();
try {
Thread.sleep(120);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// 双缓冲
Image bufImage;
Graphics bufGraphics;
// 当前要显示得屏幕位置
int sx, sy;
public void DrawMap(Graphics g) {
// 将地图画在缓冲区
// 当人物往左上角漫游时sx和sy的值
sx = player.x - Const.SCREEN_WIDTH / 2 < 0 ? 0 : player.x
- Const.SCREEN_WIDTH / 2;
sy = player.y - Const.SCREEN_HEIGHT / 2 < 0 ? 0 : player.y
- Const.SCREEN_HEIGHT / 2;
// 当人物往右下角漫游时sx和sy的值
sx = player.x + Const.SCREEN_WIDTH / 2 + player.playerWidth > maxWidth ? maxWidth
- Const.SCREEN_WIDTH
: sx;
sy = player.y + Const.SCREEN_HEIGHT / 2 + player.playerHeight > maxHeight ? maxHeight
- Const.SCREEN_HEIGHT
: sy;
// 需要绘制的地图的起始索引
int startIndexX = sx / MAP_TILE_SIZE;
int startIndexY = sy / MAP_TILE_SIZE;
// x和y方向的偏移量
int offSetX = sx % MAP_TILE_SIZE;
int offSetY = sy % MAP_TILE_SIZE;
// 备缓中图片当前索引
int xPos = 0;
int yPos = 0;
bufGraphics.setColor(0);
bufGraphics.fillRect(0, 0, Const.SCREEN_WIDTH, Const.SCREEN_HEIGHT);
for (int i = startIndexX; i <= startIndexX + Const.SCREEN_WIDTH
/ MAP_TILE_SIZE + 1; i++) {
for (int j = startIndexY; j <= startIndexY + Const.SCREEN_HEIGHT
/ MAP_TILE_SIZE + 1; j++) {
// System.out.println(i + " " + j);
if (i >= mapData.length || j >= mapData[i].length)
continue;
drawClipImg(xPos * MAP_TILE_SIZE - offSetX, yPos
* MAP_TILE_SIZE - offSetY, MAP_TILE_SIZE,
MAP_TILE_SIZE, (mapData[j][i] - 1) * MAP_TILE_SIZE, 0,
imgMap, bufGraphics);
if(i == mapTrigger[0] && j == mapTrigger[1]) {
bufGraphics.setColor(0xffff00);
bufGraphics.drawRect(xPos * MAP_TILE_SIZE - offSetX, yPos
* MAP_TILE_SIZE - offSetY, 20, 20);
}
yPos++;
}
// bufGraphics.setColor(0xff0000);
// bufGraphics.drawRect((mapTrigger[0]-startIndexX) * MAP_TILE_SIZE + offSetX,
// (mapTrigger[1]-startIndexY) * MAP_TILE_SIZE + offSetY, MAP_TILE_SIZE, MAP_TILE_SIZE);
yPos = 0;
xPos++;
}
}
// ==========================界面绘制=====================
// 绘制半透明框
public void DrawAlphaRect(int x, int y, int width, int height, int color,
Graphics g) {
int array[] = new int[height * width];
for (int i = 0; i < array.length; i++) {
array[i] = color;
}
g.drawRGB(array, 0, width, x, y, width, height, true);
g.setColor(color);
g.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 10, 10);
g.drawRoundRect(x - 2, y - 2, width + 3, height + 3, 10, 10);
}
// 绘制物品界面
public void DrawTools() {
DrawFightMap(bufGraphics);
player.drawAnimationFight(bufGraphics);
for (int i = 0; i < enemys.size(); i++) {
Enemy e = (Enemy) enemys.elementAt(i);
e.drawAnimation(bufGraphics);
}
String[] toolNames = new String[player.tools.size()];
int id = ((Tool)player.tools.elementAt(curIndex)).id;
for(int i=0; i<player.tools.size(); i++) {
Tool t = (Tool)player.tools.elementAt(i);
toolNames[i] = t.name + " " + t.count;
}
DrawStringMenu(toolNames, bufGraphics);
this.DrawIntroduce("功效HP加"+Const.TOOLS_PROPERTICE[id][1]+", MP加"+Const.TOOLS_PROPERTICE[id][2], bufGraphics);
this.DrawCommand(Const.COMMAND[3], Const.COMMAND[1]);
}
public void DrawSystemTools() {
DrawMap(bufGraphics);
player.drawAnimationFight(bufGraphics);
String[] toolNames = new String[player.tools.size()];
int id = ((Tool)player.tools.elementAt(curIndex)).id;
for(int i=0; i<player.tools.size(); i++) {
Tool t = (Tool)player.tools.elementAt(i);
toolNames[i] = t.name + " " + t.count;
}
DrawStringMenu(toolNames, bufGraphics);
this.DrawIntroduce("功效HP加"+Const.TOOLS_PROPERTICE[id][1]+", MP加"+Const.TOOLS_PROPERTICE[id][2], bufGraphics);
this.DrawCommand(Const.COMMAND[3], Const.COMMAND[1]);
}
//绘制魔法菜单
public void DrawMagicMenu() {
DrawFightMap(bufGraphics);
player.drawAnimationFight(bufGraphics);
for (int i = 0; i < enemys.size(); i++) {
Enemy e = (Enemy) enemys.elementAt(i);
e.drawAnimation(bufGraphics);
}
DrawStringMenu(player.magic, bufGraphics);
DrawCommand(Const.COMMAND[3], Const.COMMAND[1]);
}
// 绘制暂停界面
public void DrawPause() {
DrawMap(bufGraphics);
player.drawAnimation(bufGraphics);
this.DrawStringMenu(Const.PAUSE, bufGraphics);
this.DrawCommand(Const.COMMAND[3], Const.COMMAND[2]);
}
//绘制系统界面
public void DrawSystem() {
DrawMap(bufGraphics);
player.drawAnimation(bufGraphics);
this.DrawStringMenu(Const.SYSTEM, bufGraphics);
this.DrawCommand(Const.COMMAND[3], Const.COMMAND[2]);
}
// 绘制游戏界面
public void DrawScreenScene() {
DrawMap(bufGraphics);
player.drawAnimation(bufGraphics);
this.DrawCommand(Const.COMMAND[4], Const.COMMAND[6]);
}
// 绘制游戏封面logo
public void DrawScreenLogo() {
bufGraphics.drawImage(imgLogoBack, 0, 0, 20);
bufGraphics.drawImage(imgLogoTitle, (Const.SCREEN_WIDTH-logoWidth)/2, Const.SCREEN_HEIGHT-logoHeight,
J2ME RPG游戏 仿梦幻西游
3星 · 超过75%的资源 需积分: 11 168 浏览量
2009-08-15
23:00:17
上传
评论
收藏 800KB RAR 举报
hhp50215
- 粉丝: 1
- 资源: 4
最新资源
- WANGSHANGYINHANG-4.2.9.031406-android
- docker&docker-compose离线安装包(centos)
- 混淆矩阵(Confusion Matrix)是机器学习领域中一种常用的可视化工具4.txt
- 滑动窗口是一种流量控制技术,用于在数据传输过程中进行拥塞控制和流量调节4.txt
- Nacos如何支持服务发现和注册-基于词频统计的分析.txt
- 基于BP神经网络的PID控制算法-MATLAB实现
- :基于java打造的深度学习框架,帮助你快速搭建神经网络,实现模型推理与训练,引擎支持自动求导,多线程与GPU运算
- yolo人脸目标检测数据集
- 第九次作业(XY图,XY图显示,三维曲面,数字波形图)
- Unity3D版本游戏源码解压密码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈