示例#1
0
文件: Enemy.cpp 项目: AS3ECoder/Chaos
void Enemy::skillCallBackAction(Node* pSender)
{
	Hero* p_hero = global->hero;
	Rect attackReck = m_hitBox.actual;//怪物攻击区域
	Rect hurtReck = p_hero->getBodyBox().actual;


	if (attackReck.intersectsRect(hurtReck))
	{
		p_hero->setAllowMove(false);
		int damage = this->getDamageStrength();

		if (getMoveDirection().x > 0)
		{
			p_hero->setFlippedX(true);
			p_hero->runHurtFlyRightAction();
		}
		else
		{
			p_hero->setFlippedX(false);
			p_hero->runHurtFlyLeftAction();
		}
		//连击数归零
		p_hero->hitCount = 0;
		p_hero->setCurtLifeValue(p_hero->getCurtLifeValue() - damage);
	}
	if (p_hero->getCurtLifeValue() <= 0)
	{
		p_hero->runDeadAction();
		p_hero->setBodyBox(createBoundingBox(Vec2::ZERO, Size::ZERO));
	}
}
示例#2
0
void MovingMeshFB::moveMesh()
{
  int i, j, k, m;
  double epsilon = 0.2;
  double error = 1.;
  double area, h, l[3], d[3];
  while (error > epsilon) {
    getMoveDirection();
    error = 0;
    for (i = 0;i < n_geometry(2);i ++) {
      const Point<2>& x0 = point(geometry(2,i).vertex(0));
      const Point<2>& x1 = point(geometry(2,i).vertex(1)); 
      const Point<2>& x2 = point(geometry(2,i).vertex(2));
      l[0] = (x2[0] - x1[0])*(x2[0] - x1[0]) + (x2[1] - x1[1])*(x2[1] - x1[1]);
      l[1] = (x0[0] - x2[0])*(x0[0] - x2[0]) + (x0[1] - x2[1])*(x0[1] - x2[1]);
      l[2] = (x1[0] - x0[0])*(x1[0] - x0[0]) + (x1[1] - x0[1])*(x1[1] - x0[1]);
      area = (x1[0] - x0[0])*(x2[1] - x0[1]) - (x2[0] - x0[0])*(x1[1] - x0[1]);
      h = 0.5*area/sqrt(*std::max_element(&l[0], &l[3]));
      for (k = 0;k < 3;++ k) {
	m = geometry(2,i).vertex(k);
	for (d[k] = 0.0, j = 0;j < 2;j ++) {
	  d[k] += move_direction[m][j]*move_direction[m][j];
	}
      }
      h = sqrt(*std::max_element(&d[0], &d[3]))/h;
      if (error < h) error = h;
    }
    std::cerr << "mesh moving error = " << error << std::endl;
    getMoveStepLength();
    for (i = 0;i < n_move_step;i ++) {
      updateSolution();
      updateMesh();
    };
  };
}
示例#3
0
void 
phgMovingMeshMove(MovingMesh *mmesh, int max_step)
{
    GRID *g = _m->g;
    FLOAT eps = _mp->tol;
    FLOAT min_mv = 2 * eps, max_mv = 0.;
    INT i, j, k, step;
    FLOAT *v;
    char name[100];
    
    Unused(j);
    Unused(k);

    step = 0; 
    while (min_mv > eps) {
	if (max_step > 0 && step >= max_step) {
	    phgPrintf(MESSAGE_HEADER1"Moving mesh stop: reach max step\n");
	    break;
	}
	elapsed_time(g, FALSE, 0.);	/* reset timer */

	if (_mp->verb > 0) {
	    phgPrintf(MESSAGE_HEADER1"Moving mesh substep: %d ", step);
	    elapsed_time(g, TRUE, 0.);
	}

	getMoveDirection(mmesh); 
	max_mv = 0;
	
	v = _m->move->data;
	for (i = 0; i < g->nvert; i++) {
	    FLOAT d = 0.;

	    d += *v * *v; v++;
	    d += *v * *v; v++;
	    d += *v * *v; v++;
	    d = sqrt(d);
	    min_mv = MIN(min_mv, d);
	    max_mv = MAX(max_mv, d);
	}

#if USE_MPI
	{
	    FLOAT min_mv0 = min_mv, max_mv0 = max_mv;
	    MPI_Allreduce(&min_mv0, &min_mv,
			  1, MPI_DOUBLE, MPI_MIN, g->comm);
	    MPI_Allreduce(&max_mv0, &max_mv,
			  1, MPI_DOUBLE, MPI_MAX, g->comm);
	}
#endif /* USE_MPI */

	if (_mp->verb > 0) {
	    phgPrintf(MESSAGE_HEADER1"mesh moving min move = %e\n", min_mv);
	    phgPrintf(MESSAGE_HEADER1"mesh moving max move = %e\n", max_mv);
	}
	getMoveStepLength(_m);

	for (i = 0;i < _mp->n_move_substep;i ++) {
	    updateDof(_m);
	    updateMesh(_m);
#if 1
	    /* use analytic dof to check update dof */
	    {
		DOF **dofs = _m->dofs;
		//char name[100];
		//static int n = 0;
		DOF *dof_err = phgDofCopy(dofs[0], NULL, NULL, "dof err");
		assert(dofs[1]->type == DOF_ANALYTIC);
		phgDofAXPY(-1.0, dofs[1], &dof_err);
		phgPrintf("* update dofs change = %e\n", phgDofNormL2(dof_err));
		//sprintf(name, "dof_error2_%03d.vtk", n++);
		//phgExportVTK(g, name, dof_err, NULL);
		phgDofFree(&dof_err);
	    }
#endif	/* Check dof update */
	}

#if 1
	sprintf(name, "Moving_mesh.dof_%03d.plt", step);
	//phgExportVTK(g, name, _m->dofs[0], NULL);
	//phgExportTecplot(g, name, _m->dofs[0], NULL);

	//phgExportEnsight(g, "Moving", (double)step, _m->monitor, _m->dofs[0], NULL);
#endif	/* export dof to VTK files */
	step++;
    }

    return;
}
示例#4
0
/**
 *	@brief		search 3x4 -> 3x3
 *	@param[in]	ac_InitState		state on start
 *	@param[in]	ac_MidState			state on first search end
 *	@param[in]	ac_MoveLog			space moved log
 */
