Example #1
0
//================================================================================
// 更新処理
//================================================================================
void Enemy::update(void)
{
    if(!m_bDeath)
    {
        //状態に応じた処理開始
        (this->*m_pFunc[m_actionMode])();
        //タイムが0なら強制的に行動させる
        if(m_time <= 0)
        {
            m_time = 0;
            m_actionMode = ACTION_NONE;
        }
        //HPが0なら消滅
        if(m_nLife <= 0)
        {
            m_nLife = 0;
            disappear();
        }
    }else{
        if(m_time > 0)
        {
            moveAction();
            m_move -= m_move * 0.01f;
        }
    }
}
	vector<shared_ptr<Action> > BulletAnimator::animate()
	{
		vector<shared_ptr<Action> > actions;
		shared_ptr<Model> model = getEntity().getSingleComponent<Model>();

		if (distance > range)
		{
			Simplicity::removeEntity(getEntity().getName());
			return vector<shared_ptr<Action> >();
		}

		unique_ptr<TransformationMatrix<> > transformation = MathFactory::getInstance().createTransformationMatrix();
		unique_ptr<TranslationVector<> > vector = MathFactory::getInstance().createTranslationVector();
		vector->setData(direction->getData());
		vector->scale(speed);
		transformation->translate(*vector);

		distance += speed;

		shared_ptr<TransformNodeAction> moveAction(
			new TransformNodeAction(getEntity(), *model->getNode(), move(transformation)));
		actions.push_back(moveAction);

		return actions;
	}
Example #3
0
void Player::makeMove() {
  vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
  const vector<Creature*>& creatures = creature->getLevel()->getAllCreatures();
  if (creature->isAffected(LastingEffect::HALLU))
    ViewObject::setHallu(true);
  else
    ViewObject::setHallu(false);
  MEASURE(
      model->getView()->refreshView(creature),
      "level render time");
  if (Options::getValue(OptionId::HINTS) && displayTravelInfo && creature->getConstSquare()->getName() == "road") {
    model->getView()->presentText("", "Use ctrl + arrows to travel quickly on roads and corridors.");
    displayTravelInfo = false;
  }
  static bool greeting = false;
  if (Options::getValue(OptionId::HINTS) && displayGreeting) {
    CHECK(creature->getFirstName());
    model->getView()->presentText("", "Dear " + *creature->getFirstName() + ",\n \n \tIf you are reading this letter, then you have arrived in the valley of " + NameGenerator::worldNames.getNext() + ". There is a band of dwarves dwelling in caves under a mountain. Find them, talk to them, they will help you. Let your sword guide you.\n \n \nYours, " + NameGenerator::firstNames.getNext() + "\n \nPS.: Beware the goblins!");
    model->getView()->presentText("", "Every settlement that you find has a leader, and they may have quests for you."
        "\n \nYou can turn these messages off in the options (press F2).");
    displayGreeting = false;
    model->getView()->refreshView(creature);
  }
  for (const Creature* c : creature->getVisibleEnemies()) {
    if (c->isSpecialMonster() && !contains(specialCreatures, c)) {
      privateMessage(MessageBuffer::important(c->getDescription()));
      model->getView()->refreshView(creature);
      specialCreatures.push_back(c);
    }
  }
  if (travelling)
    travelAction();
  else if (target)
    targetAction();
  else {
    UserInput action = model->getView()->getAction();
    Debug() << "Action " << int(action.type);
  vector<Vec2> direction;
  bool travel = false;
  if (action.type != UserInput::IDLE)
    model->getView()->retireMessages();
  switch (action.type) {
    case UserInput::FIRE: fireAction(action.getPosition()); break;
    case UserInput::TRAVEL: travel = true;
    case UserInput::MOVE: direction.push_back(action.getPosition()); break;
    case UserInput::MOVE_TO: 
      if (action.getPosition().dist8(creature->getPosition()) == 1) {
        Vec2 dir = action.getPosition() - creature->getPosition();
        if (const Creature* c = creature->getConstSquare(dir)->getCreature()) {
          if (!creature->isEnemy(c)) {
            chatAction(dir);
            break;
          }
        }
        direction.push_back(dir);
      } else
        if (action.getPosition() != creature->getPosition()) {
          target = action.getPosition();
          target = Vec2(min(creature->getLevel()->getBounds().getKX() - 1, max(0, target->x)),
              min(creature->getLevel()->getBounds().getKY() - 1, max(0, target->y)));
          // Just in case
          if (!target->inRectangle(creature->getLevel()->getBounds()))
            target = Nothing();
        }
        else
          pickUpAction(false);
      break;
    case UserInput::SHOW_INVENTORY: displayInventory(); break;
    case UserInput::PICK_UP: pickUpAction(false); break;
    case UserInput::EXT_PICK_UP: pickUpAction(true); break;
    case UserInput::DROP: dropAction(false); break;
    case UserInput::EXT_DROP: dropAction(true); break;
    case UserInput::WAIT: creature->wait().perform(); break;
    case UserInput::APPLY_ITEM: applyAction(); break; 
    case UserInput::THROW: throwAction(); break;
    case UserInput::THROW_DIR: throwAction(action.getPosition()); break;
    case UserInput::EQUIPMENT: equipmentAction(); break;
    case UserInput::HIDE: hideAction(); break;
    case UserInput::PAY_DEBT: payDebtAction(); break;
    case UserInput::CHAT: chatAction(); break;
    case UserInput::SHOW_HISTORY: messageBuffer.showHistory(); break;
    case UserInput::UNPOSSESS:
      if (unpossess()) {
        creature->popController();
        return;
      }
      break;
    case UserInput::CAST_SPELL: spellAction(); break;
    case UserInput::DRAW_LEVEL_MAP: model->getView()->drawLevelMap(creature); break;
    case UserInput::EXIT: model->exitAction(); break;
    case UserInput::IDLE: break;
    default: break;
  }
  if (creature->isAffected(LastingEffect::SLEEP)) {
    onFellAsleep();
    return;
  }
  for (Vec2 dir : direction)
    if (travel) {
      if (Creature* other = creature->getSquare(dir)->getCreature())
        attackAction(other);
      else {
        vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
        if (findElement(squareDirs, dir)) {
          travelDir = dir;
          lastLocation = creature->getLevel()->getLocation(creature->getPosition());
          travelling = true;
          travelAction();
        }
      }
    } else {
      moveAction(dir);
      break;
    }
  }
  for (Vec2 pos : creature->getLevel()->getVisibleTiles(creature)) {
    (*levelMemory)[creature->getLevel()].update(pos, creature->getLevel()->getSquare(pos)->getViewIndex(creature));
  }
}
Example #4
0
void ToolDockWidget::createMenu(Qt::DockWidgetArea area, bool split)
{
    QMenu *moveMenu = new QMenu(tr("Move To"),this);
    if (area != Qt::TopDockWidgetArea) {
        QAction *act = new QAction(tr("Top"),this);
        act->setData(Qt::TopDockWidgetArea);
        moveMenu->addAction(act);
        connect(act,SIGNAL(triggered()),this,SLOT(moveAction()));
        QAction *act1 = new QAction(tr("Top : Split"),this);
        act1->setData(Qt::TopDockWidgetArea);
        moveMenu->addAction(act1);
        connect(act1,SIGNAL(triggered()),this,SLOT(moveActionSplit()));
    }
    if (area != Qt::BottomDockWidgetArea) {
        QAction *act = new QAction(tr("Bottom"),this);
        act->setData(Qt::BottomDockWidgetArea);
        moveMenu->addAction(act);
        connect(act,SIGNAL(triggered()),this,SLOT(moveAction()));
        QAction *act1 = new QAction(tr("Bottom : Split"),this);
        act1->setData(Qt::BottomDockWidgetArea);
        moveMenu->addAction(act1);
        connect(act1,SIGNAL(triggered()),this,SLOT(moveActionSplit()));
    }
    if (area != Qt::LeftDockWidgetArea) {
        QAction *act = new QAction(tr("Left"),this);
        act->setData(Qt::LeftDockWidgetArea);
        moveMenu->addAction(act);
        connect(act,SIGNAL(triggered()),this,SLOT(moveAction()));
        QAction *act1 = new QAction(tr("Left : Split"),this);
        act1->setData(Qt::LeftDockWidgetArea);
        moveMenu->addAction(act1);
        connect(act1,SIGNAL(triggered()),this,SLOT(moveActionSplit()));
    }
    if (area != Qt::RightDockWidgetArea) {
        QAction *act = new QAction(tr("Right"),this);
        act->setData(Qt::RightDockWidgetArea);
        moveMenu->addAction(act);
        connect(act,SIGNAL(triggered()),this,SLOT(moveAction()));
        QAction *act1 = new QAction(tr("Right : Split"),this);
        act1->setData(Qt::RightDockWidgetArea);
        moveMenu->addAction(act1);
        connect(act1,SIGNAL(triggered()),this,SLOT(moveActionSplit()));
    }

    QMenu *menu = new QMenu(this);
    if (split) {
        QAction *unsplitAct = new QAction(tr("UnSplit"),this);
        unsplitAct->setData(area);
        connect(unsplitAct,SIGNAL(triggered()),this,SLOT(unsplitAction()));
        menu->addAction(unsplitAct);
    } else {
        QAction *splitAct = new QAction(tr("Split"),this);
        splitAct->setData(area);
        connect(splitAct,SIGNAL(triggered()),this,SLOT(splitAction()));
        menu->addAction(splitAct);
    }
    menu->addAction(moveMenu->menuAction());

    QToolButton *btn = new QToolButton(m_toolBar);
    btn->setPopupMode(QToolButton::InstantPopup);
    btn->setIcon(QIcon("icon:images/movemenu.png"));
    btn->setMenu(menu);
    btn->setText(tr("Move To"));
    btn->setToolTip(tr("Move To"));
    btn->setStyleSheet("QToolButton::menu-indicator {image: none;}");
    m_toolBar->insertWidget(m_closeAct,btn);
}