示例#1
0
  @Override
  public boolean ccTouchesBegan(MotionEvent event) {

    if (GameController.getInstance().isStart()) {
      // 如果游戏开始,防止游戏点击事件冲突
      GameController.getInstance().handleTouch(event);
    } else {
      // 没有开始游戏
      if (CommonUtil.isClicke(event, this, choseContainer)) {
        boolean isDel = false; // 记录是否有删除条目
        // 点击的是已选容器
        for (ShowPlant plant : chosePlantList) {
          if (CommonUtil.isClicke(event, this, plant.getDefaultImg())) {
            CCMoveTo moveTo = CCMoveTo.action(0.3f, plant.getBgImg().getPosition());
            plant.getDefaultImg().runAction(moveTo);
            chosePlantList.remove(plant);
            isDel = true;
          }

          if (isDel) {
            // 有条目删除,后面的item依次向前顶一格
            plant
                .getDefaultImg()
                .setPosition(
                    plant.getDefaultImg().getPosition().x - 54,
                    plant.getDefaultImg().getPosition().y);
          }
        }
      } else {
        // 点击开始图片,开启游戏
        if (CommonUtil.isClicke(event, this, start)) {
          setIsTouchEnabled(false); // 不能点击屏幕
          preGame();

        } else {
          // 点击选择容器
          for (ShowPlant plant : showPlantList) {
            if (CommonUtil.isClicke(event, this, plant.getDefaultImg())
                && chosePlantList.size() < 5) {
              CGPoint pos = CGPoint.ccp(75 + chosePlantList.size() * 54, winSize.height - 65);
              CCMoveTo moveTo = CCMoveTo.action(0.3f, pos);
              plant.getDefaultImg().runAction(moveTo);
              chosePlantList.add(plant); // 已选集合
            }
          }
        }
      }
    }

    return super.ccTouchesBegan(event);
  }
示例#2
0
  /** 开启游戏前的准备 */
  private void preGame() {

    // 1.回收容器
    chooseContainer.removeSelf();

    // 玩家已有植物容器进行缩放(包含所有已经选择的植物信息)
    choseContainer.setScale(0.65f);

    // 用已选择的植物填充容器,对容器做缩放操作
    for (ShowPlant item : chosePlantList) {
      CCSprite sprite = item.getDefaultImg();
      CGPoint pos =
          CGPoint.ccp(
              sprite.getPosition().x * 0.65f,
              sprite.getPosition().y + (winSize.getHeight() - sprite.getPosition().y) * 0.35f);
      sprite.setPosition(pos);
      sprite.setScale(0.65f);
      this.addChild(sprite);
    }

    // 2.移动地图
    CGPoint pos =
        CGPoint.ccp(
            gameMap.getContentSize().getWidth() / 2, gameMap.getContentSize().getHeight() / 2);
    CCMoveTo moveTo = CCMoveTo.action(1, pos);
    gameMap.runAction(moveTo);

    CCSequence sequence = CCSequence.actions(moveTo, CCCallFunc.action(this, "clearZombies"));
    // 3.回收僵尸
    gameMap.runAction(sequence);
  }
示例#3
0
  /** 移动地图 */
  private void moveMap() {

    CGPoint pos =
        CGPoint.ccp(
            gameMap.getPosition().x - (gameMap.getContentSize().getWidth() - winSize.getWidth()),
            gameMap.getPosition().y);
    CCMoveTo moveTo = CCMoveTo.action(1, pos);
    CCSequence sequence =
        CCSequence.actions(
            CCDelayTime.action(1),
            moveTo,
            CCDelayTime.action(0.5f),
            CCCallFunc.action(this, "loadContainer"));
    gameMap.runAction(sequence);
  }
示例#4
0
  public BattleLayer() {
    this.setIsTouchEnabled(true);

    btn_skill_bark_activated = CCSprite.sprite("minigame/btn_skill_bark_activated.png");
    btn_skill_bark_normal = CCSprite.sprite("minigame/btn_skill_bark_normal.png");
    btn_skill_bone_activated = CCSprite.sprite("minigame/btn_skill_bone_activated.png");
    btn_skill_bone_normal = CCSprite.sprite("minigame/btn_skill_bone_normal.png");
    btn_skill_punch_activated = CCSprite.sprite("minigame/btn_skill_punch_activated.png");
    btn_skill_punch_normal = CCSprite.sprite("minigame/btn_skill_punch_normal.png");

    gage_bar = CCSprite.sprite("minigame/gage_bar.png");
    gage_bar_black = CCSprite.sprite("minigame/bg_gage_bar.png");

    init_statics();
    init_states();

    gage_bar.setPosition(86 * Manager.ratio_width, 570 * Manager.ratio_height);
    gage_bar.setScaleX(Manager.ratio_width);
    gage_bar.setScaleY(Manager.ratio_height);
    this.addChild(gage_bar);

    gage_bar_black.setPosition(85 * Manager.ratio_width, 765 * Manager.ratio_height);
    gage_bar_black.setAnchorPoint(0.5f, 1f);
    gage_bar_black.setScaleX(Manager.ratio_width);
    gage_bar_black.setScaleY(1 - gage / Manager.full_gage);
    gage_bar_black.setScaleY(Manager.ratio_height);
    this.addChild(gage_bar_black);

    // ��ų ��ư ��ġ ����, ���̾ �߰�
    btn_skill_bark_activated.setPosition(631 * Manager.ratio_width, 733 * Manager.ratio_height);
    btn_skill_bark_activated.setScaleX(Manager.ratio_width); // * Ȯ�� �ʿ�
    btn_skill_bark_activated.setScaleY(Manager.ratio_height);
    this.addChild(btn_skill_bark_activated);
    btn_skill_bark_normal.setPosition(631 * Manager.ratio_width, 733 * Manager.ratio_height);
    btn_skill_bark_normal.setScaleX(Manager.ratio_width); // * Ȯ�� �ʿ�
    btn_skill_bark_normal.setScaleY(Manager.ratio_height);
    this.addChild(btn_skill_bark_normal);

    btn_skill_bone_activated.setPosition(631 * Manager.ratio_width, 589 * Manager.ratio_height);
    btn_skill_bone_activated.setScaleX(Manager.ratio_width);
    btn_skill_bone_activated.setScaleY(Manager.ratio_height);
    this.addChild(btn_skill_bone_activated);
    btn_skill_bone_normal.setPosition(631 * Manager.ratio_width, 589 * Manager.ratio_height);
    btn_skill_bone_normal.setScaleX(Manager.ratio_width);
    btn_skill_bone_normal.setScaleY(Manager.ratio_height);
    this.addChild(btn_skill_bone_normal);

    btn_skill_punch_activated.setPosition(631 * Manager.ratio_width, 439 * Manager.ratio_height);
    btn_skill_punch_activated.setScaleX(Manager.ratio_width);
    btn_skill_punch_activated.setScaleY(Manager.ratio_height);
    this.addChild(btn_skill_punch_activated);
    btn_skill_punch_normal.setPosition(631 * Manager.ratio_width, 439 * Manager.ratio_height);
    btn_skill_punch_normal.setScaleX(Manager.ratio_width);
    btn_skill_punch_normal.setScaleY(Manager.ratio_height);
    this.addChild(btn_skill_punch_normal);

    ////////////////////////////////////////////////////////////////////////////
    bg_battlelayer.setPosition(360 * Manager.ratio_width, 1057 * Manager.ratio_height);
    bg_battlelayer.setScaleX(Manager.ratio_width);
    bg_battlelayer.setScaleY(Manager.ratio_height);
    this.addChild(bg_battlelayer);

    makeNormalAnimation();
    makeDemagedAnimation();

    myCharacter_normal =
        CCSprite.sprite(
            String.format("character/char%d_normal1.png", CurrentUserInformation.userChar));
    myCharacter_normal.setScaleX(-1 * Manager.ratio_width);
    myCharacter_normal.setScaleY(Manager.ratio_height);
    myCharacter_normal.setPosition(212 * Manager.ratio_width, 1019 * Manager.ratio_height);
    myCharacter_normal.runAction(CCRepeatForever.action(normalAnimate_mine));
    this.addChild(myCharacter_normal);

    opponentCharacter_normal =
        CCSprite.sprite(
            String.format("character/char%d_normal1.png", CurrentUserInformation.opponentchar));
    opponentCharacter_normal.setScaleX(Manager.ratio_width);
    opponentCharacter_normal.setScaleY(Manager.ratio_height);
    opponentCharacter_normal.setPosition(508 * Manager.ratio_width, 1019 * Manager.ratio_height);
    opponentCharacter_normal.runAction(CCRepeatForever.action(normalAnimate_opponent));
    this.addChild(opponentCharacter_normal);

    myCharacter_hurted =
        CCSprite.sprite(
            String.format("character/char%d_hurted1.png", CurrentUserInformation.userChar));
    myCharacter_hurted.setScaleX(-1 * Manager.ratio_width);
    myCharacter_hurted.setScaleY(Manager.ratio_height);
    myCharacter_hurted.setPosition(212 * Manager.ratio_width, 1019 * Manager.ratio_height);

    opponentCharacter_hurted =
        CCSprite.sprite(
            String.format("character/char%d_hurted1.png", CurrentUserInformation.opponentchar));
    opponentCharacter_hurted.setScaleX(Manager.ratio_width);
    opponentCharacter_hurted.setScaleY(Manager.ratio_height);
    opponentCharacter_hurted.setPosition(508 * Manager.ratio_width, 1019 * Manager.ratio_height);

    bg_hp_bar.setPosition(360 * Manager.ratio_width, 1240 * Manager.ratio_height);
    bg_hp_bar.setScaleX(-1 * Manager.ratio_width);
    bg_hp_bar.setScaleY(Manager.ratio_height);
    this.addChild(bg_hp_bar);

    hp_bar_mine.setPosition(321 * Manager.ratio_width, 1240 * Manager.ratio_height);
    hp_bar_mine.setScaleX(Manager.ratio_width);
    hp_bar_mine.setScaleY(Manager.ratio_height);
    hp_bar_mine.setAnchorPoint(1f, 0.5f);
    this.addChild(hp_bar_mine);

    hp_bar_opponent.setPosition(400 * Manager.ratio_width, 1240 * Manager.ratio_height);
    hp_bar_opponent.setScaleX(Manager.ratio_width);
    hp_bar_opponent.setScaleY(Manager.ratio_height);
    hp_bar_opponent.setAnchorPoint(0f, 0.5f);
    this.addChild(hp_bar_opponent);

    title.setPosition(360 * Manager.ratio_width, 1235 * Manager.ratio_height);
    title.setScaleX(Manager.ratio_width);
    title.setScaleY(Manager.ratio_height);
    this.addChild(title);

    attack_bark_opponent =
        CCSprite.sprite(
            String.format("character/attack_bark%d.png", CurrentUserInformation.opponentchar));
    attack_bark_opponent.setScaleX(Manager.ratio_width);
    attack_bark_opponent.setScaleY(Manager.ratio_height);
    attack_bark_opponent.setPosition(508 * Manager.ratio_width, 1019 * Manager.ratio_height);
    attack_bark_mine =
        CCSprite.sprite(
            String.format("character/attack_bark%d.png", CurrentUserInformation.userChar));
    attack_bark_mine.setPosition(212 * Manager.ratio_width, 1019 * Manager.ratio_height);
    attack_bark_mine.setScaleX(-1 * Manager.ratio_width);
    attack_bark_mine.setScaleY(Manager.ratio_height);

    attack_bone_opponent =
        CCSprite.sprite(
            String.format("character/attack_bone%d.png", CurrentUserInformation.opponentchar));
    attack_bone_opponent.setScaleX(Manager.ratio_width);
    attack_bone_opponent.setScaleY(Manager.ratio_height);
    attack_bone_opponent.setPosition(508 * Manager.ratio_width, 1019 * Manager.ratio_height);
    attack_bone_mine =
        CCSprite.sprite(
            String.format("character/attack_bone%d.png", CurrentUserInformation.userChar));
    attack_bone_mine.setScaleX(-1 * Manager.ratio_width);
    attack_bone_mine.setScaleY(Manager.ratio_height);
    attack_bone_mine.setPosition(212 * Manager.ratio_width, 1019 * Manager.ratio_height);

    attack_punch_opponent =
        CCSprite.sprite(
            String.format("character/attack_punch%d.png", CurrentUserInformation.opponentchar));
    attack_punch_opponent.setScaleX(Manager.ratio_width);
    attack_punch_opponent.setScaleY(Manager.ratio_height);
    attack_punch_opponent.setPosition(508 * Manager.ratio_width, 1019 * Manager.ratio_height);
    attack_punch_mine =
        CCSprite.sprite(
            String.format("character/attack_punch%d.png", CurrentUserInformation.userChar));
    attack_punch_mine.setScaleX(-1 * Manager.ratio_width);
    attack_punch_mine.setScaleY(Manager.ratio_height);
    attack_punch_mine.setPosition(212 * Manager.ratio_width, 1019 * Manager.ratio_height);

    coming_bark = CCSprite.sprite("battle/coming_bark.png");
    coming_bark.setScaleX(Manager.ratio_width);
    coming_bark.setScaleY(Manager.ratio_height);
    going_bark = CCSprite.sprite("battle/coming_bark.png");
    going_bark.setScaleX(-1 * Manager.ratio_width);
    going_bark.setScaleY(Manager.ratio_height);

    coming_bone = CCSprite.sprite("battle/coming_bone.png");
    coming_bone.setScaleX(Manager.ratio_width);
    coming_bone.setScaleY(Manager.ratio_height);

    going_bone = CCSprite.sprite("battle/coming_bone.png");
    going_bone.setScaleX(-1 * Manager.ratio_width);
    going_bone.setScaleY(Manager.ratio_height);

    coming_punch = CCSprite.sprite("battle/coming_punch.png");
    coming_punch.setScaleX(Manager.ratio_width);
    coming_punch.setScaleY(Manager.ratio_height);

    going_punch = CCSprite.sprite("battle/coming_punch.png");
    going_punch.setScaleX(-1 * Manager.ratio_width);
    going_punch.setScaleY(Manager.ratio_height);

    danger = CCSprite.sprite("minigame/danger.png");
    danger.setScaleX(Manager.ratio_width);
    danger.setScaleY(Manager.ratio_height);
    danger.setPosition(360 * Manager.ratio_width, 833 * Manager.ratio_height);
    danger.setVisible(false);
    this.addChild(danger);

    bg_danger = CCSprite.sprite("minigame/bg_danger.png");
    bg_danger.setScaleX(Manager.ratio_width);
    bg_danger.setScaleY(Manager.ratio_height);
    bg_danger.setPosition(360 * Manager.ratio_width, 640 * Manager.ratio_height);
    bg_danger.setVisible(false);
    this.addChild(bg_danger);

    CCFiniteTimeAction action_waitFight =
        CCMoveTo.action(2f, CGPoint.ccp(-360 * Manager.ratio_width, 826 * Manager.ratio_height));
    CCFiniteTimeAction action_incomingFight =
        CCMoveTo.action(0.3f, CGPoint.ccp(360 * Manager.ratio_width, 826 * Manager.ratio_height));
    CCFiniteTimeAction action_delayFight =
        CCMoveTo.action(0.5f, CGPoint.ccp(360 * Manager.ratio_width, 826 * Manager.ratio_height));
    CCFiniteTimeAction action_outgoingFight =
        CCMoveTo.action(0.3f, CGPoint.ccp(1080 * Manager.ratio_width, 826 * Manager.ratio_height));
    CCCallFuncN tellFight = CCCallFuncN.action(this, "tellFight");
    CCCallFuncN removeFight = CCCallFuncN.action(this, "removeFight");

    CCSequence sequence_fight =
        CCSequence.actions(
            action_waitFight,
            tellFight,
            action_incomingFight,
            action_delayFight,
            action_outgoingFight,
            removeFight);
    fight = CCSprite.sprite("minigame/fight.png");
    fight.setPosition(-360, 826);
    fight.setScaleX(Manager.ratio_width);
    fight.setScaleY(Manager.ratio_height);
    fight.runAction(sequence_fight);
    this.addChild(fight);

    NetworkManager.getInstance().setGetDamagedCallback(this);
  }