📄 gamecanvas.java
字号:
private void showLuoPan(Graphics g)
{
int x = 10;
int y = i_lcdCenterY - 70;
int width = i_lcdWidth - 20;
int height = 140;
g.setClip(x, y, width, height);
g.setColor(0x000000);
g.fillRect(x, y, width, height);
g.setColor(0xFF0000);
x++;
y++;
width -= 3;
height -= 3;
g.drawRect(x, y, width, height);
g.drawString("风之罗盘", i_lcdCenterX, y + 2, Configration.G_TH);
y += 20;
g.drawLine(x, y, x + width, y);
g.setColor(0xFFFFFF);
x += 5;
g.drawString("请您选择要去的地方:", x, y + 2, Configration.G_TL);
y += 22;
height -= 40;
height /= 5;
width /= 4;
StringBuffer s = new StringBuffer();
for(byte i = 1; i < 21; i++)
{
if(i <= maxStage)
{
g.setColor(0xFFFFFF);
}
else
{
g.setColor(0x333333);
}
if(i == b_Selected)
{
g.drawRect(x + (i - 1) % 4 * width, y + (i - 1) / 4 * height - 2,
36, height);
}
s.append("第");
s.append(i);
s.append("层");
g.drawString(s.toString(), x + (i - 1) % 4 * width + 2, y + (i - 1) / 4 * height, Configration.G_TL);
s.delete(0, s.length());
}
}
private void showStageChanged(Graphics g)
{
g.setColor(0x000000);
g.fillRect(0, 0, i_lcdWidth, i_lcdHeight);
g.drawImage(img_Title, i_lcdCenterX, i_lcdCenterY, Configration.G_BH);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE ));
g.setColor(0xFFFFFF);
g.drawString("第" + b_Stage + "层", i_lcdCenterX, i_lcdCenterY + 30, Configration.G_BH);
if(i_num % 10 == 0)
{
CurrentState = Configration.NORMAL;
}
}
private void showAbout(Graphics g)
{
showMessage(Configration.About, g);
}
private void drawEnd(Graphics g)
{
showInfo(Configration.End, g);
}
private void drawGaming(Graphics g)
{
for(byte i = 0; i <= i_lcdHeight / 32; i++)
{
for(byte j = 0; j <= i_lcdWidth / 32; j++)
{
g.setClip(j * 32, i * 32, 32, 32);
g.drawImage(img_Map, j * 32 - 288, i * 32 - 288, Configration.G_TL);
}
}
map.paint(g);
g.setClip(0, 0, i_lcdWidth, i_lcdHeight);
g.setColor(0x00FFFF);
g.drawString("您已用时:"+ UsedTime / 60000
+ "分" + (UsedTime % 60000) / 1000 + "秒", 5, 5, Configration.G_TL);
g.drawString("Level:" + HeroLv, 5, i_lcdHeight - 95, Configration.G_TL);
g.drawString("Life:" + HeroLp, 5, i_lcdHeight - 85, Configration.G_TL);
g.drawString("AC:" + HeroAc, 5, i_lcdHeight - 75, Configration.G_TL);
g.drawString("DC:" + HeroDc, 5, i_lcdHeight - 65, Configration.G_TL);
g.drawString("Exp:" + HeroExp, 5, i_lcdHeight - 55, Configration.G_TL);
g.drawString("Money:" + HeroMoney, 5, i_lcdHeight - 45, Configration.G_TL);
g.drawString("R:" + RedKey, 5, i_lcdHeight - 35, Configration.G_TL);
g.drawString("B:" + BlueKey, 5, i_lcdHeight - 25, Configration.G_TL);
g.drawString("Y:" + YellowKey, 5, i_lcdHeight - 15, Configration.G_TL);
switch(CurrentState)
{
case Configration.NORMAL:
g.setClip(i_lcdCenterX - 9, i_lcdCenterY - 14, 19, 28);
g.drawImage(img_Hero, i_lcdCenterX - 9 - Steps[stepIndex] * 19,
i_lcdCenterY - 14 - Direction * 28, Configration.G_TL);
if(Msg != null)
{
showMessage(Msg, g);
}
else
{
if(BeelzeBubIsDead)
{
FreeImage();
SS_NOW = Configration.SS_END;
LoadImage();
}
}
break;
case Configration.ANGEL:
case Configration.JACK:
case Configration.PRINCESS:
case Configration.BEELZEBUB:
if(Message != null)
{
showMessage(Message, g);
}
break;
case Configration.STAGECHANGED:
showStageChanged(g);
break;
case Configration.SHOWMENU:
String Menu[]= {"返回游戏", "保存进度", "读取进度","游戏说明", "退出游戏"};
showMenu("游戏菜单", "", Menu, g);
break;
case Configration.SHOPING:
if(b_Stage == 3)
{
String Menu1[] = {"加800点生命", "加4点攻击", "加4点防御", "离开"};
showMenu("商店", "如果您有25个金币,那么我可以为您提供以下服务:", Menu1, g);
}
else
{
String Menu1[] = {"加4000点生命", "加20点攻击", "加20点防御", "离开"};
showMenu("商店", " 如果您有100个金币,那么我可以为您提供以下服务:", Menu1, g);
}
break;
case Configration.LEVELUP:
switch(b_Stage)
{
case 2:
case 15:
if(Message != null)
{
showMessage(Message, g);
}
break;
case 5:
String Menu2[] = {"等级提升1(100经验)", "加5点攻击(30经验)", "加5点防御(30经验)", "离开"};
showMenu("神秘老人", "", Menu2, g);
break;
case 13:
String Menu3[] = {"等级提升3(270经验)", "加17点攻击(95经验)", "加17点防御(95经验)", "离开"};
showMenu("神秘老人", "", Menu3, g);
break;
}
break;
case Configration.BUYKEY:
switch(b_Stage)
{
case 2:
case 15:
if(Message != null)
{
showMessage(Message, g);
}
break;
case 5:
String Menukey5[] = {"购买黄钥匙(30金币)","购买蓝钥匙(50金币)","购买红钥匙(100金币)","离开"};
showMenu("神秘商人", "", Menukey5, g);
break;
case 12:
String Menukey12[] = {"出售黄钥匙(10金币)","出售蓝钥匙(30金币)","出售买红钥匙(70金币)","离开"};
showMenu("神秘商人", "", Menukey12, g);
break;
}
break;
case Configration.ABOUT:
showAbout(g);
break;
case Configration.INFO:
showMonInfo(g);
break;
case Configration.LUOPAN:
showLuoPan(g);
break;
}
}
private void drawIntro(Graphics g)
{
showInfo(Configration.Intro, g);
}
private void drawLogo(Graphics g)
{
g.setColor(0xFFFFFF);
g.fillRect(0, 0, i_lcdWidth, i_lcdHeight);
g.drawImage(img_Logo, i_lcdCenterX, i_lcdCenterY, Configration.G_VH);
if(i_num % 10 == 0)
{
FreeImage();
SS_NOW = Configration.SS_TITLE;
LoadImage();
}
}
private void showMenu(String Title, String Info, String Items[], Graphics g)
{
Font f = Font.getDefaultFont();
byte w = (byte)(f.charWidth('汉') + 2);
byte h = 20;
byte width =(byte)((i_lcdWidth - 26) / w);
byte height = (byte)(Info.length() / width);
if(Info.length() % width != 0)
{
height++;
}
int index = -1;
int MenuHeight = (height + 1 + Items.length) * h + 6;
int y = i_lcdCenterY - MenuHeight / 2;
int x = 10;
g.setColor(0x000000);
g.setClip(x, y, i_lcdWidth - 20, MenuHeight);
g.fillRect(x, y, i_lcdWidth - 20, MenuHeight);
g.setColor(0xFF0000);
x++;
g.drawRect(x, y + 1, i_lcdWidth - 23, MenuHeight - 3);
y += h;
g.drawLine(x, y, i_lcdWidth - 13, y);
g.drawString(Title, i_lcdCenterX, y, Configration.G_BH);
g.setColor(0xFFFFFF);
x += 5;
if(!Info.equals(""))
{
for(byte i = 0; i < height; i++)
{
for(byte j = 0; j < width; j++)
{
index++;
if(index < Info.length())
{
g.drawString(Info.substring(index,index+1), x + j * w,
y + i * h, Configration.G_TL);
}
}
}
y += height * h;
}
y += 20;
for(byte i = 0; i < Items.length; i++)
{
if(i == b_Selected)
{
g.drawImage(img_jtr, i_lcdCenterX - 60, y + i * h - 5,
Configration.G_BH);
g.drawImage(img_jtl, i_lcdCenterX + 60, y + i * h - 5,
Configration.G_BH);
g.setColor(0xD733E6);
}
else
{
g.setColor(0xFFFFFF);
}
g.drawString(Items[i], i_lcdCenterX, y + i * h, Configration.G_BH);
}
}
private void MapMove()//地图的动态处理
{
for(byte i = 1; i < 39; i++)
{
map.setAnimatedTile(-i, i * 2 - 1 + i_num % 2);
}
}
public void run()
{
while(is_Run)
{
i_num++;
if(i_num < 0)
{
i_num = 0;
}
if(i_num % 10 == 0 && Msg != null)
{
Msg = null;
is_Move = true;
}
UsedTime = System.currentTimeMillis() - StartTime;
switch(SS_NOW)
{
case Configration.SS_LOGO:
break;
case Configration.SS_TITLE:
break;
case Configration.SS_MENU:
break;
case Configration.SS_INTRO:
offestY--;
if(offestY < -IntroHeight)
{
FreeImage();
SS_NOW = Configration.SS_GAMING;
LoadImage();
initGame();
initStage();
}
break;
case Configration.SS_GAMING:
if(is_Loaded)
{
hasExp = (HeroExp >= 500 && is_DialogedForLevelUp15) ? true : false;
hasMoney = (HeroMoney >= 800 && is_DialogedForBuyKey15) ? true : false;
switch(CurrentState)
{
case Configration.NORMAL:
if(map != null && i_num % 3 == 0)
{
MapMove();
stepIndex++;
if(stepIndex >= 4)
{
stepIndex = 0;
}
}
break;
}
}
break;
case Configration.SS_END:
offestY--;
if(offestY < -IntroHeight)
{
FreeImage();
SS_NOW = Configration.SS_MENU;
LoadImage();
}
break;
case Configration.SS_ABOUT:
break;
}
repaint();
try
{
Thread.sleep(i_Speed);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
//=====================判断行进方向的物体===================
private byte getFront()
{
byte result = 0;
switch(Direction)
{
case Configration.UP:
if(b_y >= 1 && b_y < 11 && b_x >= 0 && b_x < 11)
{
result = mapArray[(b_y -1) * 11 + b_x];
}
break;
case Configration.DOWN:
if(b_y >= 0 && b_y < 10 && b_x >= 0 && b_x < 11)
{
result = mapArray[(b_y +1) * 11 + b_x];
}
break;
case Configration.LEFT:
if(b_y >= 0 && b_y < 11 && b_x >= 1 && b_x < 11)
{
result = mapArray[b_y * 11 + b_x - 1];
}
break;
case Configration.RIGHT:
if(b_y >= 0 && b_y < 11 && b_x >= 0 && b_x < 10)
{
result = mapArray[b_y * 11 + b_x + 1];
}
break;
}
return result;
}
//=====================等级提升==========================
private void HeroLvUp(int i)
{
HeroLv += i; //英雄等级
HeroLp += 1000 * i;//英雄生命值
HeroAc += 7 * i;//英雄攻击力
HeroDc += 7 * i;//英雄防御力
}
//=====================场景处理=========================
private void setValue()
{
switch(Direction)
{
case Configration.UP:
if(b_y >= 1 && b_y < 11 && b_x >= 0 && b_x < 11)
{
mapArray[(b_y - 1) * 11 + b_x] = 120;
map.setCell(b_x, b_y - 1, (byte)120);
}
break;
case Configration.DOWN:
if(b_y >= 0 && b_y < 10 && b_x >= 0 && b_x < 11)
{
mapArray[(b_y + 1) * 11 + b_x] = 120;
map.setCell(b_x, b_y + 1, (byte)120);
}
break;
case Configration.LEFT:
if(b_y >= 0 && b_y < 11 && b_x >= 1 && b_x < 11)
{
mapArray[b_y * 11 + b_x - 1] = 120;
map.setCell(b_x - 1, b_y, (byte)120);
}
break;
case Configration.RIGHT:
if(b_y >= 0 && b_y < 11 && b_x >= 0 && b_x < 10)
{
mapArray[b_y * 11 + b_x + 1] = 120;
map.setCell(b_x + 1, b_y, (byte)120);
}
break;
}
}
private void showMessage(String msg, Graphics g) //显示消息
{
byte width;
byte height;
Font f = Font.getDefaultFont();
byte w = (byte)(f.charWidth('汉') + 2);
width =(byte)((i_lcdWidth - 20) / w);
height = (byte)(msg.length() / width);
if(msg.length() % width != 0)
{
height++;
}
int index = -1;
byte h = 20;
g.setColor(0x000000);
if(width > msg.length()) width = (byte)msg.length();
int x = i_lcdCenterX - width * w /2;
int y = i_lcdCenterY - height * h / 2;
g.setClip(x- 5, y -5,
width * w + 10, height * 20 + 10);
g.setFont(f);
g.fillRect(x- 5, y -5,
width * w + 10, height * 20 + 10);
g.setColor(0xFF0000);
g.drawRect(x - 5, y -5,
width * w + 9, height * h + 9);
for(byte i = 0; i < height; i++)
{
for(byte j = 0; j < width; j++)
{
index++;
if(index < msg.length())
{
g.drawString(msg.substring(index,index+1), x + j * w,
y + i * h, Configration.G_TL);
}
}
}
}
private void DialogForPrincess() //处理与公主的对话
{
if(b_DialogIndexForPrincess >= Configration.DialogForPrincess.length - 1)
{
b_DialogIndexForPrincess =(byte)(Configration.DialogForPrincess.length - 1);
is_Move = true;
if(!is_DialogedForPrincess)
{
is_DialogedForPrincess = true;
OpenStore();
try
{
byte buffer[] = rs.getRecord(3);
mapArray[120] = 94;
map.setCell(10, 10, (byte)94);
rs.setRecord(3, buffer, 0, buffer.length);
}
catch(Exception e)
{
e.printStackTrace();
}
CloseStore();
}
}
Message = Configration.DialogForPrincess[b_DialogIndexForPrincess];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -