scr.java
来自「litwizi j2me」· Java 代码 · 共 1,821 行 · 第 1/3 页
JAVA
1,821 行
msg1="There's no space to drop";
msg2="that here.";
updateScores();
}
}
}
// *** Useful routines for converting co-ord types etc..***
// Return screen x position from and absolute xposition
public int getXscr(int xabs)
{
return 100+(xabs-xOrigin*20);
}
// Return screen y position from and absolute xposition
public int getYscr(int yabs)
{
return 100+(yabs-yOrigin*20);
}
// Return block x block from an absolute xposition
public int getXblock(int xabs)
{
return (int)xabs/20;
}
// Return block x remainder from an absolute xposition
public int getXblockMod(int xabs)
{
return xabs % 20;
}
// Return block y block from an absolute xposition
public int getYblock(int yabs)
{
return (int)yabs/20;
}
// Return block y remainder from an absolute xposition
public int getYblockMod(int yabs)
{
return yabs % 20;
}
// *** LEVEL Input ***
// Uses a level class to input the file and return it as a string
public void getLevel()
{
String levString;
msg1="Loading Level Data...";
updateScores();
repaint();
try
{
curFile=new File(new URL(getDocumentBase(), "level1.dat"));
}
catch (IOException e)
{
// e.printStackTrace();
}
// Room data appears in this string levString
levString=curFile.getData();
// lev class sets up an array to contain level data
curLev=new lev(levString, paper, gfx, gfx2);
// Clear Screen
paper.setColor(Color.black);
paper.fillRect(0,0,xscalesize,yscalesize);
// Draw current window
curLev.setUpWindow(xOrigin, yOrigin);
updateScores();
inventory.drawInv();
}
// *** KEYBOARD ***
public void keyPressed(KeyEvent e)
{
// Called when the user has pressed a key
int key = e.getKeyCode();
if (gameState==0)
{
getLevel();
gameState=1;
}
switch (key)
{
case KeyEvent.VK_DOWN:
ourEnt.dirD=true;
break;
case KeyEvent.VK_LEFT:
ourEnt.dirL=true;
break;
case KeyEvent.VK_RIGHT:
ourEnt.dirR=true;
break;
case KeyEvent.VK_UP:
ourEnt.dirU=true;
break;
case KeyEvent.VK_Y:
gameState=101;
break;
case KeyEvent.VK_N:
gameState=1;
curLev.updateWindow(xOrigin, yOrigin);
break;
case Event.ENTER:
gameState=1;
curLev.updateWindow(xOrigin, yOrigin);
break;
case KeyEvent.VK_1:
speed=5;
msg1="Speed = 5ms Sleep";
msg2="(Fastest Mode)";
updateScores();
break;
case KeyEvent.VK_2:
speed=10;
msg1="Speed = 10ms Sleep";
updateScores();
break;
case KeyEvent.VK_3:
speed=15;
msg1="Speed = 15ms Sleep";
updateScores();
break;
case KeyEvent.VK_4:
speed=20;
msg1="Speed = 20ms Sleep";
updateScores();
break;
case KeyEvent.VK_5:
speed=25;
msg1="Speed = 25ms Sleep";
updateScores();
break;
case KeyEvent.VK_6:
speed=30;
msg1="Speed = 30ms Sleep";
updateScores();
break;
case KeyEvent.VK_7:
speed=35;
msg1="Speed = 40ms Sleep";
updateScores();
break;
case KeyEvent.VK_8:
speed=40;
msg1="Speed = 50ms Sleep";
updateScores();
break;
case KeyEvent.VK_9:
speed=50;
msg1="Speed = 60ms Sleep";
msg2="(Slowest Mode)";
updateScores();
break;
default:
break;
}
}
public void keyTyped(KeyEvent e) { }
public void keyReleased(KeyEvent e)
{
// Called when the user has pressed a key
int key = e.getKeyCode();
switch (key)
{
case KeyEvent.VK_DOWN:
ourEnt.dirD=false;
break;
case KeyEvent.VK_LEFT:
ourEnt.dirL=false;
break;
case KeyEvent.VK_RIGHT:
ourEnt.dirR=false;
break;
case KeyEvent.VK_UP:
ourEnt.dirU=false;
break;
case KeyEvent.VK_D:
dropItem();
break;
case KeyEvent.VK_Q:
inventory.changeItem();
msg1="Selected "+inventory.getName();
updateScores();
break;
case Event.TAB:
inventory.changeItem();
msg1="Selected "+inventory.getName();
updateScores();
break;
case KeyEvent.VK_SPACE:
doCauldronThing();
break;
case KeyEvent.VK_ESCAPE:
doInit();
break;
default:
break;
}
}
// Update scoreboard
public void updateScores()
{
scores.setColor(Color.black);
scores.fillRect(0,0,xscalesize,36);
scores.setColor(Color.lightGray);
scores.drawString("Gold:", 5, 35);
scores.drawString("Food:", 70, 35);
scores.drawString("Health:", 140, 35);
scores.setColor(Color.white);
scores.drawString(msg1, 5,10);
scores.drawString(msg2, 5,20);
msg1="";
msg2="";
scores.setColor(Color.yellow);
scores.drawString(gold+"", 37, 35);
scores.drawString(food+"", 104, 35);
scores.drawString(health+"", 180, 35);
}
// ---*** SPACE KEY Routine
// We have pressed space
public void doCauldronThing()
{
int a;
int b;
int c;
a=inventory.getID();
// First, is this a scroll we're gripping?
// If so, read it
if (a>69 && a<85)
{
msg1="You read the "+inventory.getName();
trade.doMsg(a, getXscr(ourEnt.x), getYscr(ourEnt.y));
s_message.play();
updateScores();
gameState=99;
}
// Maybe we're casting a spell?
// If so, stand back!
if (a>109)
{
int z;
// Extra health
if (a==110)
{
msg1="You feel much better!";
msg2="(Health +75)";
health+=75;
}
if (a==111)
{
msg1="You feel excellent!";
msg2="(Health +125)";
health+=125;
}
// These spells 'roam'
if (a>111 && a<120)
{
msg1="You cast the "+item.getName(a)+"!";
z=getXblock(ourEnt.x)+( (getYblock(ourEnt.y)) *200);
// Facing left
if (ourEnt.i==99)
{
curLev.curEnt[z].dirL=true;
curLev.curEnt[z].dirR=false;
}
else
{
curLev.curEnt[z].dirL=false;
curLev.curEnt[z].dirR=true;
}
curLev.curEnt[z].z=a;
curLev.curEnt[z].moves=true;
curLev.addToMvArray(z);
}
// Voidum Spell -- To next teleport stone.
if (a==120)
{
// Find next teleportation stone
int qx=xOrigin;
int qy=yOrigin;
while (curLev.curEnt[qx+(qy*200)].z!=49)
{
qx++;
if (qx>199)
{
qx=0;
qy++;
if (qy>135)
{
qy=1;
}
}
}
xOrigin=qx+1;
yOrigin=qy;
ourEnt.x=xOrigin*20;
ourEnt.y=yOrigin*20;
curLev.setUpWindow(xOrigin, yOrigin);
msg2="You feel strange.";
}
// Tranformation spells (to trees, to walls)
if (a==122 || a==123)
{
// Tree / wall
if (a==122) transform(7);
if (a==123) transform(32);
curLev.updateWindow(xOrigin, yOrigin);
msg2="Wow! Quite an effect!";
}
// Tranformation to bats! (Except evil wizard)
if (a==124)
{
for (int i=0; i<curLev.numInRm; i++)
{
ent aa=curLev.movInRm[i];
aa.z=87;
}
msg2="Everyone turns into bats!";
}
// ** To DO!
// = Create Temporal Fix Asi Tacil 121
// = Destroy Wall Frenis Vim 119
// = Destroy Tree Natum Tan 118
inventory.removeFromInv();
s_spell.play();
updateScores();
}
// Otherwise, are we putting into cauldron?
if (a>49 & a<70)
{
// Close to a cauldon?
if (nearCauldron)
{
// We have something selected
if (a>0)
{
s_pickUp.play();
msg1="You add the "+inventory.getName();
inventory.removeFromInv();
curLev.reDist(a);
b=ourCauldron.addItem(a);
// We made something!
if (b>0)
{
msg2="You made a "+item.getName(b)+"!";
c=curLev.getNearestSpace(getXblock(ourEnt.x), getYblock(ourEnt.y));
if (c>0)
{
s_spell.play();
curLev.curEnt[c].z=b;
curLev.curEnt[c].i=b;
drawEnt(curLev.curEnt[c]);
// We made a .... monster!
if (b>84 && b<102)
{
curLev.curEnt[c].dirL=true;
curLev.curEnt[c].dirU=true;
curLev.curEnt[c].moves=true;
curLev.addToMvArray(c);
}
}
}
else
{
msg2="Nothing happens!";
}
updateScores();
} // end if a>0
} // end if nrcauld
} // end if
}
// Display a one-time message to help players understand how to play
private void publicM(int a, int x, int y)
{
publicMsg[a]=true;
trade.doMsg(100+a, x, y);
s_message.play();
gameState=99;
}
// Code for gateway transformations
private void doGateway()
{
int x2=getXblock(ourEnt.x);
int y2=getYblock(ourEnt.y);
msg2=""+x2+" "+y2;
// Room 1 enter
if (x2==40 && y2==10)
{
xOrigin=155;
yOrigin=8;
}
// Room 2 enter
if (x2==5 && y2==22)
{
xOrigin=167;
yOrigin=8;
}
// Room 3 enter
if (x2==136 && y2==9)
{
xOrigin=179;
yOrigin=8;
}
// Room 4 enter
if (x2==97 && y2==10)
{
xOrigin=191;
yOrigin=8;
}
// Room 5 enter
if (x2==39 && y2==48)
{
xOrigin=155;
yOrigin=19;
}
// Room 6 enter
if (x2==72 && y2==49)
{
xOrigin=167;
yOrigin=19;
}
// Room 7 enter
if (x2==162 && y2==62)
{
xOrigin=179;
yOrigin=19;
}
// Room 8 enter
if (x2==30 && y2==71)
{
xOrigin=191;
yOrigin=19;
}
// Room 9 enter
if (x2==10 && y2==72)
{
xOrigin=155;
yOrigin=30;
}
// Room 10 enter
if (x2==86 && y2==78)
{
xOrigin=167;
yOrigin=30;
}
// Room 11 enter
if (x2==164 && y2==90)
{
xOrigin=179;
yOrigin=30;
}
// Room 12 enter
if (x2==148 && y2==105)
{
xOrigin=191;
yOrigin=30;
}
// Room1 exit
if (x2==155 && y2==7)
{
xOrigin=40;
yOrigin=11;
}
// Room2 exit
if (x2==167 && y2==7)
{
xOrigin=5;
yOrigin=23;
}
// Room3 exit
if (x2==179 && y2==7)
{
xOrigin=136;
yOrigin=10;
}
// Room4 exit
if (x2==191 && y2==7)
{
xOrigin=97;
yOrigin=11;
}
// Room5 exit
if (x2==155 && y2==18)
{
xOrigin=39;
yOrigin=49;
}
// Room6 exit
if (x2==167 && y2==18)
{
xOrigin=72;
yOrigin=50;
}
// Room7 exit
if (x2==179 && y2==18)
{
xOrigin=162;
yOrigin=63;
}
// Room8 exit
if (x2==191 && y2==18)
{
xOrigin=30;
yOrigin=72;
}
// Room9 exit
if (x2==155 && y2==29)
{
xOrigin=10;
yOrigin=73;
}
// Room10 exit
if (x2==167 && y2==29)
{
xOrigin=86;
yOrigin=79;
}
// Room11 exit
if (x2==179 && y2==29)
{
xOrigin=164;
yOrigin=91;
}
// Room12 exit
if (x2==191 && y2==29)
{
xOrigin=148;
yOrigin=106;
}
xOffset=20;
yOffset=20;
ourEnt.x=xOrigin*20;
ourEnt.y=yOrigin*20;
ourEnt.dirU=false;
ourEnt.dirD=false;
ourEnt.dirL=false;
ourEnt.dirR=false;
curLev.setUpWindow(xOrigin, yOrigin);
msg1="You go through the gateway.";
updateScores();
}
// Transforms an area around wizard into value of 'a'
public void transform(int a)
{
int x=getXblock(ourEnt.x);
int y=getYblock(ourEnt.y);
for (int y2=y-2; y2<y+2; y2++)
{
for (int x2=x-2; x2<x+2; x2++)
{
int k=x2+(y2*200);
if (curLev.curEnt[k].z<50 && curLev.curEnt[k].z>0) curLev.curEnt[k].z=a;
}
}
}
// 'BlowUp' an area around ent 'e'
public void blowUp(ent e)
{
int x=getXblock(e.x);
int y=getYblock(e.y);
for (int y2=y-2; y2<y+2; y2++)
{
for (int x2=x-2; x2<x+2; x2++)
{
int k=x2+(y2*200);
if (curLev.curEnt[k].z<50 && curLev.curEnt[k].z>0) curLev.curEnt[k].z=0;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?