Esempio n. 1
0
	void UpdateLogic()
	{
		// Update pacman Character Object logic
		Pacman.UpdateLogic();
		// Update pacman collision check
		for (int counter = 0; counter < gameObjectCount; counter++)
		{
			Pacman.CollisionLogic(gameObject[counter]);
		}
	}
Esempio n. 2
0
void VehicleObject::ejectAll()
{
	for(std::map<size_t, GameObject*>::iterator it = seatOccupants.begin();
		it != seatOccupants.end();
	) {
		if(it->second->type() == GameObject::Character) {
			CharacterObject* c = static_cast<CharacterObject*>(it->second);
			c->setCurrentVehicle(nullptr, 0);
			c->setPosition(getPosition());
		}
		it = seatOccupants.erase(it);
	}
}
Esempio n. 3
0
	void DrawLevel(ALLEGRO_DISPLAY *screen)
	{
		score = 0;
		// Draw level objects
		for (int loopCounter = 0; loopCounter < gameObjectCount; loopCounter++)
		{

			gameObject[loopCounter].DrawObject();


			switch (gameObject[loopCounter].type)
			{
			case FOOD:
			{
				//gameObject[loopCounter].alive = false;
				bool f;
				f = gameObject[loopCounter].alive;
				if (f == false)
				{
					score++;
					//cout << score << endl;
				}

				break;
			}
			}

		}

		// Draw pacman Character Object
		Pacman.DrawObject(screen);

	}
Esempio n. 4
0
Menu DebugState::createDebugMenu() {
    CharacterObject* player = nullptr;
    if (game->getWorld()->getPlayer()) {
        player = game->getWorld()->getPlayer()->getCharacter();
    }

    Menu menu{
        {{"Jump to Debug Camera",
          [=] {
              jumpCharacter(game, player,
                            _debugCam.position +
                                _debugCam.rotation * glm::vec3(3.f, 0.f, 0.f),
                            false);
          }},
         {"-Map", [=] { setNextMenu(createMapMenu()); }},
         {"-Vehicles", [=] { setNextMenu(createVehicleMenu()); }},
         {"-AI", [=] { setNextMenu(createAIMenu()); }},
         {"-Weapons", [=] { setNextMenu(createWeaponMenu()); }},
         {"-Weather", [=] { setNextMenu(createWeatherMenu()); }},
         {"-Missions", [=] { setNextMenu(createMissionsMenu()); }},
         {"Set Super Jump", [=] { player->setJumpSpeed(20.f); }},
         {"Set Normal Jump",
          [=] { player->setJumpSpeed(CharacterObject::DefaultJumpSpeed); }},
         {"Full Health", [=] { player->getCurrentState().health = 100.f; }},
         {"Full Armour", [=] { player->getCurrentState().armour = 100.f; }},
         {"Cull Here",
          [=] { game->getRenderer().setCullOverride(true, _debugCam); }}},
        kDebugMenuOffset,
        kDebugFont,
        kDebugEntryHeight};

    // Optional block if the player is in a vehicle
    auto cv = player->getCurrentVehicle();
    if (cv) {
        menu.lambda("Flip vehicle", [=] {
            cv->setRotation(cv->getRotation() *
                            glm::quat(glm::vec3(0.f, glm::pi<float>(), 0.f)));
        });
    }

    return menu;
}
Esempio n. 5
0
	void DrawLevel(ALLEGRO_DISPLAY *screen)
	{
		// Draw level objects
		for (int counter = 0; counter < gameObjectCount; counter++)
		{
			gameObject[counter].DrawObj();
		}

		// Draw pacman Character Object
		Pacman.DrawObj(screen);

	}
Esempio n. 6
0
	// Method to Initialize Level
	void level1()
	{
		Pacman.image = al_load_bitmap("Pacman_Sprite_Sheet.PNG"); // Loading pacman sprite sheet
		Pacman.X = SCREEN_W / 2; // Starting x-coordinate of pacman on the screen
		Pacman.Y = SCREEN_H / 2; // Starting y-coordinate of pacman on the screen
		Pacman.S = 2.0; // Movement S of pacman
		Pacman.NumbOfFrames = 2; // Total number of pacman animation frames in the sprite sheet
		Pacman.frameDelay = 7; // S of pacman animation
		Pacman.InitObject(); // Initialize pacman

		gameObject = new GameObject[(SCREEN_W / TILE_SIZE) * (SCREEN_H / TILE_SIZE)];
		gameObjectCount = 0;

		Food = al_load_bitmap("food.png");
		Block = al_load_bitmap("block.png");

		Level = al_fopen("level_1.data", "r");

		// Loading and initializing Level & Game Objects
		for (int R = 0; R < SCREEN_H / TILE_SIZE; R++)
		{
			for (int C = 0; C < SCREEN_W / TILE_SIZE; C++)
			{
				levelGrid[R][C] = al_fgetc(Level);
				switch (levelGrid[R][C])
				{
				case 10:
					C--;
					break;
				case 49:
					gameObject[gameObjectCount].InitObject(Block, C * TILE_SIZE, R * TILE_SIZE, BLOCK);
					gameObjectCount++;
					break;
				case 48:
					gameObject[gameObjectCount].InitObject(Food, C * TILE_SIZE, R * TILE_SIZE, FOOD);
					gameObjectCount++;
					break;
				}
			}
		}

	}
Esempio n. 7
0
	// Method to Initialize Level 
	void InitLevel()
	{
		Pacman.image = al_load_bitmap("Pacman_Sprite_Sheet.PNG"); // Loading pacman sprite sheet
		Pacman.posX = SCREEN_W / 2; // Starting x-coordinate of pacman on the screen
		Pacman.posY = SCREEN_H / 1.45; // Starting y-coordinate of pacman on the screen
		Pacman.speed = 2.0; // Movement speed of pacman
		Pacman.totalFrame = 2; // Total number of pacman animation frames in the sprite sheet
		Pacman.frameDelay = 7; // Speed of pacman animation
		Pacman.InitObject(); // Initialize pacman 

		gameObject = new GameObject[(SCREEN_W / TILE_SIZE) * (SCREEN_H / TILE_SIZE)];
		gameObjectCount = 0;

		foodSprite = al_load_bitmap("food.png");
		blockSprite = al_load_bitmap("block.png");

		levelData = al_fopen("level_2.data.txt", "r");

		// Loading and initializing Level & Game Objects
		for (int row = 0; row < SCREEN_H / TILE_SIZE; row++)
		{
			for (int column = 0; column < SCREEN_W / TILE_SIZE; column++)
			{
				levelGrid[row][column] = al_fgetc(levelData);
				switch (levelGrid[row][column])
				{
				case 10:
					column--;
					break;
				case 49:
					gameObject[gameObjectCount].InitObject(blockSprite, column * TILE_SIZE, row * TILE_SIZE, BLOCK);
					gameObjectCount++;
					break;
				case 48:
					gameObject[gameObjectCount].InitObject(foodSprite, column * TILE_SIZE, row * TILE_SIZE, FOOD);
					gameObjectCount++;
					break;
				}
			}
		}

	}
