📄 gamecanvas.java
字号:
import javax.microedition.lcdui.*;
import com.nokia.mid.ui.*;
import java.util.*;
import javax.microedition.media.*;
public class GameCanvas extends FullCanvas implements PlayerListener{
//脱屏画布、脱屏画笔、旋转画笔
protected Image offScreen;
protected Graphics offG;
protected DirectGraphics DG;
//图片定义区
protected Image Logo1,Logo2; //移动LOGO和工作室LOGO
protected Image Input_Bk; //登陆界面
protected Image Input_Hand; //界面指针
protected Image Game_Bk[]; //每一关的背景图
protected Image Game_Help; //游戏帮助
protected Image Game_Make; //制作小组
protected Image Game_Player; //游戏主角
protected Image Game_Enemy[]; //游戏NPC
protected Image Player_Head; //头像
protected Image Player_Kan; //主角跑动中攻击
protected Image Enemy_Dead; //敌人的死亡
protected Image Thunder; //主角的必杀:闪电
protected Image BOSS; //BOSS
protected Image BOSSACT;
protected Image BOSSBK;
protected Image Huoyan;
protected Image Skull;
protected Image Skull_Chibang;
protected Image Chongji;
protected Image BOSS_Siwang;
protected Image BOSS_Yan;
protected Image Zidan;
protected Image Xueqing;
//定义随机种子
protected Random R; //随机种子
//定义向量
protected Vector AllEnemy; //所有敌人
protected Vector EnemyAI; //敌人的AI
protected Vector EnemyDead; //敌人死亡
//变量定义区
protected int Game_Time; //游戏时间,可用于一切的时间计算
protected byte Game_Mode; //游戏模式
protected byte Draw_Mode; //绘制模式
protected int Input_Hand_y; //界面指针的Y轴
protected int Bk_x; //背景图的X轴
protected byte Game_Code; //游戏按键
protected int Retrun_Code; //返回按键
protected byte Player_Direction; //主角的行动
protected byte Now_Direction; //主角的当前行动
protected int Player_x; //主角的X轴
protected int Player_y; //主角的Y轴
protected byte Player_Speed; //主角速度
protected byte Player_Frames; //帧系列
protected byte Player_Nowframe; //主角当前帧
protected byte Player_Act; //主角的动作
protected byte Run_Time; //当Run_Time < 4时再按下方向键动作帧为跑
protected byte Act_Time; //当Act_Time < 6时按下攻击键动作帧++
protected byte Key_Time; //按下键的时间
protected byte Enemy_Sum; //敌人最多能出现的数量
protected byte Enemy_Create_Time; //敌人出现相隔的时间
protected long Game_Score; //游戏分数
protected byte Player_Bullet; //子弹数量
protected byte Player_Serum; //血清
protected byte Player_Blood; //主角血条
protected byte Player_Wrath; //主角怒气
protected int Enemy_x[];
protected byte Blood_Num;
protected byte Blood_Time;
protected byte Player_ZTime;
protected byte Power_Time;
protected int Baitiao; //主角发必杀时中间的白条
protected int BOSSBK_x; //打BOSS时的背景图X轴
protected byte Huoyan_Time; //火焰闪烁的时间
protected int BOSS_Time; //
protected int BOSS_x;
protected int BOSS_y;
protected byte BOSS_Nowframe;
protected byte BOSS_Frames;
protected byte BOSS_Act;
protected int BOSS_y_Time;
protected int Skull_x1;
protected int Skull_x2;
protected int Black_Width;
protected byte Chibang_Nowframe;
protected byte Chibang_Act;
protected byte Chibang_Frames;
protected byte Zhuanquan;
protected byte Input_BOSS_Mode;
protected byte BOSS_Speed;
protected int BOSS_Blood;
protected int BOSS_Blood_x;
protected int BOSS_Blood_Red;
protected int BOSS_Blood_Green;
protected int BOSS_Blood_Blue;
protected byte BOSS_Mode;
protected int BOSS_Yingzi_x;
protected int BOSS_Yingzi_y;
protected byte BOSS_Yingzi_Width;
protected byte BOSS_Yingzi_Hight;
protected int BOSS_Random;
protected byte Yan_Time;
protected byte BOSSAct_Nowframe;
protected byte BOSSAct_Act;
protected byte BOSSAct_Frames;
protected int Now_BOSS_y;
protected int Now_BOSS_x;
protected byte Zhongqiang_Num;
protected byte Gongji_Num;
protected int Fly_Time;
protected byte Beigongji_Time;
protected int Game_Over_x;
protected byte BOSSSiwang_Nowframe;
protected byte BOSSSiwang_Act;
protected byte BOSSSiwang_Frames;
protected byte Enemy_Num;
protected int BK_Sum;
protected int Zidan_x;
protected int Zidan_y;
protected int Xueqing_x;
protected int Xueqing_y;
//boolean定义区
protected boolean Is_Left_Or_Right; //true时为左,false时为右
protected boolean Is_Act; //抬起攻击键时为true,为true时Act_Time++
protected boolean Is_Run; //抬起方向键时为true,为true时Run_Time++
protected boolean Is_KeyDown; //是否按着键不动
protected boolean Is_Act_Or_Kan; //判断是正常攻击还是特殊攻击
protected boolean Is_Walk_Or_Run; //true时为走m,false时为跑
protected boolean Is_On_Or_Off;
protected boolean Is_BOSS_Left_Or_Right;
protected boolean Is_BOSS_Bianshen;
protected boolean Is_Shifoudazhong;
protected boolean Is_Chiyao;
protected boolean Is_Bianshen;
protected boolean Is_BOSSSiwang;
protected boolean Is_Zidan;
protected boolean Is_Xueqing;
//主角帧系列
protected int Player_Frame[][] = {
//动作 //帧
{0, 0, 69, 48}, //站立 0
{69, 0, 30, 48}, //跑动1 1
{138, 0, 30, 48}, //跑动2 2
{207, 0, 30, 48}, //跑动3 3
{276, 0, 30, 48}, //跑动4 4
{345, 0, 30, 48}, //攻击1 5
{414, 0, 50, 48}, //攻击2 6
{483, 0, 50, 48}, //攻击3 7
{552, 0, 50, 48}, //攻击4 8
{621, 0, 50, 48}, //走动1 9
{690, 0, 30, 48}, //走动2 10
{759, 0, 30, 48}, //走动3 11
{828, 0, 30, 48}, //走动4 12
{897, 0, 30, 48}, //射击1 13
{966, 0, 30, 48}, //射击2 14
{1035, 0, 30, 48}, //射击3 15
{1104, 0, 30, 48} //死亡 16
};
//主角动作系列
protected byte Player_Action[][] = {
{0}, //站立
{1,1,2,2,3,3,4,4,3,3,2,2}, //跑
{5,6,7,8}, //攻击
{9,9,10,10,11,11,12,12,11,11,10,10}, //走
{13,14,15}, //开枪
{16,16,16} //死亡
};
//BOSS帧系列
protected int BOSS_Frame[][] = {
//动作 //帧
{0, 0, 21, 33}, //往前移动 0
{21, 0, 21, 33}, //站立 1
{42, 0, 21, 33}, //往后移动 2
{63, 0, 21, 33}, //悬浮 3
{84, 0, 21, 33}, //准备攻击 4
{105, 0, 21, 33}, //普通攻击 5
{126, 0, 21, 33}, //挨打
{147, 0, 21, 33}
};
//BOSS动作系列
protected byte BOSS_Action[][] = {
{1}, //站立
{0}, //向前移动
{1,1,1,1,2,2,2,2,2,2,2}, //向后移动
{3}, //悬浮
{4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5}, //攻击
{6}, //被攻击
{3,3,3,3,3,3,3,0,0,0,0,0,0,1,1,1,1,1,1,6,6,6,6,6,6,6}, //片头
{5}, //冲刺攻击
{0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2}, //死亡
{2} //变身后往下掉
};
//BOSS的死亡帧
protected int BOSSSiwang_Frame[][] = {
{0, 0, 35, 27},
{35, 0, 35, 27},
{70, 0, 35, 27},
{135, 0, 35, 27}
};
//BOSS的死亡动作系列
protected byte BOSSSiwang_Action[][] = {
{0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2}
};
//BOSS的攻击帧
protected int BOSSAct_Frame[][] = {
{0, 0, 19, 13},
{38, 0, 19, 13},
{57, 0, 19, 13},
{76, 0, 19, 13},
};
//BOSS的攻击动作系列
protected byte BOSSAct_Action[][] = {
{0,0,0,0,1,1,1,1,2,2,2,2,0,0,0,0,1,1,1,1,2,2,2,2}
};
//翅膀的帧系列
protected byte Chibang_Frame[][] = {
{0, 0, 21, 25},
{21, 0, 21, 25},
{42, 0, 21, 25},
{60, 0, 21, 25}
};
//
protected byte Chibang_Action[][] = {
{0,0,0,0,1,1,1,1,2,2,2,2}
};
//敌人1的帧系列
protected int Enemy1_Frame[][] = {
//动作 //帧
{0, 0, 30, 30}, //走动1 0
{30, 0, 30, 30}, //走动2 1
{60, 0, 30, 30}, //走动3 2
{90, 0, 30, 30}, //攻击 3
{120, 0, 30, 30}, //走动4 4
{150, 0, 30, 30}, //站立 5
{180, 0, 30, 30}
};
//敌人1的动作系列
protected byte Enemy1_Action[][] = {
{5}, //站立
{0,0,1,1,2,2,4,4}, //走
{3,3,3,5,5,5,5,5,5,5,5,5,5}, //攻击
{0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2} //死亡
};
//线程定义区
protected Timer T;
//构造方法
protected GameCanvas()
{
//脱屏画布、脱屏画笔、旋转画笔初始化
offScreen = Image.createImage(176,208);
offG = offScreen.getGraphics();
DG = DirectUtils.getDirectGraphics(offG);
//随机种子初始化
R = new Random();
//向量初始化
AllEnemy = new Vector();
EnemyAI = new Vector();
EnemyDead = new Vector();
//数组初始化
Game_Bk = new Image[1];
Game_Enemy = new Image[1];
Enemy_x = new int[7];
//变量初始化
Game_Mode = 0;
Draw_Mode = 0;
Game_Time = 0;
Input_Hand_y = 110;
Game_Code = 0;
Retrun_Code = 0;
Bk_x = 0;
Player_Direction = 0;
Player_x = 20;
Player_y = 115;
Player_Speed = 2;
Player_Nowframe = 0;
Player_Act = 0;
Run_Time = 0;
Act_Time = 0;
Key_Time = 0;
Now_Direction = 0;
Enemy_Sum = 0;
Enemy_Create_Time = 0;
Game_Score = 0;
Player_Bullet = 20;
Player_Serum = 3;
Player_Blood = 62;
Player_Wrath = 62;
Blood_Num = 0;
Blood_Time = 0;
Player_ZTime = 0;
Power_Time = 0;
Baitiao = 0;
BOSSBK_x = -88;
Huoyan_Time = 0;
BOSS_Time = 0;
BOSS_x = 180;
BOSS_y = 70;
BOSS_Nowframe = 0;
BOSS_Frames = 0;
BOSS_Act = 3;
BOSS_y_Time = 0;
Skull_x1 = 205;
Skull_x2 = 160;
Black_Width = 22;
Chibang_Act = 0;
Chibang_Nowframe = 0;
Chibang_Frames = 0;
Zhuanquan = 0;
Input_BOSS_Mode = 0;
BOSS_Speed = 4;
BOSS_Blood = 60;
BOSS_Blood_x = 176;
BOSS_Blood_Red = 255;
BOSS_Blood_Green = 255;
BOSS_Blood_Blue = 0;
BOSS_Mode = 0;
BOSS_Yingzi_x = 0;
BOSS_Yingzi_y = 0;
BOSS_Yingzi_Width = 0;
BOSS_Yingzi_Hight = 0;
Yan_Time = 0;
BOSSAct_Nowframe = 0;
BOSSAct_Act = 0;
BOSSAct_Frames = 0;
Now_BOSS_y = 0;
Now_BOSS_x = 0;
Zhongqiang_Num = 0;
Gongji_Num = 0;
Fly_Time = 0;
Beigongji_Time = 0;
Game_Over_x = 176;
BOSSSiwang_Nowframe = 0;
BOSSSiwang_Act = 0;
BOSSSiwang_Frames = 0;
Enemy_Num = 0;
BK_Sum = 0;
Zidan_x = 0;
Zidan_y = 0;
Xueqing_x = 0;
Xueqing_y = 0;
//boolean初始化
Is_Left_Or_Right = false;
Is_Act_Or_Kan = true;
Is_Walk_Or_Run = true;
Is_Act = false;
Is_Run = false;
Is_KeyDown = false;
Is_On_Or_Off = false;
Is_BOSS_Left_Or_Right = true;
Is_BOSS_Bianshen = false;
Is_Shifoudazhong = false;
Is_Chiyao = false;
Is_Bianshen = false;
Is_BOSSSiwang = false;
Is_Zidan = false;
Is_Xueqing = false;
//图片装载
try{
Logo1 = Image.createImage("/MobileLogo.png");
Logo2 = Image.createImage("/GameBugLogo.png");
Input_Bk = Image.createImage("/BK.png");
Input_Hand = Image.createImage("/Input_Hand.png");
Game_Bk[0] = Image.createImage("/Game_BK1.png");
Game_Help = Image.createImage("/Game_Help.png");
Game_Make = Image.createImage("/Game_Help.png");
Game_Player = Image.createImage("/Player.png");
Game_Enemy[0] = Image.createImage("/Enemy1.png");
Enemy_Dead = Image.createImage("/Enemy_Dead.png");
Player_Head = Image.createImage("/Head.png");
Player_Kan = Image.createImage("/Kan.png");
Thunder = Image.createImage("/Thunder.png");
BOSS = Image.createImage("/Boss1.png");
BOSSACT = Image.createImage("/BossAct.png");
BOSSBK = Image.createImage("/dating.png");
Huoyan = Image.createImage("/huoyan.png");
Skull = Image.createImage("/skull.png");
Skull_Chibang = Image.createImage("/skullchibang.png");
Chongji = Image.createImage("/chongji.png");
BOSS_Siwang = Image.createImage("/bosssiwang.png");
BOSS_Yan = Image.createImage("/yan.png");
Zidan = Image.createImage("/zidan.png");
Xueqing = Image.createImage("/xueqing.png");
}catch(Exception xx){System.out.println("pic err");}
//线程初始化
T = new Timer();
T.schedule(Game_T,0,60);
}
//数据初始化
protected void GameInit()
{
}
//绘制屏幕
protected void paint(Graphics G)
{
G.drawImage(offScreen,0,0,0);
}
//游戏模式
protected void GameStatus()
{
switch(Game_Mode)
{
case 0:
Game_Time++;
if(Game_Time > 20)
{
Game_Time = 0;
Game_Mode++;
Draw_Mode++;
}
break;
case 1:
Game_Time++;
if(Game_Time > 30)
{
Game_Time = 0;
Game_Mode++;
Draw_Mode++;
}
break;
case 2:
Game_Time++;
if(Game_Time > 2)
{
switch(Game_Code)
{
case -1:
Game_Time = 0;
Input_Hand_y -= 18;
if(Input_Hand_y < 110)
{
Input_Hand_y = 182;
}
break;
case -2:
Game_Time = 0;
Input_Hand_y += 18;
if(Input_Hand_y > 182)
{
Input_Hand_y = 110;
}
break;
case -5:
switch(Input_Hand_y)
{
case 110:
Game_Mode++;
Draw_Mode++;
break;
case 128:
Game_Mode += 2;
Draw_Mode += 2;
break;
case 146:
Game_Mode +=3;
Draw_Mode +=3;
break;
case 164:
Game_Mode += 4;
Draw_Mode += 4;
break;
case 182:
GameMIDlet.G_MIDlet.notifyDestroyed();
break;
}
break;
case 50:
Game_Code = -1;
break;
case 56:
Game_Code = -2;
break;
case 53:
Game_Code = -5;
break;
}
}
break;
case 3:
PlayerSpeed();
AllTime();
PlayerStatus();
break;
case 4:
switch(Game_Code)
{
case -7:
Game_Mode = 2;
Draw_Mode = 2;
break;
}
break;
case 5:
switch(Game_Code)
{
case -7:
Game_Mode = 2;
Draw_Mode = 2;
break;
}
break;
case 6:
switch(Game_Code)
{
case -7:
Game_Mode = 2;
Draw_Mode = 2;
break;
}
break;
case 7:
if(Is_On_Or_Off)
{
PlayerSpeed();
AllTime();
if(!Is_Bianshen && BOSS_Mode != 88)
{
PlayerStatus1();
}
if(Player_Direction != 57)
{
BOSSAI();
}
}
break;
}
}
//绘制模式
protected void DrawStatus()
{
offG.setClip(0,0,176,208);
switch(Draw_Mode)
{
case 0:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -