예제 #1
0
파일: Animal.cpp 프로젝트: ken4500/zoo
void Animal::startDashToPoint(Vec2 targetPoint, float dashTime)
{
    if (isDead()) {
        return;
    }

    _state = AnimalState::Dash;
    _timeline->play("dash", false);

    _targetPointByDash = targetPoint;
    Vec2 move = targetPoint - this->getPosition();

    if (move.x < 0) {
        _image->setFlippedX(false);
        _backImage->setFlippedX(false);
    } else {
        _image->setFlippedX(true);
        _backImage->setFlippedX(true);
    }

    _stopMoveAction();
    if (isOpponent()) {
        _moveAction = this->runAction(MoveBy::create(dashTime, move));
    } else {
        _moveAction = this->runAction(Sequence::create(
                                          MoveBy::create(dashTime, move),
        CallFunc::create([this]() {
            startWalk();
        }),
        NULL
                                      ));
    }
    _moveAction->retain();
}
예제 #2
0
파일: Animal.cpp 프로젝트: ken4500/zoo
void Animal::jump(Vec2 target, float height, std::function<void ()> callback)
{
    if (_state == AnimalState::Dead) {
        return;
    }
    _state = AnimalState::Jump;
    float jumpInterval = ZUtil::calcDurationTime(_timeline, "drop");
    this->runAction(Sequence::create(
                        JumpTo::create(1.0f, target, height, 1),
    CallFunc::create([this, callback] {
        if (callback) {
            callback();
        }
        _timeline->play("drop", false);
    }),
    DelayTime::create(jumpInterval),
    CallFunc::create([this] {
        if (isOpponent() == false) {
            startWalk();
        }
    }),
    NULL
                    ));

    if (SceneManager::getInstance()->isNetwork() == false) {
        auto maxRank = getMaxSizeRank();
        auto minRank = getMinSizeRank();
        SizeRank rank = SizeRank::None;
        Sprite* crown = nullptr;
        if (maxRank != SizeRank::None) {
            crown = Sprite::create(StringUtils::format("ui/max_crown%d.png", maxRank));
            rank = maxRank;
        } else if (minRank != SizeRank::None) {
            crown = Sprite::create(StringUtils::format("ui/min_crown%d.png", minRank));
            rank = minRank;
        }
        if (crown) {
            //
            WorldManager::getInstance()->appearCrown(rank);

            float size = 0.8f;
            if (rank == SizeRank::Gold) {
                size = 1.2f;
            }
            float scale = size / (getScale() * getParent()->getScale());
            crown->setScale(0);
            crown->setPosition(Vec2(200, 400));
            addChild(crown);
            crown->runAction(Sequence::create(
                                 DelayTime::create(1.0f),
                                 EaseBackOut::create(ScaleTo::create(1.0f, scale)),
                                 DelayTime::create(0.5f),
                                 EaseBackIn::create(ScaleTo::create(0.5f, 0)),
                                 RemoveSelf::create(),
                                 NULL
                             ));
        }
    }
}
예제 #3
0
void ModelExtractor::extractModel(shared_connection _con)
{
	C* bean;
	construct(*this, &bean, static_cast<unsigned int>(0));
	bean_key key(_con, Database::NULL_ID, false);
	startWalk(*bean, key);
	destroy(*this, bean, static_cast<unsigned int>(0));
}
예제 #4
0
파일: Animal.cpp 프로젝트: ken4500/zoo
void Animal::startWalk()
{
    if (isDead() || isOpponent()) {
        return;
    }

    Vec2 targetP = WorldManager::getInstance()->getRadomPlace();
    auto speed = getSpeed();
    startWalk(targetP, speed);
}
예제 #5
0
파일: Animal.cpp 프로젝트: ken4500/zoo
void Animal::reborn()
{
    _state = AnimalState::Reborn;
    repairHp();
    setOpacity(255);
    _timeline->play("reborn", false);
    _timeline->setLastFrameCallFunc([this] {
        startWalk();
        _timeline->clearLastFrameCallFunc();
    });
}
예제 #6
0
파일: Animal.cpp 프로젝트: ken4500/zoo
void Animal::startFreeAction()
{
    int rnd = rand() % 2;
    switch (rnd) {
    case 0:
        startWalk();
        break;
    case 1:
        startStop();
    default:
        break;
    }
}
예제 #7
0
파일: Animal.cpp 프로젝트: ken4500/zoo
void Animal::endFight()
{
    _target->release();
    _target = NULL;
    _stopMoveAction();
    _state = AnimalState::Stop;

    auto enemyList = WorldManager::getInstance()->getEnemyAnimalList();
    for (auto enemy : enemyList) {
        if (enemy->isTarget(this)) {
            fight(enemy);
            return;
        }
    }

    startWalk();
}
예제 #8
0
void KGrEnemy::startSearching()
{
    // Called from "KGoldrunner::startPlaying" and "KGrEnemy::dieAndReappear".
    init(x,y);

    if (canStand()||((*playfield)[x][y+1]->whatIam()==USEDHOLE)) {
	status = WALKING;
	walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE);
    }
    else {
	status = FALLING;
	fallTimer->start ((FALLDELAY * NSPEED) / speed, TRUE);
    }

    walkCounter = 1;
    direction = searchbestway(x,y,herox,heroy);
    startWalk();
}
예제 #9
0
void BeanUpdater::update(bean_key key, C& bean)
{
	startWalk( bean, key );
}
예제 #10
0
void KGrEnemy::fallTimeDone ()
{
  if (KGrObject::frozen) {fallFrozen = TRUE; return; }

  if ((*playfield)[x][y+1]->whatIam() == HOLE) {  // wenn Enemy ins Loch fällt
    ((KGrBrick*)(*playfield)[x][y+1])->useHole(); // reserviere das Loch, damit
						  // kein anderer es benutzt und
    if (nuggets) {			  // er muss Gold vorher fallen lassen
      nuggets=0;
      switch ((*playfield)[x][y]->whatIam()) {
      case FREE:
      case HLADDER:	
        ((KGrFree *)(*playfield)[x][y])->setNugget(true); break;
      default:
	emit lostNugget(); break;		// Cannot drop the nugget here.
      }
    }
    emit trapped (75);				// Enemy trapped: score 75.
  }
  else if (walkCounter <= 1) {
	// Enemies collect nuggets when falling.
	if (!nuggets) {
	  collectNugget();
	}
  }

  if ((*playfield)[x][y]->whatIam()==BRICK) {	// sollte er aber in einem Brick
    dieAndReappear();				// sein, dann stirbt er wohl
    return;			// Must leave "fallTimeDone" when an enemy dies.
    }

  if (standOnEnemy()) {				// Don't fall into a friend.
    fallTimer->start((FALLDELAY * NSPEED) / speed, TRUE);
    return;
  }

  if (walkCounter++ < 4){
    fallTimer->start((FALLDELAY * NSPEED) / speed, TRUE);
    { rely+=STEP; absy+=STEP;}
  }
  else {
    rely = 0; y ++; absy=16*y;
    if ((*playfield)[x][y]->whatIam() == USEDHOLE) {
        captiveCounter = 0;
        status = CAPTIVE;
        captiveTimer->start((CAPTIVEDELAY * NSPEED) / speed, TRUE);
    }
    else if (!(canStand()||hangAtPole())) {
	fallTimer->start((FALLDELAY * NSPEED) / speed, TRUE);
	walkCounter=1;
    }
    else {
	status = STANDING;
	if (hangAtPole())
	  actualPixmap=(direction ==RIGHT)?8:12;
    }
  }
  if (status == STANDING) {
    status = WALKING;
    walkCounter = 1;
    direction = searchbestway(x,y,herox,heroy);
    walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE);
    startWalk ();
    if (!nuggets)
      collectNugget();
    else
      dropNugget();
  }
  showFigure();
}
예제 #11
0
void KGrEnemy::walkTimeDone ()
{
  if (KGrObject::frozen) {walkFrozen = TRUE; return; }

  // Check we are alive BEFORE checking for friends being in the way.
  // Maybe a friend overhead is blocking our escape from a brick.
  if ((*playfield)[x][y]->whatIam()==BRICK) {	// sollte er aber in einem Brick
    dieAndReappear();				// sein, dann stirbt er wohl
    return;			// Must leave "walkTimeDone" when an enemy dies.
    }

  if (! bumpingFriend()) {
    switch (direction) {
      case UP:		walkUp (WALKDELAY);
			if ((rely == 0) &&
			    ((*playfield)[x][y+1]->whatIam() == USEDHOLE))
			    // Enemy kletterte grad aus einem Loch hinaus
			    // -> gib es frei!
			    ((KGrBrick *)(*playfield)[x][y+1])->unUseHole();
			break;
      case DOWN:	walkDown (WALKDELAY, FALLDELAY); break;
      case RIGHT:	walkRight (WALKDELAY, FALLDELAY); break;
      case LEFT:	walkLeft (WALKDELAY, FALLDELAY); break;
      default:		// Switch search direction in KGoldrunner search (only).
			searchStatus = (searchStatus==VERTIKAL) ?
					HORIZONTAL : VERTIKAL;

                        // In KGoldrunner rules, if a hole opens under an enemy
                        // who is standing and waiting to move, he should fall.
                        if (!(canStand()||hangAtPole())) {
                            initFall (actualPixmap, FALLDELAY);
                        }
                        else {
                            status = STANDING;
                        }

			break;
    }
    // wenn die Figur genau ein Feld gelaufen ist
    if (status == STANDING) { // dann suche den Helden
      direction = searchbestway(x,y,herox,heroy); // und
      if (walkCounter >= 4) {
        if (! nuggets)
	    collectNugget();
        else
	    dropNugget();
      }
      status = WALKING; // initialisiere die Zählervariablen und
      walkCounter = 1; // den Timer um den Held weiter
      walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE); // zu jagen
      startWalk ();
      }
  }
  else {
    // A friend is in the way.  Try a new direction, but not if leaving a hole.
    Direction dirn;

    // In KGoldrunner rules, change the search strategy,
    // to avoid enemy-enemy deadlock.
    searchStatus = (searchStatus==VERTIKAL) ? HORIZONTAL : VERTIKAL;

    dirn = searchbestway (x, y, herox, heroy);
    if ((dirn != direction) && ((*playfield)[x][y]->whatIam() != USEDHOLE)) {
      direction = dirn;
      status = WALKING;
      walkCounter = 1;
      relx = 0; absx = 16 * x;
      rely = 0; absy = 16 * y;
      startWalk ();
    }
    walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE);
  }
  showFigure();
}
예제 #12
0
void KGrHero::walkTimeDone ()
{
  if (! started) return;	// Ignore signals from earlier play.
  if (KGrObject::frozen) {walkFrozen = TRUE; return; }

  if ((*playfield)[x][y]->whatIam() == BRICK) {
    emit caughtHero();		// Brick closed over hero.
    return;
  }

  if ((y==1)&&(nuggets<=0)) {	// If on top row and all nuggets collected,
    emit leaveLevel();		// the hero has won and can go to next level.
    return;
  }

  if (status == STANDING)
    setNextDir();
  if ((status == STANDING) && (nextDir != STAND)) {
    if ((standOnEnemy()) && (nextDir == DOWN)) {
	emit caughtHero();	// Hero is going to step down into an enemy.
	return;
    }
    startWalk();
  }
  if (status != STANDING) {
      switch (direction) {
      case UP:		walkUp (WALKDELAY); break;
      case DOWN:	walkDown (WALKDELAY, FALLDELAY); break;
      case RIGHT:	walkRight (WALKDELAY, FALLDELAY); break;
      case LEFT:	walkLeft (WALKDELAY, FALLDELAY); break;
      default :
	// The following code is strange.  It makes the hero fall off a pole.
	// It works because of other strange code in "startWalk(), case DOWN:".
	if (!canStand()||hangAtPole()) // falling
	  initFall(FALL1, FALLDELAY);
	else  status = STANDING;
      break;
      }
    herox=x;heroy=y; // Koordinatenvariablen neu
    // wenn Held genau ein Feld weitergelaufen ist,
    if ((relx==0)&&(rely==0)) // dann setzte statische
      {
      collectNugget(); // und nehme evtl. Nugget
      }
    showFigure();	// Is this REDUNDANT now?  See showFigure() below.
			//////////////////////////////////////////////////
    }
  if (status == STANDING)
    if (!canStand()&&!hangAtPole())
      initFall(FALL1, FALLDELAY);
    else
      walkTimer->start ((WALKDELAY * NSPEED) / speed, TRUE);

  // This additional showFigure() is to update the hero position after it is
  // altered by the hero-enemy deadlock fix in standOnEnemy().  Messy, but ...
  ////////////////////////////////////////////////////////////////////////////
  showFigure();
  if(isInEnemy()) {
    walkTimer->stop();
    emit caughtHero();
  }
}