void CreatureManager::Strategy()
{
	//当前有单位行动中,等待其行动完成
	if(m_nActionCreatureNum != -1)
		return;

	ResetAllCreature();

	if (m_eCampTurn == eCampTurn_Enemy)
	{
		Character* enemy = GetNextEnemy();
		if(enemy == NULL)
			return;
		if(enemy->GetActionStage() == eActionStage_WaitStage)
		{
			enemy->SetActionStage(eActionStage_MoveStage);
			m_nActionCreatureNum = enemy->GetNum();
			//m_nSelectNum = m_nActionCreatureNum;
			int xMove = g_RandomInt(0,enemy->GetMoveAbility());
			int yMove = enemy->GetMoveAbility() - xMove;
			int xDir = (g_RandomInt(0,1)==0)?-1:1;
			int yDir = (g_RandomInt(0,1)==0)?-1:1;
			eErrorCode errorCode = enemy->Move(enemy->GetBlock().xpos+xMove*xDir,enemy->GetBlock().ypos+yMove*yDir);

			//测试
			if (errorCode != eErrorCode_Success)
			{
				enemy->SetFinish(true);
			}
		}

	}
//	enemy->Move((Direction)(App::sInstance().GetHGE()->Random_Int(0,4)));
}
bool SpaceMine::React()
{
	bool reactFlag = false;
	std::map<int, D3DXVECTOR3> targetList;

	for ( int i = 0; i < REAL_PLAYER_NUM; ++i )
	{
		Character* targetCharacter = GObjectTable->GetCharacter( i );
		if ( !targetCharacter )
			continue;

		// 범위 및 현재 거리 계산
		D3DXVECTOR4 tempMat;
		D3DXVECTOR3 minePosition = GetTransform()->GetPosition();	// ISS 좌표계 기준 좌표

		// 현재 위치
		D3DXVec3Transform( &tempMat, &minePosition, &m_Matrix );
		minePosition = D3DXVECTOR3( tempMat.x, tempMat.y, tempMat.z );

		// 일단 각 플레이어와의 거리 확인
		D3DXVECTOR3 relativeDirection = minePosition - targetCharacter->GetTransform()->GetPosition();
		float distance = D3DXVec3Length( &relativeDirection );
		
		if ( distance <= SPACE_MINE_RANGE )
		{
			// 범위 안이면 일단 추가
			targetList.insert( std::map<int, D3DXVECTOR3>::value_type( i, relativeDirection ) );

			// 만약 다른 팀원이면 발동!
			if ( m_Team != targetCharacter->GetTeam() )
				reactFlag = true;
		}
	}

	// 발동되었다!
	// 발동 조건은 상대방 팀에 한정이지만 발동 후 효과 적용은 전체
	if ( reactFlag )
	{
		printf_s( "react!!\n" );
		for ( std::map<int, D3DXVECTOR3>::const_iterator it = targetList.begin(); it != targetList.end(); ++it )
		{
			// 밀려나는 방향 및 세기 결정
			D3DXVECTOR3 force;
			D3DXVec3Normalize( &force, &it->second );
			force *= -SPACE_MINE_FORCE;

			// 적용 및 방송
			Character* targetCharacter = GObjectTable->GetCharacter( it->first );
			assert( targetCharacter );

			targetCharacter->Move( force );
			targetCharacter->GetClassComponent()->SetMovementControlCooldown( COOLDOWN_STUN );
			GObjectTable->GetActorManager()->BroadcastCharacterChange( it->first, ChangeType::KINETIC_STATE );
		}
	}

	return reactFlag;
}
Beispiel #3
0
    void System::HandleKeyboardInput( Character& player ) {
        // Handle input - Player controls
        if (Key(sf::Key::Left) || Key(sf::Key::A)) {
            player.Move(LEFT);
        } else if (Key(sf::Key::Right) || Key(sf::Key::D)) {
            player.Move(RIGHT);
        }
        if (Key(sf::Key::Up) || Key(sf::Key::W)) {
            player.Move(UP);
        } else if (Key(sf::Key::Down) || Key(sf::Key::S)) {
            player.Move(DOWN);
        }
        if (Key(sf::Key::LShift)) {
            player.SetSpeed( 10.0F );
        }
        else {
            player.SetSpeed( 3.0F );
        }

        // Handle input - Program controls
        if (Key(sf::Key::F4)) {
            SetState(EXIT);
        }
    }
void CreatureManager::SelectCreature()
{
	//友方回合才可以进行选择操作,包括查看敌方行动范围
	if (m_eCampTurn == eCampTurn_Friend)
	{
		Block mouseBlock = App::sInstance().GetMouseBlock();
		Character* selectChar = NULL;
		if (mouseBlock.xpos!=-1 && mouseBlock.ypos!=-1)
		{
			selectChar = GetCreature(mouseBlock.xpos,mouseBlock.ypos);
			//选中单位
			if(selectChar!=NULL)
			{
				//需要拦截点击操作界面的消息
				if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up && !(UISystem::sInstance().GetWindow(eWindowID_Command)->IsOnControl()))
				{
					int nLastSelect = m_nSelectNum;
					if (selectChar->GetCamp() == eCamp_Friend )
					{
						//上次没有选择单位
						if(nLastSelect == -1)
						{
							//选中的未行动友方进入移动阶段
							if(!selectChar->GetFinish())
							{
								m_nSelectNum = selectChar->GetNum();
								selectChar->SetActionStage(eActionStage_MoveStage);
							}
						}
						//连续两次点击同一友方单位
						else if(nLastSelect == selectChar->GetNum())
						{
							if(!selectChar->GetFinish())
							{
								//跳过移动阶段,进入操作阶段
								selectChar->SetActionStage(eActionStage_HandleStage);
								//打开操作界面
								UIWindow* commandWindow = UISystem::sInstance().GetWindow(eWindowID_Command);
								if(commandWindow)
								{
									commandWindow->SetShow(true);
									commandWindow->SetBindChar(selectChar);
								}
							}
						}
						//其他情况
						else
						{
							Character* lastChar = GetCreature(nLastSelect);
							if(lastChar != NULL)
							{
								//上次点的是别的友方
								if(lastChar->GetCamp() == eCamp_Friend)
								{
									if(lastChar->GetFinish() && !selectChar->GetFinish())
									{
										m_nSelectNum = selectChar->GetNum();
										selectChar->SetActionStage(eActionStage_MoveStage);
									}
// 									//上次的友方返回至待命阶段
// 									lastChar->SetActionStage(eActionStage_WaitStage);
// 									selectChar->SetActionStage(eActionStage_MoveStage);
								}
								else if(lastChar->GetCamp() == eCamp_Enemy)
								{
									if(!selectChar->GetFinish())
									{
										m_nSelectNum = selectChar->GetNum();
										selectChar->SetActionStage(eActionStage_MoveStage);
									}
								}
							}
							else 
								//这里是错误分支,不可以运行到这里
								return;
						}
					}
					else if (selectChar->GetCamp() == eCamp_Enemy)
					{
						Character* lastChar = GetCreature(nLastSelect);
						if(lastChar!=NULL) 
						{
							if(lastChar->GetCamp()==eCamp_Friend)
							{
								if(lastChar->GetActionStage() == eActionStage_AttackStage)
								{
									//判断是否可以攻击到选中单位
									if(lastChar->CanHitTarget(selectChar))
									{
										lastChar->SetTarget(selectChar->GetNum());
										lastChar->GeginHit();
										m_nSelectNum = -1;
										return;
									}
								}
							}
							else if (lastChar->GetCamp() == eCamp_Enemy)
							{
								m_nSelectNum = selectChar->GetNum();
							}
						}
						else
						{
							m_nSelectNum = selectChar->GetNum();
						}
					}
				}
			}
			//点中地面
			else
			{
				if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up && !(UISystem::sInstance().GetWindow(eWindowID_Command)->IsOnControl()))
				{
					if (m_nSelectNum>=0)
					{
						selectChar = GetCreature(m_nSelectNum);
						if (selectChar!= NULL)
						{
							if(selectChar->GetCamp() == eCamp_Friend && selectChar->GetActionStage() == eActionStage_MoveStage)
							{
								//判断是否可以移动过去
								int length = abs(mouseBlock.xpos - selectChar->GetBlock().xpos) + abs(mouseBlock.ypos - selectChar->GetBlock().ypos);
								//超过移动范围
								if(length > selectChar->GetMoveAbility())
									return;

								//移动过去,记录原始位置
								selectChar->GetOrigBlock().xpos = selectChar->GetBlock().xpos;
								selectChar->GetOrigBlock().ypos = selectChar->GetBlock().ypos;
								selectChar->GetOrigDirection() = selectChar->GetCurDirection();
								selectChar->Move(mouseBlock.xpos,mouseBlock.ypos);
							}
						}
					}
				}
			}
		}
	}
}
Beispiel #5
0
void Stage_1::update()
{
	GetFrame();
	Input_device->GetKeyState();
	if( Input_device->IsKeyDown( DIK_ESCAPE ) )
	{
		obj->SetNextMode( obj->MODE_END );
		obj->RemoveModeObject();
	}else {
		switch( sstate ) {
		case MOVE_1:
			for( _TaskIterator i( ListObj.Enemy ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}
			for( _TaskIterator i( ListObj.Player ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}
			DrawBase->Draw( 0.0f, 0.0f );
			font_1->Draw( _T( "避けろ!" ), 130, 140 );
			font_2->Draw( _T( "Zキーで始まる" ), 180, 220 );
			if( Input_device->IsKeyPressed( DIK_Z ) )
			{
				sstate = MOVE_2;
			}
			break;
		case MOVE_2:
			for( _TaskIterator i( ListObj.Enemy ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Move();
			}
			for( _TaskIterator i( ListObj.Bullet ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Move();
				if( !chara->GetAlive() ) {
					chara->Uninit();
					i.Remove();
				}
			}
			for( _TaskIterator i( ListObj.Player ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Move();
				if( !chara->GetAlive() ) {
					chara->Uninit();
					i.Remove();
					sstate = MOVE_3;
				}
			}
			for( _TaskIterator i( ListObj.Enemy ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}
			for( _TaskIterator i( ListObj.Player ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}
			for( _TaskIterator i( ListObj.Bullet ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}

			DrawBase->Draw( 0.0f, 0.0f );
			TCHAR buf[10];
			swprintf_s( buf, _T( "%d" ), count );
			RECT rect;
			rect = { 500, 205, 500, 205 };
			font_3->Draw( buf, -1, &rect, DT_NOCLIP | DT_SINGLELINE, 0xFF000000 );
			rect = { 465, 170, 465, 170 };
			font_3->Draw( _T( "残り時間" ), -1, &rect, DT_NOCLIP | DT_SINGLELINE, 0xFF000000 );

			frame = ( frame + 1 ) % 60; 
			if( frame == 0 ) { count--; }
			if( count == 0 ) 
			{
				sstate = MOVE_4;
			}
			break;
		case MOVE_3:
			for( _TaskIterator i( ListObj.Enemy ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}
			DrawBase->Draw( 0.0f, 0.0f );
			font_1->Draw( _T( "GAME OVER" ), 105, 140 );
			font_2->Draw( _T( "Zキーで戻る" ), 180, 220 );
			if( Input_device->IsKeyPressed( DIK_Z ) )
			{
				obj->SetNextMode( obj->MODE_TITLE );
				obj->RemoveModeObject();
			}
			break;
		case MOVE_4:
			for( _TaskIterator i( ListObj.Player ); i.HasNext(); )
			{
				Character* chara = static_cast< Character* >( i.Next() );
				chara->Draw();
			}
			DrawBase->Draw( 0.0f, 0.0f );
			font_1->Draw( _T( "GAME CLEAR" ), 100, 140 );
			font_2->Draw( _T( "Zキーで戻る" ), 180, 220 );
			if( Input_device->IsKeyPressed( DIK_Z ) )
			{
				obj->SetNextMode( obj->MODE_TITLE );
				obj->RemoveModeObject();
			}
			break;
		}
	}
	SleepFrame();
}
void CreatureManager::SelectCreature()
{
	//友方回合才可以进行选择操作,包括查看敌方行动范围
	if (m_eCampTurn == eCampTurn_Friend)
	{
		Block mouseBlock = App::sInstance().GetMouseBlock();
		Character* selectChar = NULL;
		if (mouseBlock.xpos!=-1 && mouseBlock.ypos!=-1)
		{
			selectChar = GetCreature(mouseBlock.xpos,mouseBlock.ypos);
			//选中单位
			if(selectChar!=NULL)
			{
				if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up)
				{
					int nLastSelect = m_nSelectNum;
					if (selectChar->GetCamp() == eCamp_Friend )
					{
						//上次没有选择单位
						if(nLastSelect == -1)
						{
							//选中的未行动友方进入移动阶段
							if(!selectChar->GetFinish())
							{
								m_nSelectNum = selectChar->GetNum();
								selectChar->SetActionStage(eActionStage_MoveStage);
							}
						}
						//连续两次点击同一友方单位
						else if(nLastSelect == m_nSelectNum)
						{
							//过滤移动阶段,进入攻击阶段
							selectChar->SetActionStage(eActionStage_AttackStage);
						}
						//其他情况
						else
						{
							Character* lastChar = GetCreature(nLastSelect);
							if(lastChar != NULL)
							{
								//上次点的是别的友方
								if(lastChar->GetCamp() == eCamp_Friend)
								{
// 									//上次的友方返回至待命阶段
// 									lastChar->SetActionStage(eActionStage_WaitStage);
// 									selectChar->SetActionStage(eActionStage_MoveStage);
								}
								else if(lastChar->GetCamp() == eCamp_Enemy)
								{
									if(!selectChar->GetFinish())
									{
										m_nSelectNum = selectChar->GetNum();
										selectChar->SetActionStage(eActionStage_MoveStage);
									}
								}
							}
							else 
								//这里是错误分支,不可以运行到这里
								return;
						}
					}
					else if (selectChar->GetCamp() == eCamp_Enemy)
					{
						Character* lastChar = GetCreature(nLastSelect);
						if(lastChar!=NULL) 
						{
							if(lastChar->GetCamp()==eCamp_Friend)
							{
								if(lastChar->GetActionStage() == eActionStage_AttackStage)
								{
									//判断是否可以攻击到选中单位
									eAttackRange attackRange = lastChar->GetAttackRange();
									int tarX = 0,tarY = 0;
									for (MAttackRange::iterator mit=m_mAttackRange.begin();mit!=m_mAttackRange.end();mit++)
									{
										if(mit->first == attackRange)
										{
											for (vector<Pair>::iterator it=mit->second.begin();it!=mit->second.end();it++)
											{
												tarX = it->x + lastChar->GetBlock().xpos;
												tarY = it->y + lastChar->GetBlock().ypos;
												if(selectChar->GetBlock().xpos == tarX && selectChar->GetBlock().ypos == tarY)
												{
													//在攻击范围内
													lastChar->SetTarget(selectChar->GetNum());
													lastChar->GeginHit();
													m_nSelectNum = -1;
													return;
												}
											}
										}
									}
								}
							}
							else if (lastChar->GetCamp() == eCamp_Enemy)
							{
								m_nSelectNum = selectChar->GetNum();
							}
						}
						else
						{
							m_nSelectNum = selectChar->GetNum();
						}
					}
				}
			}
			//点中地面
			else
			{
				if (g_getLButtonState(App::sInstance().GetHGE()) == eLButtonState_Up)
				{
					if (m_nSelectNum>=0)
					{
						selectChar = GetCreature(m_nSelectNum);
						if (selectChar!= NULL)
						{
							if(selectChar->GetCamp() == eCamp_Friend && selectChar->GetActionStage() == eActionStage_MoveStage)
							{
								//判断是否可以移动过去
								int length = abs(mouseBlock.xpos - selectChar->GetBlock().xpos) + abs(mouseBlock.ypos - selectChar->GetBlock().ypos);
								//超过移动范围
								if(length > selectChar->GetMoveAbility())
									return;

								//移动过去,记录原始位置
								selectChar->GetOrigBlock().xpos = selectChar->GetBlock().xpos;
								selectChar->GetOrigBlock().ypos = selectChar->GetBlock().ypos;
								selectChar->GetOrigDirection() = selectChar->GetCurDirection();
								selectChar->Move(mouseBlock.xpos,mouseBlock.ypos);
							}
						}
					}
				}
			}
		}
	}
}