📄 game.java
字号:
case RIGHT_PRESSED:
lin.setFrame(lin.frameright[(count++ % 3)]);
if (count >= 3)
count = 0;
lin.hdx = 5;
break;
case FIRE_PRESSED:
if (buy) {
GAMESTATE = Const.GAME_DIALOGTASK;
pagedown = true;
dlen = 0;
return;
}
if (preEnter3) {
GAMESTATE = Const.GAME_DIALOGTASK;
pagedown = true;
dlen = 0;
return;
}
break;
case GAME_A_PRESSED:
ts1 = System.currentTimeMillis();
if (System.currentTimeMillis() - ts2 > 300)
GAMESTATE = Const.GAME_SYSTEM;// 这里进入系统菜单界面;
break;
}
}
boolean buy = false;
boolean openBox = false;
boolean preOpen = false;
/*********************************************************************************
* 管理游戏进行时的人物移动视窗移动;
*********************************************************************************/
void gameRunning(LayerManager l, int i) { //
int lx = lin.getX();
int ly = lin.getY();
lx += lin.hdx;
ly += lin.hdy;
int backw = l.getLayerAt(i).getWidth();
int backh = l.getLayerAt(i).getHeight();
outBound(l, lx, ly, i);
TiledLayer t = null;
t = (TiledLayer) l.getLayerAt(i);
boolean npcBroke = false;
switch (lin.zmap) {
case 0:
lin.defineCollisionRectangle(0, 6, 16, 20);
if (lin.collidesWith(this.npcSchoolMaster, false)
|| lin.collidesWith(this.npcFeng, false))
npcBroke = true;
break;
case 2:
lin.defineCollisionRectangle(0, 6, 16, 20);
if (lin.collidesWith(this.npcPrince, false))
npcBroke = true;
break;
case 3:
lin.defineCollisionRectangle(0, 6, 16, 20);
if (lin.collidesWith(this.npcEnemyGuard, false)
|| lin.collidesWith(this.npcWendini, false)
|| lin.collidesWith(npcBox, false)
|| lin.collidesWith(npcBox2, false))
npcBroke = true;
if (lin.collidesWith(this.npcEnemyGuard, false)) {
this.currentNpc = this.npcEnemyGuard;
GAMESTATE = Const.GAME_FIGHT;
break;
}
if (lin.collidesWith(this.npcWendini, false)) {
this.currentNpc = this.npcWendini;
GAMESTATE = Const.GAME_FIGHT;
break;
}
if (lin.collidesWith(npcBox, false)) {
preOpen = true;
this.currentNpc = npcBox;
GAMESTATE = Const.GAME_FIGHT;
break;
}
if (lin.collidesWith(npcBox2, false)) {
preOpen = true;
this.currentNpc = npcBox2;
GAMESTATE = Const.GAME_FIGHT;
break;
}
break;
}
lin.defineCollisionRectangle(4, 22, 8, 8);
if (!npcBroke && !lin.collidesWith(t, false)) {
viewX += lin.hdx;
viewY += lin.hdy;
if (viewX <= 0 || lx <= SCREENWIDTH / 2)
viewX = 0;
if (viewY <= 0 || ly <= SCREENHEIGHT / 2)
viewY = 0;
if (viewX >= backw - SCREENWIDTH
|| lx > backw - SCREENWIDTH / 2)
viewX = backw - SCREENWIDTH;
if (viewY >= backh - SCREENHEIGHT || ly > backh - SCREENHEIGHT / 2)
viewY = backh - SCREENHEIGHT;
l.setViewWindow(viewX, viewY, SCREENWIDTH, SCREENHEIGHT);
} else {
lin.move(-lin.hdx, -lin.hdy);// 如果碰撞了就倒退原来的位置;
}
g.setColor(0, 180, 20);
g.fillRect(0, 0, SCREENWIDTH, SCREENHEIGHT);
l.paint(g, 0, 0);
lin.hx = lin.getX();
lin.hy = lin.getY();
taskRunning(l);// 处理该地图内的任务
t = null;
}
void npcBroke(LayerManager l) {
}
/**
* 判断越界是否;
*
* @param lx
* 主角在大地图上的坐标x
* @param ly
* 主角在大地图上的坐标y
*/
void outBound(LayerManager l, int lx, int ly, int i) {
int backw = l.getLayerAt(i).getWidth();
int backh = l.getLayerAt(i).getHeight();
if (ly >= backh - 32)
ly = backh - 32;
if (ly <= 0)
ly = 0;
if (lx >= backw - 16)
lx = backw - 16;
if (lx <= 0)
lx = 0;
lin.setPosition(lx, ly);// 不越界的情况再设定玩家此时合法的坐标位置
}
private Image imSchoolMaster = null, imPrince = null;
void taskRunning(LayerManager lay) {
if (judgeTaskArea() != 5)
buy = false;// buy就是判断主角是否在买卖区域;
if (judgeTaskArea() != 6)
preEnter3 = false;
if (lay == l)// 当主人公在大地图时可以触发的任务;
{
if (judgeTaskArea() != 5)
buy = false;
if (judgeTaskArea() != 6)
preEnter3 = false;
switch (judgeTaskArea()) {
case 0:
if (lin.task[0] == -1 && lin.diagState == -1)// 任务1未接受的状态下;
{
GAMESTATE = Const.GAME_DIALOGTASK;
lin.diagState = 0;
}
break;
case 1:
if (lin.task[0] == -1 && lin.diagState == 0) {
GAMESTATE = Const.GAME_DIALOGTASK;
lin.diagState = 1;
diagFinished = false;
dlen = 0;
}
if (lin.task[0] == 1 && lin.diagState == 4) {
GAMESTATE = Const.GAME_DIALOGTASK;
diagFinished = false;
dlen = 0;
lin.diagState = 5;
}
break;
case 2:
if (lin.task[0] == 0 && lin.diagState == 1) {
GAMESTATE = Const.GAME_DIALOGTASK;
lin.diagState = 2;
diagFinished = false;
dlen = 0;
}
break;
// ;
case 5:
if (lin.task[0] == 1 && lin.diagState == 5) {
GAMESTATE = Const.GAME_DIALOGTASK;
lin.diagState = 6;
diagFinished = false;
dlen = 0;
return;
}
if (lin.task[0] == 1) {
diagFinished = false;
dlen = 0;
buy = true;
pagedown = true;
return;
}
break;
case 6:
if (lin.task[2] == 0) {
diagFinished = false;
pagedown = false;// 不按下中间建不会出现对话;
dlen = 0;
preEnter3 = true;
break;
}
}
return;
}
if (lay == lprince) {
switch (judgeTaskArea()) {
case 3:
if (lin.task[0] == 0 && lin.diagState == 2) {
GAMESTATE = Const.GAME_DIALOGTASK;
lin.diagState = 3;
diagFinished = false;
}
break;
case 4:
if (lin.task[0] == 1 && lin.diagState == 4) {
// chuqu;
lin.secondLoad = true;
lin.zmap = 0;
lin.hx = 27 * 16;
lin.hy = 18 * 16;
}
break;
}
return;
}
if (lay == lplain) {
switch (judgeTaskArea()) {
case 7:
lin.secondLoad = true;
lin.zmap = 0;
lin.hx = 5 * 16;
lin.hy = 21 * 16;
break;
}
}
}
/**
* @param key游戏任务对话中的按键处理
* ;
*/
void dialogTaskInput(int key) {
switch (key) { // 针对不同对话进行处理 ;
case FIRE_PRESSED:
pagedown = true;
switch (lin.diagState) {
case 0:
GAMESTATE = Const.GAME_RUNNING;
dlen = 0;
diagFinished = false;
break;
case 1:
if (diagFinished) {
lin.task[0] = 0;// 对话完成才算接受任务
dlen = 0;
diagFinished = false;
GAMESTATE = Const.GAME_RUNNING;
}
break;
case 2:
GAMESTATE = Const.GAME_RUNNING;
lin.hx = 9 * 16;
lin.hy = 17 * 16;
lin.zmap = 2;
diagFinished = false;
dlen = 0;
lin.firstLoad = true;
break;
case 3:
if (diagFinished) {
dlen = 0;
diagFinished = false;
GAMESTATE = Const.GAME_FIGHT;
currentNpc = this.npcPrince;// 当前战斗的怪物;
indexX = 0;
indexY = 0;
}
break;
case 4:
if (diagFinished) {
GAMESTATE = Const.GAME_RUNNING;
pagedown = true;
lin.task[0] = 1;
dlen = 0;
diagFinished = false;
break;
}
case 5:
if (diagFinished) {
GAMESTATE = Const.GAME_RUNNING;
lin.task[2] = 0;
dlen = 0;
diagFinished = false;
break;
}
case 6:
if (diagFinished) {
lin.diagState = 7;
dlen = 0;
diagFinished = false;
GAMESTATE = Const.GAME_RUNNING;
break;
}
}
if (this.sellOrBuy)
{
this.GAMESTATE = Const.GAME_SELLORBUY;
return;
}
if (this.Enter3) {
lin.hx = 1 * 24;
lin.hy = 8 * 16;
lin.zmap = 3;
diagFinished = false;
dlen = 0;
lin.firstLoad = true;
this.GAMESTATE = Const.GAME_RUNNING;
return;
}
}
}
boolean diagFinished = false;
private int dlen = 0;
private boolean sellOrBuy = false;
private boolean Enter3 = false, preEnter3 = false;
/**
*
*/
void drawDialogTask() {
if (buy && pagedown && !(lin.diagState == 6)) {
Const.drawString(g, "希洛,今天你想买点什么?请多注意身体,", 0, 0,
2 * SCREENHEIGHT / 3, SCREENWIDTH, SCREENHEIGHT / 3, true,
true, Font.SIZE_LARGE);
g.drawImage(loadImage("/character/fenghead.png"), 0,
2 * SCREENHEIGHT / 3 - 50, 20);
dlen++;
if (dlen >= 1)
this.diagFinished = true;
pagedown = false;
this.sellOrBuy = true;
return;
}
if (preEnter3 && pagedown) {
pagedown = false;
Const.drawString(g, "希洛学长,你要去试炼草原吗,祝你好运,", 0, 0,
2 * SCREENHEIGHT / 3, SCREENWIDTH, SCREENHEIGHT / 3, true,
true, Font.SIZE_LARGE);
dlen++;
if (dlen >= 1)
this.diagFinished = true;
this.Enter3 = true;
return;
}
switch (lin.diagState) {// 这是情节对话控制器;
case 0: {
if (pagedown)
Const.drawString(g, "希洛学长,院长有重要的事情找您,请您快去中庭找他;", 0, 0,
2 * SCREENHEIGHT / 3, SCREENWIDTH, SCREENHEIGHT / 3,
true, true, Font.SIZE_LARGE);
pagedown = false;
}
break;
case 1:
try {
if (pagedown) {
// 画一幅背景图;
g.drawImage(loadImage("/back.png"), 0, 0, 20);
if (dlen == 1 || dlen == 8)
g.drawImage(lin.imgplayer, 0, 2 * SCREENHEIGHT / 3
- lin.imgplayer.getHeight(), 20);
else
g.drawImage(imSchoolMaster, 0, 2 * SCREENHEIGHT / 3
- imSchoolMaster.getHeight(), 20);
Const.drawString(g, Const.TaskDiag[0][dlen++], 0, 0,
2 * SCREENHEIGHT / 3, SCREENWIDTH,
SCREENHEIGHT / 3, true, true, Font.SIZE_LARGE);
pagedown = false;
if (dlen >= Const.TaskDiag[0].length) {
dlen = Const.TaskDiag[0].length - 1;
diagFinished = true;
}
}
} catch (Exception e) {
System.out.println("发生异常程序中止");
}
break;
case 2:
if (lin.trait == 1) {
Const.drawString(g, "欢迎您的光临,希洛阁下,"
+ "您就是尊贵的希尔法学院派出的代表吧,看起来您的眼睛不太好,还请多加小心,我这就带您到王子殿下的行宫去",
0, 0, 2 * SCREENHEIGHT / 3, SCREENWIDTH,
SCREENHEIGHT / 3, true, true, Font.SIZE_LARGE);
} else
Const.drawString(g,
"欢迎您的光临,希洛阁下,您就是尊贵的希尔法学院派出的代表吧,我这就带您到王子殿下的行宫去", 0, 0,
2 * SCREENHEIGHT / 3, SCREENWIDTH, SCREENHEIGHT / 3,
true, true, Font.SIZE_LARGE);
break;
case 3:
if (pagedown) {
g.drawImage(loadImage("/fightback/princefight.png"), 0, 0, 20);
if (dlen == 2 || dlen == 4 || dlen == 6)
g.drawImage(lin.imgplayer, 0, 2 * SCREENHEIGHT / 3
- lin.imgplayer.getHeight(), 20);
else
g.drawImage(imPrince, 0, 2 * SCREENHEIGHT / 3
- imPrince.getHeight(), 20);
Const.drawString(g, Const.TaskDiag[1][dlen++], 0, 0,
2 * SCREENHEIGHT / 3, SCREENWIDTH, SCREENHEIGHT / 3,
true, true, Font.SIZE_LARGE);
pagedown = false;
if (lin.trait == 2) {
}
if (dlen >= Const.TaskDiag[1].length) {
dlen = Const.TaskDiag[1].length - 1;
diagFinished = true;
}
}
break;
case 4:
if (pagedown) {
pagedown = false;
g.drawImage(loadImage("/fightback/princefight.png"), 0, 0, 20);// 这里可以抽象的;
Const
.drawString(
g,
"我竟然输了,可恶!!一定是他们隐瞒了什么,我还要更强的力量,小子不要得意,下次再见到我的时候就让你死,现在给我滚",
0, 0, 2 * SCREENHEIGHT / 3, SCREENWIDTH,
SCREENHEIGHT / 3, true, true, Font.SIZE_LARGE);
g.drawImage(imPrince, 0, 2 * SCREENHEIGHT / 3
- imPrince.getHeight(), 20);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -