示例#1
0
bool BombMissile::onContactBegin(cocos2d::PhysicsContact& contact)
{
	//한 번만 데미지 입히게 하기 위한 용도. 뎀 드가고 나면 그림만 보임.
	//실제 미사일 삭제 시점은 그래픽 사라지는 시점.
	m_IsPhysics = false;

	auto bodyA = contact.getShapeA()->getBody();
	auto bodyB = contact.getShapeB()->getBody();
	auto componentA = (BaseComponent*)bodyA->getNode();
	auto componentB = (BaseComponent*)bodyB->getNode();
	BaseComponent* enemyComponent;
	bool isComponentA = true;

	if (componentA->getType() == getType())
	{
		enemyComponent = componentB;
		isComponentA = true;
	}
	else
	{
		enemyComponent = componentA;
		isComponentA = false;
	}

	GET_SOUND_MANAGER()->createSound(SoundManager::MONSTERHIT, false, getPosition());
	GET_EFFECT_MANAGER()->createEffect(ET_PUNCH_MISSILE, enemyComponent->getPosition())->enter();

	return false;
}
示例#2
0
void EntitySystem::CreateAndAttachComponent(
	Entity e,
	COMPONENT_TYPE type,
	BaseComponent::Data& data )
{
	// unfortunately, it appears we have to create the component
	// and try to insert it. It's easier than iterating through the set.
	BaseComponent* c = _create_component_map()[ type ]();
	c->SetData( data );

	// result.second indicates success
	std::pair< BaseComponentPtrSet::iterator, bool > result =
		_entity_map[ e ].insert( c );
	if( !result.second )
	{
		c->~BaseComponent();
		_aligned_free( c );
		c = 0;
	}
	else
	{
		// The insertion succeeded, so we need to add the entity to the 
		// component's list now
		_component_type_map[ type ].insert( e );
	}
}
示例#3
0
bool ObjectManager::AddFuelComponent(int objectNumber, SMapSquare fuelPoint)
{
	BaseComponent* newComponent = new FuelPatrolComponent(Objects.at(objectNumber), myMap, fuelPoint);
	vector<string> newComponentRequirements = newComponent->GetRequiredComponents();
	Object* object = Objects.at(objectNumber);

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		//check if there is already an override of this type
		if (object->CheckForComponant("PatrolAIOverride"))
		{
			//delete the existing component and replace it
			delete object->GetComponentPointer("PatrolAIOverride");
		}

		object->AddComponant("PatrolAIOverride", newComponent);
		return true;
}
示例#4
0
bool MonsterDevil::onContactBegin(cocos2d::PhysicsContact& contact)
{
	auto bodyA = contact.getShapeA()->getBody();
	auto bodyB = contact.getShapeB()->getBody();
	auto componentA = (BaseComponent*)bodyA->getNode();
	auto componentB = (BaseComponent*)bodyB->getNode();
	BaseComponent* enemyComponent;
	bool isComponentA = true;


	//어떤것 끼리 부딪혔는지는 안가르쳐주기 때문에
	//여기서 어느쪽이 monsterDevil인지 밝혀낸다.
	if (componentA->getType() == getType())
	{
		enemyComponent = componentB;
		isComponentA = true;
	}
	else
	{
		enemyComponent = componentA;
		isComponentA = false;
	}


	//FLOOR 충돌 무시 
	if (enemyComponent->getType() == OT_FLOOR)
	{
		return false;
	}

	//미사일이랑 충돌 처리
	if (enemyComponent->getPhysicsBody()->getCategoryBitmask() == PHYC_MISSILE)
	{
		Missile* missile = static_cast<Missile*>(enemyComponent);

		//수류탄은 뎀 안 입음
		if (missile->getType() == OT_MISSILE_GRENADE)
		{
			return false;
		}

		//몹이 쏜 건 안 맞음.
		if (!missile->isPlayerMissile())
		{
			return false;
		}

		float damage = missile->getDamage();

		m_Info.m_CurrentHp -= damage * 100 / (100 + m_Info.m_DefensivePower);

		//사망
		if (m_Info.m_CurrentHp <= 0)
		{
			m_IsDead = true;
		}
	}
	return true;
}
示例#5
0
	// Get component name
	int LuaEnv_Component::GetComponentName(LuaEnvironment &env)
	{
		// First argument is self
		BaseComponent *comp = env.readArg<BaseComponent*>("Saurobyte_Component");

		env.pushArgs(comp->getName());
		return 1;
	}
	// Getter for component values
	int LuaEnv_Component::GetComponentValue(lua_State *state)
	{
		// First argument is self
		BaseComponent *comp = LuaEnvironment::convertUserdata<BaseComponent>(state, 1, "jl.Component");

		// Second argument is value identifier
		std::string valueName = luaL_checkstring(state, 2);

		return comp->onLuaGet(valueName, state);
	}
示例#7
0
	// Getter for component values
	int LuaEnv_Component::GetComponentValue(LuaEnvironment &env)
	{
		// First argument is self
		BaseComponent *comp = env.readArg<BaseComponent*>("Saurobyte_Component");

		// Second argument is value identifier
		std::string valueName = env.readArg<std::string>();

		return comp->onLuaGet(valueName, env);
	}
	// Setter for component values
	int LuaEnv_Component::SetComponentValue(lua_State *state)
	{
		// First argument is self
		BaseComponent *comp = LuaEnvironment::convertUserdata<BaseComponent>(state, 1, "jl.Component");

		// Second argument is value identifier
		std::string valueName = luaL_checkstring(state, 2);

		// Third values and so forth are optional arguments handled in
		// the component. But we will remove first and second args
		// to make it easier on the users end.
		lua_remove(state, 1); // Pop two front elements
		lua_remove(state, 1);

		comp->onLuaSet(valueName, state);
		return 0;
	}
示例#9
0
	// Setter for component values
	int LuaEnv_Component::SetComponentValue(LuaEnvironment &env)
	{
		// First argument is self
		BaseComponent *comp = env.readArg<BaseComponent*>("Saurobyte_Component");

		// Second argument is value identifier
		std::string valueName = env.readArg<std::string>();

		// Third values and so forth are optional arguments handled in
		// the component. But we will remove first and second args
		// to make it easier on the users end.
		//lua_remove(state, 1); // Pop two front elements
		//lua_remove(state, 1);

		comp->onLuaSet(valueName, env);
		return 0;
	}
示例#10
0
bool ObjectManager::AddBasicAIComponent(int objectNumber, vector<SCoord> patrolPath)
{
	BaseComponent* newComponent = new BasicAIComponent(Objects.at(objectNumber), myMap,patrolPath);
	vector<string> newComponentRequirements = newComponent->GetRequiredComponents();
	Object* object = Objects.at(objectNumber);

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

	Objects.at(objectNumber)->AddComponant("BasicAIComponent", newComponent);
	return true;
}
示例#11
0
bool RushPig::onContactBegin(cocos2d::PhysicsContact& contact)
{
	auto bodyA = contact.getShapeA()->getBody();
	auto bodyB = contact.getShapeB()->getBody();
	auto componentA = (BaseComponent*)bodyA->getNode();
	auto componentB = (BaseComponent*)bodyB->getNode();
	BaseComponent* enemyComponent;
	bool isComponentA = true;

	if (componentA->getType() == getType())
	{
		enemyComponent = componentB;
		isComponentA = true;
	}
	else
	{
		enemyComponent = componentA;
		isComponentA = false;
	}

	//미사일이랑 충돌 처리
	if (enemyComponent->getPhysicsBody()->getCategoryBitmask() == PHYC_MISSILE)
	{
		Missile* missile = static_cast<Missile*>(enemyComponent);

		float damage = missile->getDamage();

		m_Info.m_CurrentHp -= damage * 100 / (100 + m_Info.m_DefensivePower);

		cocos2d::log("HP : %d / %d", m_Info.m_CurrentHp, m_Info.m_MaxHp);
		//사망
		if (m_Info.m_CurrentHp <= 0)
		{
			m_IsDead = true;
		}
	}
	return true;
}
示例#12
0
void Player::Raycast(const GameContext& gameContext)
{
	GameScene* scene = GetScene();

	XMFLOAT3 pos = GetTransform()->GetPosition();
	XMFLOAT3 fw = GetTransform()->GetForward();
	PxVec3 rayOrigin(pos.x,pos.y + 1.f,pos.z), rayDirection(fw.x,fw.y,fw.z);
	rayOrigin.x += fw.x * 2.5f;
	rayOrigin.z += fw.z * 2.5f;

	const PxU32 bufSize = 20;
	PxRaycastHit hit[bufSize];
	PxRaycastBuffer buf(hit, bufSize); // [out] Blocking and touching hits will be stored here

	if(scene->GetPhysxProxy()->Raycast(rayOrigin, rayDirection, 5000, buf))
	{
		for(PxU32 i = 0; i < buf.nbTouches; ++i)
		{
			BaseComponent* component = static_cast<BaseComponent*>(buf.touches[i].actor->userData);
			GameObject* go = component->GetGameObject();
			string name = go->GetName();	
			cout << "RAYCAST OBJECT: " << name << endl;		

			if(name == "Enemy")
			{
				Enemy* enemy = reinterpret_cast<Enemy*>(go);
				int dmg = 12.5f;
				enemy->Damage(dmg);
			}
		}

		PxVec3 vel = rayDirection * 1000;
		auto laser = new Laser(XMFLOAT3(vel.x, vel.y, vel.z));
		AddChild(laser);
	}
}
示例#13
0
bool MonsterRush::onContactBegin(cocos2d::PhysicsContact& contact)
{
	auto bodyA = contact.getShapeA()->getBody();
	auto bodyB = contact.getShapeB()->getBody();
	auto componentA = (BaseComponent*)bodyA->getNode();
	auto componentB = (BaseComponent*)bodyB->getNode();
	BaseComponent* enemyComponent;
	bool isComponentA = true;

	if (componentA->getType() == getType())
	{
		enemyComponent = componentB;
		isComponentA = true;
	}
	else
	{
		enemyComponent = componentA;
		isComponentA = false;
	}

	//미사일이랑 충돌 처리
	if (enemyComponent->getPhysicsBody()->getCategoryBitmask() == PHYC_MISSILE)
	{
		Missile* missile = static_cast<Missile*>(enemyComponent);

		//수류탄은 뎀 안 입음
		if (missile->getType() == OT_MISSILE_GRENADE)
		{
			return false;
		}

		//몹이 쏜 건 안 맞음.
		if (!missile->isPlayerMissile())
		{
			return false;
		}

		float damage = missile->getDamage();

		m_Info.m_CurrentHp -= damage * 100 / (100 + m_Info.m_DefensivePower);

		//미사일에 의한 상태 이상 처리

		if (missile->getState() == Missile::MST_KNOCKBACK)
		{
			GET_SOUND_MANAGER()->createSound(SoundManager::PIG, false);
			m_KnockbackStartTime = GET_GAME_MANAGER()->getMicroSecondTime();
			if (missile->getAttackDir() == DIR_LEFT)
			{
				CommonState::enterKnockback(this, DIR_LEFT);
			}
			else
			{
				CommonState::enterKnockback(this, DIR_RIGHT);
			}

			setState(0,STAT_KNOCKBACK);
		}
		else if (missile->getState() == Missile::MST_BIND)
		{
			m_KnockbackStartTime = GET_GAME_MANAGER()->getMicroSecondTime();
			getPhysicsBody()->setVelocity(cocos2d::Vect(0, 0));
			setState(0,STAT_KNOCKBACK);
		}

		//사망
		if (m_Info.m_CurrentHp <= 0)
		{
			m_IsDead = true;
		}
	}

	//플레이어랑 부딪친 경우 이펙트 생성
	if (enemyComponent->getType() == OT_PLAYER)
	{
		GET_EFFECT_MANAGER()->createEffect(ET_PUNCH_MISSILE, enemyComponent->getPosition())->enter();
	}
	return true;
}
示例#14
0
bool ObjectManager::AddComponent(string ComponentType, int objectNumber, string mesh, float X, float Y, float Z)
{
	BaseComponent* newComponent;
	vector<string> newComponentRequirements;
	Object* object = Objects.at(objectNumber);

	if (ComponentMap.find(ComponentType) != ComponentMap.end()) // if we have the requested component
	{
		string name;
		//create the new component and get it's requiremernts
		newComponent = ComponentMap[ComponentType](object ,myMap);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//Set override name for components
		if (ComponentType == "ChargeAttackComponent")
		{
			name = "AttackAIOverride";
		}
		else if (ComponentType == "BlockSearchComponent")
		{
			name = "SearchAIOverride";
		}
		else 
		{
			name  = ComponentType;
		}

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}


		//add the component to the object and give a pointer to the object to the component
		object->AddComponant(name,newComponent);
		return true;
	}
	else if(ComponentType == "ModelComponent") // exception as this component requires a mesh and co-ordinates
	{
		//create the model from the mesh
		tle::IModel* model = MeshMap[mesh]->CreateModel(X,Y,Z);
		//create a new component with this model
		newComponent = new ModelComponent(Objects.at(objectNumber), model);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		//add the model to the component
		object->AddComponant(ComponentType,newComponent);
		return true;
	}
	else if(ComponentType == "ControlComponent")
	{
		newComponent = new ControlComponent(Objects.at(objectNumber), myEngine);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		object->AddComponant(ComponentType, newComponent);
	}
	else if (ComponentType == "InfoPanelComponent")
	{
		newComponent = new InfoPanelComponent(Objects.at(objectNumber), myEngine);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		object->AddComponant(ComponentType, newComponent);
	}
	else
	{
		//everything failed, return false
		return false;
	}
}