?? mygamecanvas.java
字號:
try {
// logic
// res
System.gc();
//
nGameScore = 0;
imageUp = Image.createImage("/res/up.png");
imageDown = Image.createImage("/res/down.png");
imageLeft = Image.createImage("/res/left.png");
imageRight = Image.createImage("/res/right.png");
isMenuInGameWorked = false;
isGameWin = false;
nPorintStrrMenuInGame = 0;
//
// DataInputStream dis = new DataInputStream(getClass()
// .getResourceAsStream("/res/tiles.png"));
// int len = dis.available();
// byte[] bytes = new byte[len];
// for (int i = 0; i < len; i++) {
// bytes[i] = dis.readByte();
// }
// dis.close();
// imageMap = Image.createImage("/res/tiles.png");
// imageMap = DirectUtils.createImage(bytes, 0, bytes.length);
// myImage1d = new MyImage[imageMap.getWidth()
// / Consts.SN_TILE_WIDTH * imageMap.getHeight()
// / Consts.SN_TILE_HEIGHT];
//
// for (int i = 0; i < myImage1d.length; i++) {
// myImage1d[i] = new MyImage(imageMap, i % 5, i / 5);
// }
imageMap = Image.createImage("/res/tiles.png");
// imageTiles = new Image[128];
// for (int i = 0; i < imageTiles.length; i++) {
// imageTiles[i] = Image.createImage(16, 16);
// Graphics g = imageTiles[i].getGraphics();
// blt(g, imageTemp, ( ( (i)) % 15) * Consts.SN_TILE_WIDTH,
// ( (i) / 8) * Consts.SN_TILE_HEIGHT,
// Consts.SN_TILE_WIDTH, Consts.SN_TILE_HEIGHT, 0, 0);
// }
// imageTemp = null;
// 地圖
if (nMapId == 3 || nMapId == 6 || nMapId == 9) {
snsTiles = getTiles("/res/boss.v");
} else {
snsTiles = getTiles("/res/m_" + nMapId + ".v");
}
snTilesWidthNum = snsTiles[0].length;
snTilesHeightNum = snsTiles.length;
// initTilesOptions();
if (nMapId == 1) {
// isScriptWorking = true;
// isStoryModeWorking = true;
// isCommandWorked = true;
isScriptWorking = false;
isStoryModeWorking = false;
isCommandWorked = false;
} else {
isScriptWorking = false;
isStoryModeWorking = false;
isCommandWorked = false;
}
snTilesWidthNum = snsTiles[0].length;
snTilesHeightNum = snsTiles.length;
snTilesWidthNumInScreen = Consts.SN_WINDOW_WIDTH
/ Consts.SN_TILE_WIDTH;
snTilesHeightNumInScreeen = Consts.SN_WINDOW_HEIGHT
/ Consts.SN_TILE_HEIGHT;
snMapAreaWidthInScreen = snTilesWidthNumInScreen
* Consts.SN_TILE_WIDTH;
snMapAreaHeightInScreen = snTilesHeightNumInScreeen
* Consts.SN_TILE_HEIGHT;
snWindowX = 0;
snWindowY = 0;
snMapWidth = snTilesWidthNum * Consts.SN_TILE_WIDTH;
snMapHeight = snTilesHeightNum * Consts.SN_TILE_HEIGHT;
//
//
imageSps = Image.createImage("/res/0.png");
imageBox = Image.createImage("/res/box.png");
imageSaving = Image.createImage("/res/bbox.png");
imageZZ = Image.createImage("/res/zz.png");
imageMouse = Image.createImage("/res/mouse.png");
imageBall = Image.createImage("/res/ball.png");
imageDoor = Image.createImage("/res/door.png");
imageBomb = Image.createImage("/res/bomb.png");
imageFire = Image.createImage("/res/f.png");
imageSuc = Image.createImage("/res/suc.png");
imageFailuer = Image.createImage("/res/fail.png");
imageX = Image.createImage("/res/x.png");
imageCi = Image.createImage("/res/ci.png");
imageBf = Image.createImage("/res/bf.png");
imageWugong = Image.createImage("/res/wugong.png");
//
isScrollMapLeft = false;
isScrollMapRight = false;
// isScrollMapMid = false;
// isScrollMapBottom = false;
//
vecticUnits = new Vector(0, 1);
//
//
// animBullet = new Anim();
// animBullet.init(this, imageBall, "/res/sps/ball.a");
animLisa = new Anim();
animLisa.init(this, imageSps, "/res/sps/lisa.a");
animSaving = new Anim();
animSaving.init(this, imageSaving, "/res/sps/bbox.a");
animZZ = new Anim();
animZZ.init(this, imageZZ, "/res/sps/zz.a");
animZZ.isStop = false;
animZZ.isLoop = true;
//
animMouse = new Anim();
animMouse.init(this, imageMouse, "/res/sps/mouse.a");
animMouse.isStop = false;
animMouse.isLoop = true;
//
//
animHead = new Anim();
animHead.init(this, imageWugong, "/res/sps/head.a");
animHead.isStop = false;
animHead.isLoop = true;
animBody = new Anim();
animBody.init(this, imageWugong, "/res/sps/body.a");
animHead.isStop = false;
animHead.isLoop = true;
animEnd = new Anim();
animEnd.init(this, imageWugong, "/res/sps/end.a");
animEnd.isStop = false;
animEnd.isLoop = true;
//
//
animBf = new Anim();
animBf.init(this, imageBf, "/res/sps/bf.a");
animBf.isStop = false;
animBf.isLoop = true;
//
animBomb = new Anim();
animBomb.init(this, imageBomb, "/res/sps/bomb.a");
animBomb.isStop = false;
animBomb.isLoop = true;
//
animFire = new Anim();
animFire.init(this, imageFire, "/res/f.a");
animFire.isStop = false;
animFire.isLoop = false;
//
initParamsForNpc();
//
initObjects();
// hahah
initStory();
//
initCamera();
} catch (Exception ex) {
ex.printStackTrace();
}
}
break;
}
sbState = sbStateToLoad;
}
// public void initTilesOptions() {
// if (snsTiles != null) {
// sisTilesNull = new boolean[snsTiles.length][snsTiles[0].length];
// for (int i = 0; i < snsTiles.length; i++) {
// for (int j = 0; j < snsTiles[i].length; j++) {
// if (Consts.getTileVar(snsTiles[i][j]) ==
// Consts.SB_TILE_NULL) {
// sisTilesNull[i][j] = true;
// }
// }
// }
// }
// }
public void initParamsForNpc() {
isKeyReponseMenu = false;
bGameResult = 0;
nPowerCMax = 1;
nBombNumCMax = 1;
nRainOrSnow = 0;
switch (nMapId) {
case 1: {
nPowerCMax = 1;
nBombNumCMax = 1;
}
break;
case 2: {
nPowerCMax = 1;
nBombNumCMax = 1;
nRainOrSnow = 1;
}
break;
case 3: {
nPowerCMax = 1;
nBombNumCMax = 2;
}
break;
case 4: {
nPowerCMax = 2;
nBombNumCMax = 2;
nRainOrSnow = 1;
}
break;
case 5: {
nPowerCMax = 2;
nBombNumCMax = 2;
}
break;
case 6: {
nPowerCMax = 2;
nBombNumCMax = 2;
}
break;
case 7: {
nPowerCMax = 3;
nBombNumCMax = 3;
nRainOrSnow = 1;
}
break;
case 8: {
nPowerCMax = 3;
nBombNumCMax = 3;
}
break;
case 9: {
nPowerCMax = 3;
nBombNumCMax = 3;
}
break;
}
}
public void initObjects() {
//
vecticUnits = new Vector(0, 1);
//
switch (nMapId) {
case 1: {
addLisa(3, 14, Canvas.DOWN, 3);
//
addNoramOgre(11, 6, Canvas.LEFT);
addNoramOgre(6, 8, (byte) Canvas.DOWN);
addNoramOgre(8, 9, (byte) Canvas.DOWN);
addNoramOgre(1, 1, (byte) Canvas.RIGHT);
addNoramOgre(14, 1, (byte) Canvas.LEFT);
addBox(4, 6);
// 木箱,
addSaving(2, 13);
}
break;
case 2: {
addLisa(1, 1, Canvas.DOWN, 3);
// OGRE
addNoramOgre(6, 4, (byte) Canvas.UP);
addNoramOgre(9, 1, (byte) Canvas.DOWN);
addNoramOgre(13, 2, (byte) Canvas.LEFT);
addNoramOgre(15, 2, (byte) Canvas.RIGHT);
addNoramOgre(5, 8, (byte) Canvas.RIGHT);
addNoramOgre(1, 18, (byte) Canvas.RIGHT);
addNoramOgre(18, 18, (byte) Canvas.RIGHT);
// SAVING
addSaving(6, 1);
addSaving(18, 1);
//
addZhen(9, 4);
addZhen(9, 10);
addZhen(10, 11);
addZhen(9, 12);
}
break;
case 4: {
addLisa(1, 1, Canvas.DOWN, 3);
// OGRE
addNoramOgre(3, 3, (byte) Canvas.DOWN);
addNoramOgre(6, 6, (byte) Canvas.UP);
addNoramOgre(10, 1, (byte) Canvas.RIGHT);
addNoramOgre(18, 1, (byte) Canvas.LEFT);
addNoramOgre(11, 6, (byte) Canvas.RIGHT);
addNoramOgre(17, 4, (byte) Canvas.LEFT);
addNoramOgre(12, 12, (byte) Canvas.RIGHT);
addNoramOgre(12, 14, (byte) Canvas.RIGHT);
addNoramOgre(3, 13, (byte) Canvas.RIGHT);
addNoramOgre(3, 15, (byte) Canvas.DOWN);
// SAVING
addSaving(8, 1);
addSaving(13, 8);
// ZHEN
addZhen(8, 8);
addZhen(10, 8);
addZhen(8, 10);
addZhen(10, 10);
addZhen(18, 12);
addZhen(18, 14);
}
break;
case 5: {
//
addLisa(10, 10, Canvas.DOWN, 3);
// ogre
addNoramOgre(2, 10, Canvas.RIGHT);
addNoramOgre(18, 10, Canvas.LEFT);
addNoramOgre(10, 2, Canvas.DOWN);
addNoramOgre(10, 18, Canvas.UP);
// ogre
addSuperOgre(1, 5, Canvas.DOWN);
addSuperOgre(18, 1, Canvas.RIGHT);
addSuperOgre(2, 17, Canvas.RIGHT);
addSuperOgre(1, 18, Canvas.DOWN);
addSuperOgre(16, 17, Canvas.RIGHT);
addSuperOgre(19, 19, Canvas.UP);
// saving
addSaving(1, 1);
addSaving(19, 9);
// zhen
addZhen(9, 8);
addZhen(11, 8);
addZhen(7, 10);
addZhen(9, 10);
addZhen(11, 10);
addZhen(13, 10);
addZhen(9, 12);
addZhen(11, 12);
}
break;
case 7: {
// lisa
addLisa(9, 8, Canvas.DOWN, 3);
// normal
addNoramOgre(9, 16, Canvas.DOWN);
addNoramOgre(9, 16, Canvas.DOWN);
// ogre
addSuperOgre(9, 12, Canvas.UP);
addSuperOgre(3, 5, Canvas.DOWN);
addSuperOgre(16, 5, Canvas.DOWN);
addSuperOgre(5, 17, Canvas.RIGHT);
addSuperOgre(13, 17, Canvas.RIGHT);
// saving
addSaving(1, 1);
addSaving(18, 1);
// zhen
addZhen(6, 9);
addZhen(13, 9);
addZhen(6, 11);
addZhen(13, 11);
}
break;
case 8: {
//
// lisa
addLisa(1, 1, Canvas.DOWN, 3);
// normal
addNoramOgre(7, 8, Canvas.DOWN);
addNoramOgre(1, 14, Canvas.RIGHT);
addNoramOgre(13, 20, Canvas.DOWN);
// ogre
addSuperOgre(16, 11, Canvas.LEFT);
addSuperOgre(20, 2, Canvas.LEFT);
addSuperOgre(21, 3, Canvas.DOWN);
addSuperOgre(27, 10, Canvas.UP);
addSuperOgre(1, 27, Canvas.UP);
addSuperOgre(7, 20, Canvas.DOWN);
addSuperOgre(20, 14, Canvas.RIGHT);
// saving
// zhen
addZhen(27, 14);
addZhen(27, 18);
addZhen(27, 22);
addZhen(27, 24);
}
break;
case 3: {
addLisa(5, 1, Canvas.DOWN, 3);
//
addBossSnake(1, 1, 0, Canvas.UP);
addBossSnake(1, 2, 1, Canvas.UP);
addBossSnake(1, 3, 1, Canvas.UP);
addBossSnake(1, 4, 2, Canvas.UP);
}
break;
case 9: {
addLisa(5, 1, Canvas.DOWN, 5);
addBossSnake(1, 1, 0, Canvas.UP);
addBossSnake(1, 2, 1, Canvas.UP);
addBossSnake(1, 3, 1, Canvas.UP);
addBossSnake(1, 4, 1, Canvas.UP);
addBossSnake(1, 5, 1, Canvas.UP);
addBossSnake(1, 6, 1, Canvas.UP);
addBossSnake(2, 6, 1, Canvas.LEFT);
addBossSnake(3, 6, 1, Canvas.LEFT);
addBossSnake(4, 6, 1, Canvas.LEFT);
addBossSnake(5, 6, 2, Canvas.LEFT);
//
}
break;
case 6: {
// npcLisa = new NPC();
// npcLisa.initBasic("Lisa", 5, 1, (byte) Canvas.DOWN, 4, false,
// true,
// 0);
// npcLisa.initParam(10, 10, 0, 10, 10, 8, 2, 4);
// npcLisa.nLevel = 1;
// npcLisa.initAnim(animLisa);
addLisa(5, 1, Canvas.DOWN, 4);
cpc2 = new CPC((byte) CPC.B_VAR_BOSS_UFO);
cpc2.initBasic("b1", 1, 4, (byte) Canvas.UP, 2, true, true, 0);
cpc2.initParam(8, 2, 2, 8, 2, 4, 2, 2);
cpc2.initAnim(animBf);
cpc2.anim.isLoop = true;
cpc2.anim.isStop = false;
vecticUnits.addElement(cpc2);
}
break;
}
// snMapX = 0;
// snMapY = 0;
//
// nRainOrSnow = 0; // rain
nRainOrSnowXY = new int[20 + getRandomInt(0, 5, 0)][];
for (int i = 0; i < nRainOrSnowXY.length; i++) {
nRainOrSnowXY[i] = new int[3];
nRainOrSnowXY[i][0] = getRandomInt(0, Consts.SN_SCREEN_WIDTH, i);
nRainOrSnowXY[i][1] = getRandomInt(0, Consts.SN_SCREEN_HEIGHT,
i << 2);
// state;)
nRainOrSnowXY[i][2] = getRandomInt(0, 3, i << 2);
}
// :)
// snMapX = 0;
// snMapY = 0;
// npcLisa.nXInScreen = npcLisa.nX - MyGameCanvas.snMapX;
// npcLisa.nYInScreen = npcLisa.nY - MyGameCanvas.snMapY;
}
public void addLisa(int x, int y, int dir, int hpMax) {
npcLisa = new NPC();
npcLisa.initBasic("Lisa", x, y, (byte) dir, 4, false, true, 0);
npcLisa.initParam(hpMax, 10, 0, hpMax, 10, 8, 2, 4);
npcLisa.nLevel = 1;
npcLisa.initAnim(animLisa);
npcLisa.anim.changeAction(npcLisa.bDirection);
}
public void addNoramOgre(int x, int y, int dir) {
cpc2 = new CPC((byte) CPC.B_VAR_WORM);
cpc2.initBasic("WORM", x, y, (byte) dir, 2, true, true, 0);
cpc2.initParam(2, 2, 2, 2, 2, 4, 2, 2);
cpc2.initAnim(animMouse.copy());
vecticUnits.addElement(cpc2);
cpc2 = null;
}
public void addSuperOgre(int x, int y, int dir) {
cpc2 = new CPC((byte) CPC.B_VAR_OGRE);
cpc2.initBasic("OGRE", x, y, (byte) dir, 20, true, true, 0);
cpc2.initParam(2, 2, 2, 2, 2, 4, 2, 2);
cpc2.initAnim(animZZ.copy());
vecticUnits.addElement(cpc2);
cpc2 = null;
}
public void addSaving(int x, int y) {
cpc2 = new CPC((byte) CPC.B_VAR_SAVING);
cpc2.initBasic("baobei", x, y, (byte) Canvas.UP, 0, false, true, 0);
cpc2.initParam(4, 6, 50, 50, 50, 50, 2, 2);
cpc2.initAnim(animSaving.copy());
vecticUnits.addElement(cpc2);
cpc2 = null;
}
public void addZhen(int x, int y) {
cpc2 = new CPC((byte) CPC.B_VAR_ZHEN);
cpc2.initBasic("zhen", x, y, (byte) Canvas.UP, 2, true, true, 0);
cpc2.initParam(2, 2, 2, 2, 2, 4, 2, 2);
cpc2.initAnim(null);
vecticUnits.addElement(cpc2);
cpc2.nTimerMax = 30;
cpc2 = null;
}
public void addBox(int x, int y) {
cpc2 = new CPC((byte) CPC.B_VAR_BOX);
cpc2.initBasic("Box", x, y, (byte) Canvas.UP, 0, false, true, 0);
cpc2.initParam(4, 6, 50, 50, 50, 50, 2, 2);
cpc2.initAnim(null);
vecticUnits.addElement(cpc2);
cpc2 = null;
}
public void addBossSnake(int x, int y, int var, int dir) {
// var 0: 頭,身,尾
cpc2 = new CPC((byte) CPC.B_VAR_BOSS_SNAKE);
cpc2.initBasic("b1", x, y, (byte) dir, 2, true, true, 0);
cpc2.initParam(4, 2, 2, 4, 2, 4, 2, 2);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -