/** 加载精灵 */
  public void addSpr() {
    bs = new BattleScene();
    bs.initialize(
        SystemData.getActivityHeight(),
        SystemData.getActivityWidth(),
        SImage.createImage("/res/bg1.jpg"));
    bs.load(getResources());
    SystemData.setCurrentScene(bs);
    ds1 = new DynamicSprite(10, 10, 1, true);
    ds2 = new DynamicSprite(10, 10, 2, true);
    ds4 = new DynamicSprite(x1 - 150, 10, 3, true);
    ds5 = new DynamicSprite(x1 - 150, 10, 4, true);

    ds1.load(SImage.createImage("/res/hero1.png"));
    ds2.load(SImage.createImage("/res/hero2.png"));
    ds4.load(SImage.createImage("/res/enemy1.png"));
    ds5.load(SImage.createImage("/res/enemy2.png"));
    dsList.add(ds1);
    dsList.add(ds2);
    dsList.add(ds5);
    dsList.add(ds4);
    bs.addSprite(
        ds1, SImage.createImage("/res/hero1.png"), SystemData.getActivityHeight() / 3, 120);
    bs.addSprite(
        ds4, SImage.createImage("/res/enemy1.png"), SystemData.getActivityHeight() / 3, 200);
  }
  /**
   * 入口方法
   *
   * @param bundle bundle
   */
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    SystemData.setCurrentFPS(fps);
    x1 = SystemData.getActivityWidth();
    addSpr();
    addHeroList();
  }
Ejemplo n.º 3
0
  /**
   * 绘制,实现自sceneInterface
   *
   * @param canvas 画布
   */
  public void onDraw(Canvas canvas, Paint paint) {
    if (paint == null) {
      paint = DEFAULT_PAINT;
    }
    final Iterator<AbstractSprite> it = dynLevel.getSpriteList().iterator();
    while (it.hasNext()) {
      final AbstractSprite obj = it.next();
      if (obj instanceof Moveable) {
        ((Moveable) obj).autoMove();
      }
      if (obj instanceof StaCollidable) {
        ((StaCollidable) obj).handleStaCollision();
      }
    }
    checkCollision();
    if (mel != null) {
      MapEvent met = map.checkEvent((Rect) hero.getRect());
      if (met != null) {
        mel.mapEventOccured(met);
      }
    }
    if (hero != null) {

      offsetX = hero.getX() - SystemData.getActivityWidth() / 2;
      offsetY = hero.getY() - SystemData.getActivityHeight() / 2;
    }

    if (offsetX < 0) offsetX = 0;
    if (offsetY < 0) offsetY = 0;

    if (offsetX + SystemData.getActivityWidth() > map.getWidth()) {
      offsetX = map.getWidth() - SystemData.getActivityWidth();
    }
    if (offsetY + SystemData.getActivityHeight() > map.getHeight()) {
      offsetY = map.getHeight() - SystemData.getActivityHeight();
    }

    Matrix m = new Matrix();
    m.setTranslate(-offsetX, -offsetY);
    canvas.setMatrix(m);

    // map.setOffsetXY(offsetX, offsetY);
    // dynLevel.setOffsetXY(offsetX, offsetY);

    if (map != null) {
      map.drawDown(canvas, paint);
    }
    if (dynLevel != null) {
      dynLevel.onDraw(canvas, paint);
    }
    if (map != null) {
      map.drawUp(canvas, paint);
    }

    canvas.setMatrix(new Matrix());
  }
Ejemplo n.º 4
0
  /**
   * 入口方法
   *
   * @param savedInstanceState Bundle对象
   */
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 设置屏幕恒为纵向
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // 获得屏幕分辨率
    dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    SystemData.setCurrentComponentLevel(clevel);
    pauseb.setActionListener(new PauseListener());
    clevel.add(pauseb);
    pauseb.setVisible(true);
  }