void CharacterController::SetTargetCharacter(CharacterObject & chara) {

	m_pCharacter = &chara;

	auto sprite = new SpriteObject();
	m_pCharacter->AddChild(sprite);
	//sprite->SetTexture();

	if (m_pBinding)
		m_pBinding->SetTargetArmature(chara.Armature());

	auto& behavier = chara.Behavier();
	auto& armature = chara.Armature();
	auto& clips = behavier.Clips();
	auto& parts = m_charaParts;
	parts.SetArmature(armature);

	m_SIKs.resize(parts.size());
	for (size_t i = 0; i < m_SIKs.size(); i++)
	{
		m_SIKs[i].reset(new StylizedChainIK(parts[i]->Joints.size()));
	}

	PotientialFrame = armature.default_frame();
	m_charaFrame = armature.default_frame();
	m_PvHandles.resize(armature.size());

	parts.ComputeWeights();
	if (!g_UseJointLengthWeight)
	{
		for (auto& part : parts)
		{
			part->Wx.setOnes();
			part->Wxj.setOnes();
		}
	}

	behavier.UniformQuaternionsBetweenClips();

	for (auto& anim : clips)
	{
		if (anim.Name == "idle" || anim.Name == "die")
			anim.IsCyclic = false;
		else
			anim.IsCyclic = true;
	}

	{
		cout << chara.Name << " Armature Parts" << endl;
		int i = 0;
		for (auto pPart : parts)
		{
			auto& part = *pPart;
			cout << "Part[" << i++ << "] = " << part.Joints;
			if (part.SymetricPair != nullptr)
			{
				cout << " <--> {" << part.SymetricPair->Joints[0] << "...}";
			}
			cout << endl;
		}
	}

	//clips.erase(std::remove_if(BEGIN_TO_END(clips), [](const auto& anim) ->bool {return !anim.IsCyclic;}), clips.end());

	using namespace concurrency;
	vector<task<void>> tasks;
	m_Clipinfos.reserve(clips.size() + 1);
	{
		tasks.emplace_back(create_task([this]() {
			auto& chara = *m_pCharacter;
			auto& behavier = chara.Behavier();
			auto& parts = m_charaParts;

			auto allFrames = CreateReinforcedFrames(behavier);

			//? To-Do Setup proper feature for m_cpxClipinfo
			m_cpxClipinfo.Initialize(parts);
			// set subactive energy to almost zero that make sure all part's pca is caculated
			//m_cpxClipinfo.RcFacade.SetActiveEnergy(g_CharacterActiveEnergy, g_CharacterSubactiveEnergy * 0.01f);
			//m_cpxClipinfo.PvFacade.SetActiveEnergy(g_CharacterActiveEnergy, g_CharacterSubactiveEnergy * 0.01f);
			m_cpxClipinfo.AnalyzeSequence(allFrames, 0);
		}));
	}

	for (auto& anim : clips)
	{
		if (!anim.Cyclic())
			continue;

		m_Clipinfos.emplace_back(m_charaParts);
		auto& clipinfo = m_Clipinfos.back();

		clipinfo.SetClipName(anim.Name);

		tasks.emplace_back(create_task([&clipinfo, &anim, &parts]() {
			clipinfo.Initialize(parts);
			auto & frames = anim.GetFrameBuffer();
			clipinfo.AnalyzeSequence(frames, anim.Length().count());
		}));
	}

	when_all(tasks.begin(), tasks.end()).then([this]() {

		auto& chara = *m_pCharacter;
		auto& behavier = chara.Behavier();
		auto& clips = behavier.Clips();
		auto& parts = m_charaParts;

		cout << setprecision(4) << setw(6);
		auto& allClipinfo = m_cpxClipinfo;

		tinyxml2::XMLDocument paramdoc;
		tinyxml2::XMLElement* settings = nullptr;
		if (exists(g_CharacterAnalyzeDir))
		{
			create_directory(g_CharacterAnalyzeDir);
		}

		string paramFileName = (g_CharacterAnalyzeDir / (m_pCharacter->Name + ".param.xml")).string();
		stringstream ss;
		ss << "cr_" << CLIP_FRAME_COUNT << "_vel" << (int)g_UseVelocity << "_wj" << g_UseJointLengthWeight;
		string settingName;

		for (auto& cinfo : m_Clipinfos)
			ss << '_' << cinfo.ClipName();

		settingName = ss.str();

		if (g_LoadCharacterModelParameter)
		{
			auto error = paramdoc.LoadFile(paramFileName.c_str());
			tinyxml2::XMLElement* paramStore = nullptr;
			if (error == tinyxml2::XML_SUCCESS)
			{
				paramStore = paramdoc.RootElement();
			}

			if (paramStore == nullptr)
			{
				paramStore = paramdoc.NewElement("param_store");
				paramdoc.InsertFirstChild(paramStore);
			}

			settings = paramStore->FirstChildElement(settingName.c_str());

			if (settings == nullptr)
			{
				settings = paramdoc.NewElement(settingName.c_str());
				paramStore->InsertEndChild(settings);
			}
		}

		float globalEnergyMax = 0;
		for (auto& clipinfo : m_Clipinfos)
		{
			assert(clipinfo.IsReady());

			auto& Eb = clipinfo.PvFacade.GetAllPartsEnergy();
			globalEnergyMax = std::max(Eb.maxCoeff(), globalEnergyMax);

			//DEBUGOUT(Eb);
		}

		std::set<int> avtiveSet;
		std::set<int> subactSet;
		for (auto& clipinfo : m_Clipinfos)
		{
			auto& key = clipinfo.ClipName();
			auto& Eb = clipinfo.PvFacade.GetAllPartsEnergy();

			for (int i = 0; i < Eb.size(); i++)
			{
				if (Eb[i] > g_CharacterActiveEnergy * globalEnergyMax)
				{
					parts[i]->ActiveActions.push_back(key);
					avtiveSet.insert(i);

					// if a part is alreay marked as subactive, promote it
					auto itr = subactSet.find(i);
					if (itr != subactSet.end())
						subactSet.erase(itr);
				}
				else if (avtiveSet.find(i) == avtiveSet.end() && Eb[i] > g_CharacterSubactiveEnergy * globalEnergyMax)
				{
					parts[i]->SubActiveActions.push_back(key);
					subactSet.insert(i);
				}
			}
		}

		// Remove Root from caculation
		avtiveSet.erase(0);
		subactSet.erase(0);
		parts[0]->ActiveActions.clear();
		parts[0]->SubActiveActions.clear();

		m_ActiveParts.assign(BEGIN_TO_END(avtiveSet));
		m_SubactiveParts.assign(BEGIN_TO_END(subactSet));
		vector<int>& activeParts = m_ActiveParts;
		vector<int>& subactParts = m_SubactiveParts;

		cout << "== Active parts ==" << endl;
		for (auto& ap : activeParts)
			cout << parts[ap]->Joints << endl;
		cout << "== Subactive parts ==" << endl;
		for (auto& ap : subactParts)
			cout << parts[ap]->Joints << endl;
		cout << "== End Parts =" << endl;

		// Active parts Pv s
		MatrixXf Xabpv = GenerateXapv(activeParts);
		int dXabpv = Xabpv.cols();

		parallel_for(0, (int)activeParts.size(), 1, [&, this](int apid)
		{
			InitializeAcvtivePart(*parts[activeParts[apid]], settings);
		}
		);

		if (g_LoadCharacterModelParameter)
		{
			auto error = paramdoc.SaveFile(paramFileName.c_str());
			assert(error == tinyxml2::XML_SUCCESS);
		}

		if (g_EnableDependentControl)
			parallel_for_each(BEGIN_TO_END(subactParts), [&, this](int sapid)
		{
			InitializeSubacvtivePart(*parts[sapid], Xabpv, settings);
		}
		);

		cout << "=================================================================" << endl;

		assert(g_UseStylizedIK);
		{
			//? To-Do, Fix this
			auto pBinding = make_unique<SelfLocalMotionTransform>(*this);
			pBinding->pHandles = &m_PvHandles;
			m_pSelfBinding = move(pBinding);
		}

		if (g_LoadCharacterModelParameter)
		{
			auto error = paramdoc.SaveFile(paramFileName.c_str());
			assert(error == tinyxml2::XML_SUCCESS);
		}

		IsReady = true;
	});
}
Esempio n. 9
0
int NetworkFunctions::spawnPlayer(DataBuffer * data)
{
	if (data == NULL || data->getSize() != 165) return -1;

	unsigned long netID;
	memcpy(&netID, &data->getData()[4], 4);

	int playerID = -1;
	memcpy(&playerID, &data->getData()[8], 4);

	if (playerID < 0 || playerID >= players->size()) return -1;
	if ((*players)[playerID] != NULL) {
		unsigned long netID = players->at(playerID)->getNetID();
		GameObject * tempObject = gameObjects->getValue(netID);
		if (tempObject == NULL) {
			//error
			int x = 123;
		}
		else {
			gameObjects->remove(netID);
			players->at(playerID) = NULL;
			delete tempObject;
		}
	}
		
	char modelName[32];
	//for (int i = 0; i < 32; i++) modelName[i] = '\0';
	memset(modelName, '\0', 32);
	memcpy(modelName, &data->getData()[12], 32);

	char textureName[32];
	//for (int i = 0; i < 32; i++) textureName[i] = '\0';
	memset(textureName, '\0', 32);
	memcpy(textureName, &data->getData()[44], 32);

	char shaderName[32];
	//for (int i = 0; i < 32; i++) shaderName[i] = '\0';
	memset(shaderName, '\0', 32);
	memcpy(shaderName, &data->getData()[76], 32);

	float posX = 0.0f, posY = 0.0f, posZ = 0.0f;
	memcpy(&posX, &data->getData()[108], 4);
	memcpy(&posY, &data->getData()[112], 4);
	memcpy(&posZ, &data->getData()[116], 4);

	float lookAtX = 0.0f, lookAtY = 0.0f, lookAtZ = 0.0f;
	memcpy(&lookAtX, &data->getData()[120], 4);
	memcpy(&lookAtY, &data->getData()[124], 4);
	memcpy(&lookAtZ, &data->getData()[128], 4);

	char propName[33];
	//for (int i = 0; i < 33; i++) propName[i] = '\0';
	memset(propName, '\0', 32);
	memcpy(propName, &data->getData()[132], 32);

	//164 is '\n'

	string modelPath = string(modelName) + ".obj";
	string texturePath = string(textureName) + ".tga";
	string shaderPath = string(shaderName) + ".glsl";
	string propPath = string(propName) + ".prop";

	CharacterObject * newCharacter = NULL;

	if (playerID == clientID)
		newCharacter = new PlayerObject(modelPath, texturePath, shaderPath, glm::vec3(posX, posY, posZ), glm::vec3(lookAtX, lookAtY, lookAtZ), glm::vec3(0, 1, 0), propPath, playerID, netID);
	else
		newCharacter = new CharacterObject(modelPath, texturePath, shaderPath, glm::vec3(posX, posY, posZ), glm::vec3(lookAtX, lookAtY, lookAtZ), glm::vec3(0, 1, 0), propPath, playerID, netID);

	players->at(playerID) = newCharacter;
	
	netID = newCharacter->getNetID();
	data->copy(4, &netID, 4);

	if (networkState == NETWORK_STATE_SERVER) eventPacketTCP->appendToSendBuffer(data->getData(), data->getSize()); //copy to send buffer
	return 0;
}