?? thlalogic.java
字號:
import java.io.IOException;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;
public class ThLaLogic {
ThLaMapAr_Two tlma_two;
ThLaMapAr_Three tlma_three;
TiledLayer tlone,tltwo,tlthree;
LayerManager lmanager;
int tiledH,tiledW;
int spState,lastspState;
Image imgTiledThree,imgTiledTwo;
int spH,spW;
int monsW,monsH;
int wNum,hNum;
int spFlyW[],spFlyH[];
int gameoverbacktime;
int firstSp,twoSp;
int sp_mons1,sp_mons2;
int monsShowTime;
int mapNum,lastmapNum;
int repaintNum;
int mapchange;
Image imgsp;
Sprite sp;
Image two_imgNpcOne;
Sprite two_npcOne;
public ThLaLogic(){
if(tlma_two==null)
{
tlma_two=new ThLaMapAr_Two();
}
if(tlma_three==null)
{
tlma_three=new ThLaMapAr_Three();
}
try {
imgsp=Image.createImage("/res/sponerun1.png");
two_imgNpcOne=Image.createImage("/res/Two_Npc_One.png");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sp=new Sprite(imgsp,imgsp.getWidth()/2,imgsp.getHeight()/18);
two_npcOne=new Sprite(two_imgNpcOne,two_imgNpcOne.getWidth(),two_imgNpcOne.getHeight());
spState=ThLaKeyNum.SP_RIGHT;
spFlyW=new int[]{4,1570,1570,1156,740,900,547,1527,35,33,804,1570,1124,1220};
spFlyH=new int[]{20,26,280,187,340,216,340,693,1270,1562,210,1520,1520,1366};
Init();
firstSp=1;
}
public void Init()
{
mapNum=2;
tiledH=0;
tiledW=0;
spH=30;
spW=30;
wNum=0;
hNum=0;
spState=ThLaKeyNum.SP_RIGHT;
sp_mons1=25;
sp_mons2=100;
}
public TiledLayer CreateTiled()
{
try
{
imgTiledTwo=Image.createImage("/res/MapAr.png");
imgTiledThree=Image.createImage("/res/11.png");
}
catch (IOException e)
{
e.printStackTrace();
}
Image tempimage2=Image.createImage(imgTiledTwo, 0,0,32*2,32*20, Sprite.TRANS_NONE);
Image tempimage3=Image.createImage(imgTiledThree, 0,0,32,32*18, Sprite.TRANS_NONE);
if(mapNum==2)
{
tlone=new TiledLayer(50,100,tempimage2,32,32);
tltwo=new TiledLayer(50,100,tempimage2,32,32);
for(int i=0;i<100;i++)
for(int j=0;j<50;j++)
{
tlone.setCell(j,i,tlma_two.MapAr_map1[i][j]);
tltwo.setCell(j,i,tlma_two.MapAr_map0[i][j]);
}
}
else if(mapNum==3)
{
tlone=new TiledLayer(50,50,tempimage3,32,32);
tltwo=new TiledLayer(50,50,tempimage3,32,32);
tlthree=new TiledLayer(50,50,tempimage3,32,32);
for(int i=0;i<50;i++)
for(int j=0;j<50;j++)
{
tlone.setCell(j,i,tlma_three.mg1_map0[i][j]);
tltwo.setCell(j,i,tlma_three.mg1_map1[i][j]);
tlthree.setCell(j,i,tlma_three.mg1_map2[i][j]);
}
}
lmanager=new LayerManager();
return tlone;
}
public void drawMap(Graphics g)
{
if(mapNum==2&&repaintNum==0)
{
spH=40;spW=135;
tiledH=10;
tiledW=105;
CreateTiled();
repaintNum++;
}
else if(mapNum==3&&repaintNum==0)
{
tiledH=0;
tiledW=0;
spH=30;
spW=30;
CreateTiled();
repaintNum++;
}
lmanager.append(sp);
if(mapNum==3)lmanager.append(tlthree);
if(mapNum==2)
{
lmanager.append(two_npcOne);
}
else
{
lmanager.remove(two_npcOne);
}
two_npcOne.setPosition(280,30);
lmanager.append(tltwo);
lmanager.append(tlone);
sp.setPosition(spW, spH);
lmanager.paint(g,0,0);
lmanager.setViewWindow(tiledW, tiledH,g.getClipWidth(), g.getClipHeight());
}
public void SpStateAble(int keycode)
{
switch(keycode)
{
case ThLaKeyNum.KEY_UP:
case ThLaKeyNum.KEY_NUM2:
spState=ThLaKeyNum.SP_UP;
break;
case ThLaKeyNum.KEY_DOWN:
case ThLaKeyNum.KEY_NUM8:
spState=ThLaKeyNum.SP_DOWN;
break;
case ThLaKeyNum.KEY_LEFT:
case ThLaKeyNum.KEY_NUM4:
spState=ThLaKeyNum.SP_LEFT;
break;
case ThLaKeyNum.KEY_RIGHT:
case ThLaKeyNum.KEY_NUM6:
spState=ThLaKeyNum.SP_RIGHT;
break;
default:
spState=ThLaKeyNum.SP_STAND;
break;
}
}
public void SpFrame(int spState)
{
two_npcOne.setFrameSequence(new int[]{0});
switch(spState)
{
case ThLaKeyNum.SP_UP:
if(lastspState!=spState)
{
sp.setFrameSequence(new int[]{0,2,4,6,8,10,12,14,16 });
lastspState=spState;
}
else sp.nextFrame();
break;
case ThLaKeyNum.SP_DOWN:
if(lastspState!=spState)
{
sp.setFrameSequence(new int[]{1,3,5,7,9,11,13,15,17 });
lastspState=spState;
}
else sp.nextFrame();
break;
case ThLaKeyNum.SP_LEFT:
if(lastspState!=spState)
{
sp.setFrameSequence(new int[]{18,20,22,24,26,28,30,32,34});
lastspState=spState;
}
else sp.nextFrame();
break;
case ThLaKeyNum.SP_RIGHT:
if(lastspState!=spState)
{
sp.setFrameSequence(new int[]{19,21,23,25,27,29,31,33,35});
lastspState=spState;
}
else sp.nextFrame();
break;
case ThLaKeyNum.SP_STAND:
if(lastspState==ThLaKeyNum.SP_UP)sp.setFrameSequence(new int[]{0});
else if(lastspState==ThLaKeyNum.SP_DOWN)sp.setFrameSequence(new int[]{1});
else if(lastspState==ThLaKeyNum.SP_LEFT)sp.setFrameSequence(new int[]{18});
else if(lastspState==ThLaKeyNum.SP_RIGHT){sp.setFrameSequence(new int[]{19});}
lastspState=spState;
break;
default:
break;
}
}
public void sp_mapChange()
{
if(sp.collidesWith(two_npcOne, true)&&mapNum==2)
{
ThLaCV.mnNum=ThLaKeyNum.MAPA;
}
}
public void mapT_T()
{
repaintNum=0;
if(mapNum==2)
{
mapNum=3;
}
else mapNum=2;
if(mapchange==0)
{
mapNum=3;
mapchange=10;
}
}
public void KeyAll(int keycode)
{
if(monsShowTime>100)
{
ThLaCV.mnNum=ThLaKeyNum.ACTION;
}
else {
ThLaCV.mnNum=ThLaKeyNum.START;
}
chackCillition();
SpStateAble(keycode);
SpFrame(spState);
//KeyMap(keycode);
if(sp.collidesWith(tltwo, true))
{
if(lastspState==ThLaKeyNum.SP_UP){spH+=2;}
else if(lastspState==ThLaKeyNum.SP_DOWN){spH-=2;}
else if(lastspState==ThLaKeyNum.SP_LEFT){spW+=2;}
else if(lastspState==ThLaKeyNum.SP_RIGHT){spW-=2;}
}
else KeyMap(keycode);
KeyMapAble();
}
public void KeyMap(int keycode)
{
if(keycode==ThLaKeyNum.KEY_UP||keycode==ThLaKeyNum.KEY_NUM2)
{
spH-=2;
if(spH<tiledH+100)
tiledH-=2;
}
if(keycode==ThLaKeyNum.KEY_DOWN||keycode==ThLaKeyNum.KEY_NUM8)
{
spH+=2;
if(spH>tiledH+100)
tiledH+=2;
}
if(keycode==ThLaKeyNum.KEY_LEFT||keycode==ThLaKeyNum.KEY_NUM4)
{
spW-=2;
if(spW<tiledW+100)
tiledW-=2;
}
if(keycode==ThLaKeyNum.KEY_RIGHT||keycode==ThLaKeyNum.KEY_NUM6)
{
spW+=2;
if(spW>tiledW+100)
tiledW+=2;
}
}
public void KeyMapAble()
{
if(tiledH<0)tiledH=0;
else if(tiledH>=1400)tiledH=1386;
if(tiledW<0)tiledW=0;
else if(tiledW>=1380)tiledW=1380;
if(spW<-6)spW+=5;
if(spH<-16)spH+=5;
if(spW>1582)spW-=5;
if(spH>1566)spH-=5;
}
// public void Spfly(int keycode)
// {
//
// if(wNum%13==0)wNum=0;
// if(hNum%13==0)hNum=0;
//
// if(tlsp.sp.collidesWith(tlthree, true)&&keycode==ThLaKeyNum.KEY_NUM5)
// {
// spW=spFlyW[wNum];
// spH=spFlyH[hNum];
// tiledW=spW-88;
// tiledH=spH-100;
// wNum++;
// hNum++;
// }
// }
public void chackCillition()
{
sp.defineCollisionRectangle(0, 29, sp.getWidth(), 3);
// if(sp.collidesWith(tltwo, true))
// {
// if(lastspState==ThLaKeyNum.SP_UP){spH+=3;}
// else if(lastspState==ThLaKeyNum.SP_DOWN){spH-=3;}
// else if(lastspState==ThLaKeyNum.SP_LEFT){spW+=3;}
// else if(lastspState==ThLaKeyNum.SP_RIGHT){spW-=3;}
// }
}
public void Thejq_one(Graphics g)
{
g.setColor(0xffff00);
g.fillRect(0, 108, 176, 100);
g.setColor(0x000000);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD|Font.STYLE_PLAIN, Font.SIZE_LARGE)); /**設置字體屬性*/
g.drawString("罪人:", 10, 140, Graphics.TOP|Graphics.LEFT);
g.drawString("你的行為已經惹怒我了", 10, 155, Graphics.TOP|Graphics.LEFT);
g.drawString("我將把你送進迷失之地", 10, 170, Graphics.TOP|Graphics.LEFT);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -