scr.java
来自「litwizi j2me」· Java 代码 · 共 1,821 行 · 第 1/3 页
JAVA
1,821 行
a.dirU=true;
a.dirD=false;
break;
case 2:
a.dirR=true;
a.dirL=false;
break;
case 3:
a.dirD=true;
a.dirU=false;
break;
case 4:
a.dirL=true;
a.dirR=false;
break;
}
}
} // End freeze cond
drawEnt(a);
} // End else
} // End condition if gamestate
} // End loop
}
// *** MOVE an ent. If an ent has a direction and is sent to
// this routine, it will have its x & y changed accordingly
// if it is possible to move : returns true(move) or false
public boolean doDir(ent e)
{
boolean movUpDown=false;
boolean movLeftRight=false;
ent tempEnt;
tempEnt=new ent(e.x, e.y, e.z);
// Move depending on direction, y axis, then x
if (e.dirD)
{
e.y+=e.moveSpeed;
movUpDown=true;
if (!canWeMove(e))
{
e.y=tempEnt.y;
movUpDown=false;
}
}
if (e.dirU)
{
e.y-=e.moveSpeed;
movUpDown=true;
if (!canWeMove(e))
{
e.y=tempEnt.y;
movUpDown=false;
}
}
if (e.dirL)
{
e.x-=e.moveSpeed;
if (e.z<110) e.i=e.z+1;
movLeftRight=true;
if (!canWeMove(e))
{
e.x=tempEnt.x;
movLeftRight=false;
}
}
if (e.dirR)
{
e.x+=e.moveSpeed;
if (e.z<110) e.i=e.z;
movLeftRight=true;
if (!canWeMove(e))
{
e.x=tempEnt.x;
movLeftRight=false;
}
}
// If we can't move, restore x to old position
if (movUpDown || movLeftRight)
{
e.flip=!e.flip;
return true;
}
else
{
return false;
}
}
// *** MOVE HERE? Check in this position if we can move here
// Takes an ent in a new position and checks collison against background first,
// then if it isn't us, check to see if it hits us.
public boolean canWeMove(ent e)
{
int x1, y1;
x1=getXblock(e.x);
y1=getYblock(e.y);
// Check only the background near (in a square around us)
for (int qy=y1; qy<=y1+1; qy++)
{
for (int qx=x1; qx<=x1+1; qx++)
{
// Check each square
int a=qx+(qy*200);
int result;
result=curLev.collide(e, curLev.curEnt[a]);
// If result >0 then we hit something
if (result >0)
{
// Only things we can do, not monsters
if (e.z==98)
{
nearCauldron=false;
// Things we pickp but don't go into inventory
if (result >49 && result<59)
{
// GOLD
if (result==50)
{
msg1="You found some Gold!";
gold++;
curLev.reDist(result);
// --* Public Message #1
if (!publicMsg[1])
{
publicM(1, getXscr(e.x), getYscr(e.y));
}
}
// HEALTH
if (result==51)
{
msg1="You found extra health! (+10)";
health+=10;
// --* Public Message #6
if (!publicMsg[6])
{
publicM(6, getXscr(e.x), getYscr(e.y));
}
}
// FOOD
if (result==53)
{
msg1="Mmm, you eat some food.";
msg2="(Food +10)";
food+=10;
// --* Public Message #2
if (!publicMsg[2])
{
publicM(2, getXscr(e.x), getYscr(e.y));
}
}
// poisoned FOOD
if (result==54)
{
msg1="Ugh! You eat bad food.";
msg2="(Health -15)";
health-=15;
}
// Vanishing wall
if (result==55)
{
// --* Public Message #0
if (!publicMsg[11])
{
publicM(11, getXscr(e.x), getYscr(e.y));
}
}
// Fairy Queen! -- END OF GAME
if (result==56)
{
publicM(12, getXscr(e.x), getYscr(e.y));
s_won.play();
gameState=-10;
title=getImage(getCodeBase(),"end.jpg");
while (!paper.drawImage(title,20,20,this));
msg1="Congratulations!";
msg2="* Game Over *";
}
delEnt(curLev.curEnt[a]);
curLev.curEnt[a].z=0;
curLev.reDist(result);
updateScores();
s_pickUp.play();
return false;
}
// A door
if (result==40)
{
if(inventory.getID()==42)
{
inventory.removeFromInv();
curLev.reDist(42);
msg1="You open the door...";
delEnt(curLev.curEnt[a]);
curLev.curEnt[a].z=0;
updateScores();
s_pickUp.play();
return true;
}
else
{
// --* Public Message #8
if (!publicMsg[8])
{
publicM(8, getXscr(e.x), getYscr(e.y));
}
}
}
// The cauldron
if (result==59)
{
nearCauldron=true;
msg1="In the cauldron is:";
msg2=ourCauldron.whatsIn();
updateScores();
// --* Public Message #4
if (!publicMsg[4])
{
publicM(4, getXscr(e.x), getYscr(e.y));
}
}
// Gateway?
if (result==20)
{
doGateway();
return true;
}
// Ingredients for the pot? (Things you can pick up)
if ((result>59 && result <85) || result==42 || result>109)
{
if (inventory.addItem(result))
{
delEnt(curLev.curEnt[a]);
curLev.curEnt[a].z=0;
if (result==42)
{
msg1="You pick up "+item.getName(result);
}
else
{
msg1="You get some "+item.getName(result);
}
s_pickUp.play();
updateScores();
// Normal item
if (result<70)
{
// --* Public Message #3
if (!publicMsg[3])
{
publicM(3, getXscr(e.x), getYscr(e.y));
}
}
// Scroll
if (result>69 && result<85)
{
// --* Public Message #9
if (!publicMsg[9])
{
publicM(9, getXscr(e.x), getYscr(e.y));
}
}
// Spell
if (result>85)
{
// --* Public Message #10
if (!publicMsg[10])
{
publicM(10, getXscr(e.x), getYscr(e.y));
}
}
return false;
}
else
{
msg1="You can't carry any more.";
updateScores();
return false;
}
}
// Chest - random contents
if (result==41)
{
// --* Public Message #5
if (!publicMsg[5])
{
publicM(5, getXscr(e.x), getYscr(e.y));
}
int rn2=0;
int rn=(int)(3*Math.random())+1;
delEnt(curLev.curEnt[a]);
msg1="In the chest: ";
switch (rn)
{
// Food etc
case 1:
rn2=(int)(4*Math.random())+50;
msg2=item.getName(rn2);
break;
// Monsters
case 2:
rn2=(((int)(2*Math.random())))+87;
msg2=item.getName(rn2);
curLev.curEnt[a].z=rn2;
curLev.curEnt[a].moves=true;
curLev.curEnt[a].dirL=true;
curLev.addToMvArray(a);
s_pain.play();
updateScores();
return false;
// Plants etc
case 3:
rn2=(int)(9*Math.random())+60;
msg2=item.getName(rn2);
break;
default:
rn2=0;
msg1="Nothing in the chest";
break;
}
curLev.curEnt[a].z=rn2;
curLev.curEnt[a].i=rn2;
s_pickUp.play();
drawEnt(curLev.curEnt[a]);
updateScores();
}
} // End conditional e.z==98
// Spells to destory walls and trees here
if (e.z==118 || e.z==119)
{
// = Destroy Wall Frenis Vim 119
if (e.z==118 && (result==2 || result==7 || result==12))
{
blowUp(e);
curLev.updateWindow(xOrigin, yOrigin);
e.freeze=-1;
s_explode.play();
}
// = Destroy Tree Natum Tan 118
if (e.z==119 && (result==10 || result==16 || result==26 || result==27 || result==30 || result==31 || result==32 || result==33))
{
blowUp(e);
curLev.updateWindow(xOrigin, yOrigin);
e.freeze=-1;
s_explode.play();
}
}
// Otherwise, we've hit something!
return false;
}
// ** This is an ent, not a spell
// ** If the ent is NOT US, check and see if collides with us,
// ** Or another moving ent
if (e.z < 98 || e.z >99)
{
result=curLev.collide(e, ourEnt);
// It does, and it isn't a spell
if (result > 0 && e.z<110)
{
if (e.z!=90 && e.z!=106)
{
// Check if this is Evil Wiz, Death, demon, devil or (bat or ghost)
if (e.z==108) health=-1;
if (e.z==85) health-=5;
if (e.z==94 || e.z==104) health-=3;
if (e.z==100 || e.z==102) health-=2;
if (e.z==92) health-=3;
if (e.z==87 || e.z==88 || e.z==96) health--;
msg1="Argh! The "+item.getName(e.z)+" attacks!";
updateScores();
s_pain.play();
// --* Public Message #0
if (!publicMsg[0])
{
publicM(0, getXscr(e.x), getYscr(e.y));
}
// Dead!
if (health<0)
{
s_dead.play();
doInit();
}
}
return false;
}
// ** Check against other ents in room too
for (int i=0; i<curLev.numInRm; i++)
{
ent aa=curLev.movInRm[i];
if (aa!=e)
{
result=curLev.collide(e, aa);
// We have, and it isn't a spell
if (result > 0)
{
// It is a wandering spell: aa = spell, e = ent
// ********** SPELL CASTING hits Ents
if (aa.z>109)
{
// Fugit Spell 112
if (aa.z==112)
{
e.freeze=150;
msg1="The "+item.getName(e.z)+" is frozen!";
delEnt(aa);
curLev.removeFromRm(i);
s_banish.play();
}
// Spells to 'banish' ents
if ( (aa.z==113 && e.z==87)
|| (aa.z==113 && e.z==88)
|| (aa.z==114 && e.z==96)
|| (aa.z==115 && e.z==94)
|| (aa.z==115 && e.z==104)
|| (aa.z==116 && e.z==92)
|| (aa.z==116 && e.z==102)
|| (aa.z==117 && e.z==85) )
{
e.freeze=-1;
msg1="The "+item.getName(e.z)+" is banished!";
delEnt(aa);
curLev.removeFromRm(i);
s_banish.play();
}
updateScores();
return true;
} // End >109
return false;
} // end (result >0)
} // end 'not ourselves'
} // end loop through ents
} // End of ENT section
} // End loop
} // End loop
// *** - US : We did not hit anything, but have we hit a monster?
if (e.z==98)
{
ent a;
int result;
for (int i=0; i<curLev.numInRm; i++)
{
a=curLev.movInRm[i];
result=curLev.collide(e, a);
// We have, and it isn't a spell
if (result > 0 && result<110)
{
// Trader - we will buy information?
if (result==90)
{
// ** Num messages trader has is here
if (traderMsgNum<16)
{
trade.doMsg(traderMsgNum+200, getXscr(a.x), getYscr(a.y));
s_message.play();
gameState=100; //Pause
}
}
return false;
}
}
}
// If we get to here then there is nothing around us so we can move
return true;
}
// ** Set this ent as a block value on grid
// Used when an ent wanders off the current screen.
public void setAsBlock(ent a)
{
int x=getXblock(a.x);
int y=getYblock(a.y);
int c=x+(y*200);
curLev.curEnt[c].moves=a.moves;
curLev.curEnt[c].dirU=a.dirU;
curLev.curEnt[c].dirD=a.dirD;
curLev.curEnt[c].dirL=a.dirL;
curLev.curEnt[c].dirR=a.dirR;
curLev.curEnt[c].x=x*20;
curLev.curEnt[c].y=y*20;
curLev.curEnt[c].z=a.z;
curLev.curEnt[c].moveSpeed=a.moveSpeed;
}
// ** If ent is outside current room?
// Used to decide if we remove this ent from the list currently in the room
public boolean offScreen(int a)
{
int x=getXscr(curLev.movInRm[a].x);
int y=getYscr(curLev.movInRm[a].y);
if (x>xsize || x<0 || y>ysize || y<0) return true;
return false;
}
// *** Scroll screen if we need to
// Depends on us having just moved
private void scrollScreen()
{
// Check if we need to scroll screen?
if (ourEnt.dirD)
{
if (getYscr(ourEnt.y)>160)
{
yOffset+=4;
if (yOffset==40)
{
yOffset=20;
yOrigin+=1;
curLev.moveDown();
curLev.drawBottom(xOrigin, yOrigin);
}
}
}
if (ourEnt.dirU)
{
if (getYscr(ourEnt.y)<60)
{
yOffset-=4;
if (yOffset==0)
{
yOffset=20;
yOrigin-=1;
curLev.moveUp();
curLev.drawTop(xOrigin, yOrigin);
}
}
}
if (ourEnt.dirL)
{
if (getXscr(ourEnt.x)<60)
{
xOffset-=4;
if (xOffset==0)
{
xOffset=20;
xOrigin-=1;
curLev.moveLeft();
curLev.drawLeft(xOrigin, yOrigin);
}
}
}
if (ourEnt.dirR)
{
if (getXscr(ourEnt.x)>160)
{
xOffset+=4;
if (xOffset==40)
{
xOffset=20;
xOrigin+=1;
curLev.moveRight();
curLev.drawRight(xOrigin, yOrigin);
}
}
}
}
// *** Drop whatever we've selected
public void dropItem()
{
int i=inventory.getID();
// There is something to drop
if (i>0)
{
int j=curLev.getNearestSpace(getXblock(ourEnt.x), getYblock(ourEnt.y));
if (j>0)
{
if (curLev.collide(curLev.curEnt[j], ourEnt)==0)
{
curLev.curEnt[j].z=i;
curLev.curEnt[j].i=i;
drawEnt(curLev.curEnt[j]);
inventory.removeFromInv();
msg1="You drop the "+item.getName(i);
s_pickUp.play();
updateScores();
}
else
{
msg1="You can't drop that here.";
updateScores();
}
}
else
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?