void	search3x4(char* ac_InitState, char* ac_MidState, char* ac_MoveLog)
{
	char		ac_CurrState[FIELD_SIZE],
				ac_CurrMoveLog[SUM_MOVE_MAX],
				c_CurrSpcPos	= searchSpace(ac_InitState, FIELD_SIZE);
	AVAIL_STATE	ac_AvailState[AVAIL_STATE_NUM];
	const UINT	ui_GoalScore	= ANSWER_PLACE;
	UINT		ui_MaxScore		= checkScore(ac_InitState);

	memcpy(ac_CurrState, ac_InitState, FIELD_SIZE);

	while(ui_MaxScore != ui_GoalScore) {
		AVAIL_STATE	*p_NowState,
					*p_NextState;
		UINT	ui_SpcPos,
				ui_AdjaPos;
		UINT	ui_Score	= 0,
				ui_Anum		= 0,
				uii;
		char	ac_Move[2]	= {'\0', '\0'};

		ui_Score	= 0;
		ui_Anum		= 0;

		memset(ac_AvailState, 0, sizeof(ac_AvailState));
		memcpy(ac_AvailState[ui_Anum].ac_Array, ac_CurrState, FIELD_SIZE);
		ac_AvailState[ui_Anum].c_SpcPos		= c_CurrSpcPos;
		ac_AvailState[ui_Anum].c_PrevPos	= 0x7F;

		for(ui_Anum = 0; ui_Anum < (AVAIL_STATE_NUM - 3); ui_Anum += uii) {
			ui_SpcPos	= ac_AvailState[ui_Anum].c_SpcPos;

			for(uii = 0;
				(ui_AdjaPos = (UINT)ac_Adjacent[ui_SpcPos][uii]) != -1;
				uii++) {
				if((ac_AvailState[ui_Anum].ac_Array[ui_AdjaPos] == ac_AvailState[ui_Anum].c_PrevPos) ||
				   (ac_AvailState[ui_Anum].ac_Array[ui_AdjaPos] == '=')) {
					continue;
				}

				p_NowState	= &ac_AvailState[ui_Anum];
				p_NextState	= &ac_AvailState[ui_Anum + 1];

				/* 状態をコピー */
				memcpy(p_NextState->ac_Array,
					   p_NowState->ac_Array,
					   FIELD_SIZE);

				/* 移動 */
				p_NextState->ac_Array[ui_SpcPos]	= p_NextState->ac_Array[ui_AdjaPos];
				p_NextState->ac_Array[ui_AdjaPos]	= 0;
				p_NextState->c_SpcPos				= (char)ui_AdjaPos;
				p_NextState->c_PrevPos				= p_NowState->c_SpcPos;

				ac_Move[0]	= getMoveDirection(p_NowState->c_SpcPos, p_NextState->c_SpcPos);
				strcat(p_NextState->ac_mMoveLog, ac_Move);

				ui_Score	= checkScore(p_NextState->ac_Array);
				if(ui_Score > ui_MaxScore) {
					ui_MaxScore	= ui_Score;

					memcpy(ac_CurrState, p_NextState->ac_Array, FIELD_SIZE);
					c_CurrSpcPos	= p_NextState->c_SpcPos;
					strcat(ac_CurrMoveLog, p_NextState->ac_mMoveLog);

					ui_Anum	= AVAIL_STATE_NUM;		/* break */
					break;
				}
			}
		}
	}

	printf("3x4 clear !\n");
	printState((char(*)[FIELD_WIDTH])ac_CurrState);

	convertState(ac_MidState, ac_CurrState);
	strcat(ac_MoveLog, ac_CurrMoveLog);
}