基于J2ME WTK的2D手机游戏开发(英文文献翻译) 第11页

基于J2ME WTK的2D手机游戏开发(英文文献翻译) 第11页
 wight = GameMain.widht / 2 - 88;
   hight = GameMain.hight / 2 - 104;
   img = Tools.read_image("logo");
   break;
  case Tools.LOADING:
   wight = GameMain.widht / 2 - 80;
   hight = GameMain.hight / 2 - 50;
   img1 = Tools.read_image("loading1");
   img2 = Tools.read_image("loading2");
   img3 = Tools.read_image("loading3");
   img4 = Tools.read_image("loading4");
   img = img1;
   break;
  case Tools.PLAY:
   img = Tools.read_image("ditu1");
   map1 = new Map(35, 8, img, 32, 32, 1, 1);// 第一层
   map2 = new Map(35, 8, img, 32, 32, 1, 2);// 第二层
   map3 = new Map(35, 8, img, 32, 32, 1, 3);// 第三层
   map_hit = new Map(35, 8, img, 32, 32, 1, 4);
   lay.append(map1);
   // lay.append(map2);
   // lay.append(map3);
   // lay.append(map_hit);
   img1 = Tools.read_image("man");
   man = new Role(img1, 40, 40, map_hit);
   lay.insert(man, 0);
   y = map_hit.getHeight() - GameMain.hight;
   break;
  }
  state_t = setlevel;
 }
 public void render() {
  switch (state_t) {
  case Tools.LOGO:
   GameMain.grap.setColor(0x659AF0);
   GameMain.grap.fillRect(0, 0, GameMain.widht, GameMain.hight);
   GameMain.grap.drawImage(img, wight, hight, 0);
   break;
  case Tools.LOADING:
   GameMain.grap.setColor(0x659AF0);
   GameMain.grap.fillRect(0, 0, GameMain.widht, GameMain.hight);
   GameMain.grap.drawImage(img, wight, hight, 0);
   break;
  case Tools.PLAY:
   // GameMain.grap.setColor(0);
   // GameMain.grap.fillRect(0, 0, GameMain.widht, GameMain.hight);
   GameMain.grap.setColor(0x659AF0);
   GameMain.grap.fillRect(0, 0, GameMain.widht, GameMain.hight);
   GameMain.grap.setColor(0xA1FBEB);
   GameMain.grap.fillRect(0, 0, GameMain.widht, GameMain.hight / 2);
   lay.setViewWindow(x + 6, y, GameMain.widht, GameMain.hight);// 设置地图坐标
   map3.setPosition(-(x + 6) / 4, -y);
   map2.setPosition(-(x + 6) / 3, -y);
   map3.paint(GameMain.grap);
   map2.paint(GameMain.grap);
   lay.paint(GameMain.grap, 0, 0);
   for (int i = 0; i < hp; i++) {
    GameMain.grap.drawImage(img_hp, 40 + 17 * i, 10, 0);
   }
   GameMain.grap.drawImage(img_ren, 5, 2, 0);
   break;
  }
 }
 public void update() {
  switch (state_t) {
  case Tools.LOGO:
   break;
  case Tools.LOADING:
   t++;
   if (t == 10) {
    img = img2;
   }
   if (t == 20) {
    img = img3;
   }
   if (t == 30) {
    img = img4;
   }
   if (t == 40) {
    setLevel(Tools.PLAY);
   }
   break;
  case Tools.PLAY:
   man.update();
   setman();
   setmap();
   manx = man.getX() + man.getWidth() / 2;
   many = man.getY();
   map1.update();
   map2.update();
   map3.update();
   break;
  }
 }
 public void setman() {
  x = man.getX();
  if (man.getX() < 0) {
   man.setPosition(0, man.getY());
  }
  if (man.getX() > map_hit.getWidth() - 35) {
   man.setPosition(map_hit.getWidth() - 35, man.getY());
  }
 }
 public void setmap() {
  if (x < 0) {
   x = 0;
  }
  if (man.getX() < GameMain.widht / 2 - 20) {
   x = 0;
  }
  if (man.getX() >= GameMain.widht / 2 - 20) {
   x = man.getX() - (GameMain.widht / 2 - 20);
   if (x > map_hit.getWidth() - GameMain.widht - 10) {
    x = map_hit.getWidth() - GameMain.widht - 10;
   }
   y = man.getY() > GameMain.hight / 2 - man.getHeight() / 2 ? man
     .getY()
     - GameMain.hight / 2 + man.getHeight() / 2 : y;
   y = y + GameMain.hight > map_hit.getHeight() ? map_hit.getHeight()
     - GameMain.hight : y;
  }
 }
 public void input(int iAction) {
  switch (state_t) {
  case Tools.LOGO:
   if (iAction != 0) {
    img=null;
    setLevel(Tools.LOADING);
   }
   break;
  case Tools.LOADING:
   break;
  case Tools.PLAY:
   man.input(iAction);
   break;
  }
 }
 public void free() {
  img = null;
  img_man = null;// 主角
  img_bing1 = null;
  img_hp = null;
  img_ren = null;
  img_yun = null;
  img1 = null;
  img2 = null;
  img3 = null;
  img4 = null;
  map1 = null;
  map2 = null;
  map3 = null;
  map_hit = null;
  System.gc();

 << 上一页  [11] [12] [13] [14] [15] [16] [17] [18] [19] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有