?? rpgcanvas.java
字號:
g.setColor(0, 0, 100);
g.fillRect(0, getHeight() - 57, getWidth(), 57);
g.drawImage(load.hero, 0, getHeight() - 57, 0);
g.setColor(255, 255, 255);
// private String roleWord=" 選招: 星星燎燃 烈火濺射 深海狂嘯";
g.drawString("選招: ", 50, getHeight() - 57, 0);
g.drawString(" 星星燎燃", 70, getHeight() - 40, 0);
g.drawString(" 烈火濺射", 70, getHeight() - 30, 0);
g.drawString(" 深海狂嘯", 70, getHeight() - 20, 0);
g.setColor(255, 255, 0);
// g.fillArc(52, attackSelecty, 5, 5, 0, 360);
g.drawImage(load.selectIcon, 50, attackSelecty, g.TOP|g.LEFT);
isRoleAttack = true;
}
if (roleBeat) { //人物的攻擊畫面
g.setColor(255, 255, 255);
g.fillRect(0, screenheight - 57, screenheight, 57);
g.setColor(0, 0, 100);
g.fillRect(0, getHeight() - 57, getWidth(), 57);
g.drawImage(load.hero, 0, getHeight() - 57, 0);
g.setColor(255, 255, 255);
g.drawString("看招: " + roleWord, 50, getHeight() - 30, 0);
System.out.println(roleWord);
g.setClip((screenwidth - attackWidth) >> 1,
(screenheight - attackHeight) >> 1, attackWidth,
attackHeight);
//在屏幕中央顯示招數(shù)動畫
g.drawImage(load.attack[tempNum], screenwidth / 2 - attackWidth
* i, screenheight >> 1, g.HCENTER | g.VCENTER);
g.setClip(0, 0, screenwidth, screenheight);
if (i == 4) { //5幅動畫播放完后
i = -1;
roleBeat = false;
isChoose = false;
inputmode = 0;
for(int j = 0 ; j < 6; j++)
g.drawString("獲得補血草", screenwidth>>1, screenheight>>1, g.TOP|g.LEFT);
if (!warEnd) { //當(dāng)是boss的時候,根據(jù)人物等級不同,攻擊力野不相同
if (mroleProperty[0] <= 5)
bossBlood -= 5;
else if (mroleProperty[0] >= 11)
bossBlood -= 10;
else
bossBlood -= mroleProperty[0];
if (bossBlood >= 0) {
isBossAttack = true;
tempNum = getrand(4);
switch (tempNum) {
case 0:
soldierWord = "看招:一擊即中";
blood = 4;
attackWidth = 29;
attackHeight = 32;
break;
case 1:
soldierWord = "看招:所向披靡";
attackWidth = 101;
attackHeight = 76;
blood = 3;
break;
case 2:
soldierWord = "看招:怒海狂潮";
blood = 5;
attackWidth = 80;
attackHeight = 80;
break;
case 3:
soldierWord = "看招:天翻地覆";
blood = 10;
attackWidth = 78;
attackHeight = 98;
break;
default:
break;
}
} else
isBossDead = true;
}
}
i++;
}
//當(dāng)人物血氣小于等于0時,游戲結(jié)束界面
if (roleBloodHeight <= 0) {
g.setColor(0);
g.drawString("Game Over!!", screenwidth >> 1,
(screenheight >> 1) - 20, g.TOP | g.HCENTER);
g.drawString("You Died In the War!!", screenwidth >> 1,
screenheight >> 1, g.TOP | g.HCENTER);
t = null;
addCommand(exitGame);
}
//boss對話
if (isProperty) {
// soldierWord = "我是守護神壇的使者,只有通過我這一關(guān),你才能繼續(xù)前進。";
g.setColor(0, 0, 100);
g.fillRect(0, screenheight-57, getWidth(), 57);
g.drawImage(pImage, 0,screenheight-57, 0);
Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_MEDIUM);
g.setFont(f);
g.setColor(255, 255, 255);
if (pMessage.length() <= getWidth() / 17) {
g.drawString(pMessage, 57, screenheight-57, 0);
} else {
int length = pMessage.length();
int len = getWidth() / 17;
int y = screenheight-57;
int offset = 0;
while (length > 0) {
g.drawSubstring(pMessage, offset, len, 57, y, 0);
y += 17;
offset += getWidth() / 17;
length -= getWidth() / 17;
if (length > getWidth() / 17) {
len = getWidth() / 17;
} else {
len = length;
}
}
}
g.setColor(255, 255, 255);
g.drawString("Push FIRE", screenwidth, screenheight, g.BOTTOM | g.RIGHT);
}
//boss攻擊畫面
if (isBossAttack) {
switch (tempNum) {
case 0:
soldierWord = "看招:一擊即中";
blood = 4;
attackWidth = 29;
attackHeight = 32;
break;
case 1:
soldierWord = "看招:所向披靡";
attackWidth = 101;
attackHeight = 76;
blood = 3;
break;
case 2:
soldierWord = "看招:怒海狂潮";
blood = 5;
attackWidth = 80;
attackHeight = 80;
break;
case 3:
soldierWord = "看招:天翻地覆";
blood = 10;
attackWidth = 78;
attackHeight = 98;
break;
default:
break;
}
g.setColor(255, 255, 255);
g.fillRect(0, 0, screenwidth, screenheight);
g.setColor(0, 0, 100);
g.fillRect(0, 0, getWidth(), 57);
g.drawImage(load.bossface, 0, 0, 0);
Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_MEDIUM);
g.setFont(f);
g.setColor(255, 255, 255);
g.drawString(soldierWord, 50, 0, 0);
g.setClip((screenwidth - attackWidth) >> 1,
(screenheight - attackHeight) >> 1, attackWidth,
attackHeight);
g.drawImage(load.attack[tempNum], screenwidth / 2 - attackWidth
* i, screenheight >> 1, g.HCENTER | g.VCENTER);
g.setClip(0, 0, screenwidth, screenheight);
g.setColor(0);
g.drawRoundRect(0, 60, 30, 5, 4, 2);
g.setColor(0xB84909);
g.fillRoundRect(0, 60, bossBlood, 5, 4, 2);
g.setColor(255);
if (i == 6) {
isBossAttack = false;
// isBossDead = true;
load.property[1].setVisible(false);
isBoss = false;
// roleAttack = true;
// inputmode = 3;
isChoose = true ;
inputmode = 1;
choose1 = "普通攻擊";
choose2 = "魔法攻擊";
isSelectAttack = true;
i = -1;
roleBloodHeight -= blood;
if (roleBloodHeight <= 0)
warEnd = true;
}
i++;
}
}
//找到勝利旗幟時,游戲成功結(jié)束界面
else if (gameOver) {
t = null;
g.drawString("You Win The Game!!", screenwidth >> 1,
screenheight >> 1, g.TOP | g.HCENTER);
addCommand(exitGame);
}
}
public void nextmessage() {
if (vectormessage.size() > 0 && vectorpicture.size() > 0) {
curpicture = (Image) vectorpicture.elementAt(0);
curmessage = (String) vectormessage.elementAt(0);
}
if (Math.abs(tempx - mrole.x) > 4 || Math.abs(tempy - mrole.y) > 4) {
curmessage = null;
vectormessage.removeAllElements();
vectorpicture.removeAllElements();
showyesorno = false;
iscollide = false;
}
}
//人物屬性介紹
public void drawProperty() {
g.drawString("等級", 0, 0, g.TOP | g.LEFT);
g.drawString("寶物", 30, 0, g.TOP | g.LEFT);
g.drawString("任務(wù)", 60, 0, g.TOP | g.LEFT);
g.drawString("血氣", 90, 0, g.TOP | g.LEFT);
g.drawString("黃金", 130, 0, g.TOP | g.LEFT);
for (int i = 0; i < 3; i++)
g.drawString(Integer.toString(mroleProperty[i]), i * 30, 20, g.TOP
| g.LEFT);
g.setColor(0);
g.drawRoundRect(90, 25, 40, 5, 4, 2);
g.setColor(0xB84909);
g.fillRoundRect(90, 25, roleBloodHeight, 5, 4, 2);
g.setColor(255, 255, 255);
g.drawString(Integer.toString(mroleProperty[4]), 140, 20, g.TOP
| g.LEFT);
}
// 繪制對話函數(shù)
public void drawmessage() {
if (ismessage) {
// System.out.println("in drawmessage");
if (curmessage != null) {
// /////*********************/////////
g.setColor(0, 0, 100);
g.fillRect(0, getHeight() - 40, getWidth(), 40);
// //////////****************////////////
g.drawImage(curpicture, 0, getHeight() - 40, 0);
Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_MEDIUM);
g.setFont(f);
g.setColor(255, 255, 255);
if (curmessage.length() <= getWidth() / 12) {
g.drawString(curmessage, 37, getHeight() - 40, 0);
} else {
int length = curmessage.length();
int len = getWidth() / 12;
int y = getHeight() - 40;
int offset = 0;
while (length > 0) {
g.drawSubstring(curmessage, offset, len, 37, y, 0);
y += 12;
offset += getWidth() / 12;
length -= getWidth() / 12;
if (length > getWidth() / 12) {
len = getWidth() / 12;
} else {
len = length;
}
}
}
Font ff = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_SMALL);
g.setFont(ff);
g.setColor(255, 255, 255);
g.drawString("Push FIRE", screenwidth, screenheight, g.BOTTOM
| g.RIGHT);
}
}
}
// 碰撞檢測
void collidetest() {
// mrole.setPosition(mrole.roomx, mrole.roomy);
if (scene == 2) { //場景二
mrole.setPosition(mrole.roomx, mrole.roomy);
//與返回場景一的門口碰撞
if (mrole.collidesWith(load.maproom1layer2, false)) {
scene = 1;
inputmode = 0;
mrole.x = mrole.x;
mrole.y = mrole.y + 4;
}
//與家具碰撞
else if (mrole.collidesWith(load.maproom1layer1, true)) {
mrole.unmoveroom();
}
if (isBossDead && (mroleProperty[0] >= 2)) //與紅旗碰撞,代表游戲的勝利
if (mrole.collidesWith(load.property[4], true))
gameOver = true;
}
//場景一
else if (scene == 1) {
mrole.setPosition(mrole.x, mrole.y);
for (int i = 0; i < load.property.length; i++) {
if(i == 4)continue;
Property ptemp = load.property[i];
if (mrole.collidesWith(ptemp, true)) {
isProperty = true;
// inputmode = 3;
screenunmove();
mrole.unmove();
switch (i) {
// 與貓碰撞
case 0:
mrole.setPosition(mrole.x, mrole.y);
pMessage = "喵,喵~~~~~";
pImage = load.cat;
if (mainroleanswer)
catchcat = true;
else
catchcat = false;
// else catchcat = false;
// 與boss碰撞
break;
case 1:
isBoss = true;
pMessage = "我是守護神壇的使者,只有通過我這一關(guān),你才能繼續(xù)前進。";
pImage = load.bossface;
break;
// 與食物碰撞
case 2:
isFood = true;
pMessage = "食物:增加3點血氣";
pImage = load.food;
break;
// 與寶劍碰撞
case 3:
isSword = true;
pMessage = "寶劍:增加英雄攻擊力";
pImage = load.sword;
break;
// 與黃金碰撞
case 5:
pMessage = "黃金:增加黃金數(shù)";
pImage = load.gold;
isGold = true;
break;
default:
break;
}
}
}
//與農(nóng)場建筑物碰撞
if (mrole.collidesWith(load.imgmap1, true)) {
screenunmove();
mrole.unmove();
mrole.setPosition(mrole.x, mrole.y);
}
//與商店碰撞
else if (mrole.collidesWith(load.hourse, true)) {
screenunmove();
mrole.unmove();
mrole.setPosition(mrole.x, mrole.y);
}
//與npc碰撞
// for (int i = 0; i < load.vectornpc.size(); i++) {
// Npc npc = (Npc) load.vectornpc.elementAt(i);
for (int i = 0; i < load.npc.length; i++) {
Npc npc = (Npc) load.npc[i];
if (mrole.collidesWith(npc, true)) {
tempx = mrole.x;
tempy = mrole.y;
mrole.unmove();
screenunmove();
mrole.setPosition(mrole.x, mrole.y);
ismessage = true;
if (npc.name == "老人" && catchcat2 == true) {
String temp2 = npc.name + ":" + npc.message2;// 加入npc對話
vectormessage.addElement(temp2);
Image tempimage2 = npc.img;
vectorpicture.addElement(tempimage2);
missionmessage = "任務(wù)完成";
if (firstTouch) {
mroleProperty[2]++;
firstTouch = false;
}
} else if (npc.name == "老人") {
String temp = npc.name + ":" + npc.message1;// 加入npc對話
vectormessage.addElement(temp);
Image tempimage = npc.img;
vectorpicture.addElement(tempimage);
iscollide = true;
} else if (npc.name == "戰(zhàn)士" || npc.name == "戰(zhàn)士2"
|| npc.name == "戰(zhàn)士3") {
// isChoose = true;
isSoldier = true;
// inputmode = 1;
String temp = npc.name + ":" + npc.message1;// 加入npc對話
vectormessage.addElement(temp);
Image tempimage = npc.img;
vectorpicture.addElement(tempimage);
if (npc.name == "戰(zhàn)士")
number = 2;
else if (npc.name == "戰(zhàn)士2")
number = 3;
else if (npc.name == "戰(zhàn)士3")
number = 4;
// if ((key & FIRE_PRESSED) != 0) {
// isbeat = true;
// }
} else if (npc.name == "商人") {
String temp = npc.name + ":" + npc.message1;// 加入npc對話
vectormessage.addElement(temp);
Image tempimage = npc.img;
vectorpicture.addElement(tempimage);
isSeller = true;
} else if(npc.name == "超級女生"){
String temp = npc.name + ":" + npc.message1;// 加入npc對話
vectormessage.addElement(temp);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -