import javax.microedition.lcdui.*;
import java.util.Random;
import mmae.ui.*;
import mmae.game.Score;
import com.nokia.mid.ui.*;
//Download by http://www.codefans.net
public class PlayCanvas extends XCanvas {
private static int WIDTH ;
private static int HEIGHT ;
boolean gameover;
ImageFont font;
private static boolean gun_left;
private static boolean gun_right;
private static boolean fire[] = new boolean[4];
private static boolean win = false;
private static int gun_x; //大炮的X坐标
private static int gun_y; //大炮的Y坐标
private static int shot_x[] = new int[4]; //炮弹的X坐标
private static int shot_y[] = new int[4]; //炮弹的Y坐标
private int shotNum;
private static int gun_width;
private static int gun_height;
private static int cdegree = 0;
private static int tdegree[] = {0,0,0,0}; //temp degree
private static Image[] gun = new Image[3]; //大炮
private static Image cgun; //当前角度的大炮
private static Image bracket; //支架
private static Image plane[] = new Image[6];
private static Image shot[] = new Image[4]; //炮弹
private static Image bomb; //炸弹
private static Image[] explode = new Image[6]; //爆炸效果
private static Image[] bg = new Image[6];
private static final Font fs = Font.getFont(64, 0, 8);
private static final Font fl = Font.getFont(64, 1, 16);
private static int stage = 0;
private static int score ;
private static int life ;
private static int left_plane ;
private static int degree ;
int rotatedelaycount = 0;
int planeSpeed ;
int bombX ;
Random rand;
int fly; //whitch fly
int tfly;
int interval;
int fireinterval;
private static boolean [] isFly = {false,false,false,false,false,false}; //fly flag
private static boolean [] isSendBomb = {false,false,false,false,false,false};
private static boolean [] isBombShot = {false,false,false,false,false,false};
private static boolean [] isBombGun = {false,false,false,false,false,false};
private static boolean [] isBombGround = {false,false,false,false,false,false};
private static boolean [] isShotPlane = {false,false,false,false,false,false};
private static boolean [] isShotBomb = {false,false,false,false,false,false};
private static int [] hitPlane = {0,0,0,0,0,0};
private static int [] hitBomb = {0,0,0,0,0,0};
private static int [] hitGun = {0,0,0,0,0,0};
private static int [] hitGround = {0,0,0,0,0,0};
private static int [] tBombX = {0,0,0,0,0,0};
int difficulty;
private static int flip;
private static int start_tx;
private static boolean showscore = false ;
private static boolean isNewStage = false ;
private String stagelogo;
boolean out[] = {false,false,false,false,false,false};
int start_x;
int step_x;
int bomb_move_step_h;
int explodecount;
boolean rotate = true;
private int stageinterval;
private int maxstage;
private Image offimg;
private Graphics offg;
private DirectGraphics dg;
//分别对应飞机起飞的初始X,Y,投炸弹的初始X,Y,是否投弹(用0,1表示),飞机飞行的速度,飞机是否爆炸,炸弹是否爆炸(炸弹可见),爆炸效果图计数
// 0,1 2,3, 4, 5, 6, 7 8
int[][] plane_XY = {
// 0 1 2 3 4 5 6 7 8
{WIDTH, 0, 0, 0, 0, 0, 0, 0, 0}
, {0, 0, 0, 0, 0, 0, 0, 0, 0}
, {WIDTH, 0, 0, 0, 0, 0, 0, 0, 0}
, {0, 0, 0, 0, 0, 0, 0, 0, 0}
, {WIDTH, 0, 0, 0, 0, 0, 0, 0, 0}
, {0, 0, 0, 0, 0, 0, 0, 0, 0}
};
public PlayCanvas()
{
/***********************************************
以下为游戏类初使化内容
***********************************************/
gun[0] = go.getImage("/Gun0.png");
gun[1] = go.getImage("/Gun30.png");
gun[2] = go.getImage("/Gun60.png");
bracket = go.getImage("/Bracket.png");
shot[0] = go.getImage("/Shot.png");
shot[1] = go.getImage("/Shot.png");
shot[2] = go.getImage("/Shot.png");
shot[3] = go.getImage("/Shot.png");
plane[0] = go.getImage("/Plane_1.png");
plane[1] = go.getImage("/Plane_2.png");
plane[2] = go.getImage("/Plane_3.png");
plane[3] = go.getImage("/Plane_1.png");
plane[4] = go.getImage("/Plane_2.png");
plane[5] = go.getImage("/Plane_3.png");
explode[0] = go.getImage("/Explosion1.png");
explode[1] = go.getImage("/Explosion2.png");
explode[2] = go.getImage("/Explosion3.png");
explode[3] = go.getImage("/Explosion4.png");
explode[4] = go.getImage("/Explosion5.png");
explode[5] = go.getImage("/Explosion6.png");
bomb = go.getImage("/Bomb.png");
bg[0] = go.getImage("/Bg1.png");
bg[1] = go.getImage("/Bg2.png");
bg[2] = go.getImage("/Bg3.png");
bg[3] = go.getImage("/Bg1.png");
bg[4] = go.getImage("/Bg2.png");
bg[5] = go.getImage("/Bg3.png");
font = new ImageFont(go.getImage("/Font.png"),8);
font.setOffset(-1);
offimg = Image.createImage(getWidth(), getHeight());
offg = offimg.getGraphics();
offg.setFont(PlayCanvas.fs);
dg = DirectUtils.getDirectGraphics(offg);
WIDTH = getWidth();
HEIGHT = getHeight();
gun_width = gun[0].getWidth();
gun_height = gun[0].getHeight();
for(int j=0;j<shot.length;j++){
shot_x[j] = WIDTH / 2;
shot_y[j] = HEIGHT * 4 / 5 + 5;
}
rand = new Random();
init(); //初始化游戏
initPlot(); //初始化游戏关数
difficulty = 84; //难度调节数
interval = 50; //线程的时间间隔
maxstage = 6; //最大关数
start(35);
}
public void init(){ //初始化游戏
win = false;
gameover = false;
isNewStage = true;
stage = 0;
score = 0;
bomb_move_step_h = 1;
life = 10;
}
private void initPlot(){ //初始化关卡
//life = 10; //每关中 玩家的命数
left_plane = 30; //每关中 玩家需要击落的飞机数
degree = 0; //大炮在每关中初始的角度 0表示朝上
isNewStage = true; //新一关的开始 控制着过关后 显示下一关是第几关
difficulty -= 12; //每过一次 难度的修改值 通过改变飞机出场的频率来实现
stageinterval = 0; //用于每关时延的临时计数
stage++; //过关后 关数递增
shotNum = 0;
bomb_move_step_h ++; //炸弹下落时的速度 每一关加一
fireinterval = 0;
for(int j=0;j<shot.length;j++){
fire[j] = false;