Exemplo n.º 1
0
void LoadHeightmap(char *filename)
{
	uint x, y;
	byte *map = NULL;

	if (!ReadHeightMap(filename, &x, &y, &map)) {
		free(map);
		return;
	}

	GrayscaleToMapHeights(x, y, map);
	free(map);

	FixSlopes();
	MarkWholeScreenDirty();
}
Exemplo n.º 2
0
/**
 * Load a heightmap from file and change the map in his current dimensions
 *  to a landscape representing the heightmap.
 * It converts pixels to height. The brighter, the higher.
 * @param dft Type of image file.
 * @param filename of the heightmap file to be imported
 */
void LoadHeightmap(DetailedFileType dft, const char *filename)
{
	uint x, y;
	byte *map = nullptr;

	if (!ReadHeightMap(dft, filename, &x, &y, &map)) {
		free(map);
		return;
	}

	GrayscaleToMapHeights(x, y, map);
	free(map);

	FixSlopes();
	MarkWholeScreenDirty();
}
Exemplo n.º 3
0
bool GetHeightmapDimensions(char *filename, uint *x, uint *y)
{
	return ReadHeightMap(filename, x, y, NULL);
}
Exemplo n.º 4
0
/**
 * Get the dimensions of a heightmap.
 * @param dft Type of image file.
 * @param filename to query
 * @param x dimension x
 * @param y dimension y
 * @return Returns false if loading of the image failed.
 */
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
{
	return ReadHeightMap(dft, filename, x, y, nullptr);
}
Exemplo n.º 5
0
void SceneBase::UpdateMovement(double dt)
{
	player.camera.Update(dt, TERRAIN_SCALE.y * ReadHeightMap(m_heightMap, player.camera.getPosition().x/TERRAIN_SCALE.x, player.camera.getPosition().z/TERRAIN_SCALE.z));
}
Exemplo n.º 6
0
void SceneBase::UpdateCollisions(double dt)
{
	// check player with world bound
	if (player.camera.getPosition().x >= TERRAIN_SCALE.x * 0.45f || player.camera.getPosition().x <= -TERRAIN_SCALE.x * 0.45f
		|| player.camera.getPosition().z >= TERRAIN_SCALE.z * 0.45f || player.camera.getPosition().z <= -TERRAIN_SCALE.z * 0.45f)
	{
		player.camera.Reset();
	}

	if (player.camera.getPosition().x >= TERRAIN_SCALE.x * 0.35f || player.camera.getPosition().x <= -TERRAIN_SCALE.x * 0.35f
		|| player.camera.getPosition().z >= TERRAIN_SCALE.z * 0.35f || player.camera.getPosition().z <= -TERRAIN_SCALE.z * 0.35f)
	{
		leaving = true;
	}

	else
	{
		leaving = false;
	}

	// check player with environment
	/*for(std::vector<threeDObject *>::iterator it = environmentList.begin(); it != environmentList.end(); ++it)
	{
	threeDObject *go = (threeDObject *)*it;
	if(go->getRender())
	{
	string boxName = "";
	if (check3DCollision(player.getHitBox(), go->getHitBox(), boxName))
	{
	if(player.getPosition().z < go->getPosition().z)
	{
	player.camera.moveBackward(dt, TERRAIN_SCALE.y * ReadHeightMap(m_heightMap, player.camera.getPosition().x/TERRAIN_SCALE.x, player.camera.getPosition().z/TERRAIN_SCALE.z));
	}

	else
	{
	player.camera.moveForward(dt, TERRAIN_SCALE.y * ReadHeightMap(m_heightMap, player.camera.getPosition().x/TERRAIN_SCALE.x, player.camera.getPosition().z/TERRAIN_SCALE.z));
	}
	}
	}
	}*/

	for(std::vector<Bullet *>::iterator it = bulletList.begin(); it != bulletList.end(); ++it)
	{
		Bullet *go = (Bullet *)*it;
		if(go->getRender())
		{
			// check bullet with terrain
			if(go->getPosition().y < TERRAIN_SCALE.y * ReadHeightMap(m_heightMap, go->getPosition().x/TERRAIN_SCALE.x, go->getPosition().z/TERRAIN_SCALE.z))
			{
				go->setRender(false);
				go->setStatus(false);
				break;
			}

			// check with environment obj
			for(std::vector<threeDObject *>::iterator it2 = environmentList.begin(); it2 != environmentList.end(); ++it2)
			{
				threeDObject *go2 = (threeDObject *)*it2;

				if(go2->getRender())
				{
					if ((go->getHitBox().getMidPoint() - go2->getHitBox().getMidPoint()).Length() <= 30.f)
					{
						string boxName = "";
						if (check3DCollision(go->getHitBox(), go2->getHitBox(), boxName))
						{
							go->setRender(false);
							go->setStatus(false);
							break;
						}
					}
				}
			}

			// check with aliens
			for(std::vector<Character *>::iterator it2 = characterList.begin(); it2 != characterList.end(); ++it2)
			{
				Character *go2 = (Character *)*it2;

				if(go2->getRender())
				{
					if ((go->getHitBox().getMidPoint() - go2->getHitBox().getMidPoint()).Length() <= 30.f)
					{
						string boxName = "";
						if (check3DCollision(go->getHitBox(), go2->getHitBox(), boxName))
						{
							go->setRender(false);
							go->setStatus(false);
							go2->m_iHealth -= player.bagpack.currentWeapon->getDmg();
							break;
						}
					}
				}
			}
		}
	}

	//check aliens with aliens
	for(std::vector<Character *>::iterator it = characterList.begin(); it != characterList.end(); ++it)
	{
		Character *go = (Character *)*it;
		if(go->getRender())
		{
			for(std::vector<Character *>::iterator it2 = it + 1; it2 != characterList.end(); ++it2)
			{
				Character *go2 = (Character *)*it2;
				if (go2->getRender())
				{
					if ((go->getPosition() - go2->getPosition()).Length() < go->getHitBox().getLength() * 2)
					{
						Vector3 firstDir = (go->getPosition() - go2->getPosition()).Normalized();
						float dist = (go->getPosition() - go2->getPosition()).Length();

						go->camera.setTarget(go->camera.getTarget() + firstDir * (1.f / dist) * REPULSE_FORCE * dt);
						go2->camera.setTarget(go2->camera.getTarget() + (-firstDir) * (1.f / dist) * REPULSE_FORCE * dt);
					}
				}
			}
		}
	}

	//check player with aliens
	for(std::vector<Character *>::iterator it = characterList.begin(); it != characterList.end(); ++it)
	{
		Character *go = (Character *)*it;
		if(go->getRender())
		{
			if ((go->getHitBox().getMidPoint() - player.getHitBox().getMidPoint()).Length() <= 30.f)
			{
				UpdateSoundStatus('m');
				string boxName = "";
				if (check3DCollision(player.getHitBox(), go->getHitBox(), boxName))
				{
					player.m_iHealth -= 1;
					UpdateCameraStatus(32);
					UpdateSoundStatus('0');
					break;
				}
			}
		}
	}
}
Exemplo n.º 7
0
void SceneBase::UpdateCharacters(double dt)
{
	TRS = player.getProperties();
	TRS.rotation.SetToRotation(player.camera.rotationY, 0, 1, 0);
	player.setTRS(TRS);
	player.setPosition(player.camera.getPosition());
	player.updateHitbox();
	ResetTRS(TRS);

	if (player.m_iHealth <= 0)
	{
		player.m_iHealth = 0;
		gameOver = true;
	}

	// update more enemies if wave clear

	if (timer >= startTimer)
	{
		if(enemyCount == 0)
		{
			wave += 1;
			maxEnemy = wave * 3;

			for(unsigned i = enemyCount; i < maxEnemy; ++i)
			{
				float xCoord = Math::RandFloatMinMax(-TERRAIN_SCALE.x * 0.5f, TERRAIN_SCALE.x * 0.5f);
				float zCoord = Math::RandFloatMinMax(-TERRAIN_SCALE.z * 0.5f, TERRAIN_SCALE.z * 0.5f);
				Character* alien = fetchCharacter();
				alien->setMesh(meshList[GEO_ALIEN]);
				alien->setHitBox(threeDhitbox(Vector3(0, 0, 0), 13.8f, 27.8f, 19.f, "alien"));
				alien->setPosition(Vector3(xCoord, TERRAIN_SCALE.y * ReadHeightMap(m_heightMap, xCoord/TERRAIN_SCALE.x, zCoord/TERRAIN_SCALE.z) - 5.f, zCoord));
				alien->enemyTarget = &player;
				alien->m_iHealth = 10 * wave;
				alien->m_iID = 1;
				alien->camera.Init(alien->getPosition(), player.getPosition(), Vector3(0, 1, 0));

				++enemyCount;

				newAvatar.setAvatar(MeshBuilder::GenerateQuad("MinimapAvatar", Color(1, 1, 1), 1.f));
				newAvatar.setPosition(alien->getPosition().x / TERRAIN_SCALE.x * MINIMAP_SCALE, alien->getPosition().z / TERRAIN_SCALE.z * MINIMAP_SCALE);
				newAvatar.getAvatar()->textureID[0] = LoadTGA("Image//enemyAvatar.tga");
				m_Minimap->enemyList.push_back(newAvatar);
			}
		}

		for(std::vector<Character *>::iterator it = characterList.begin(); it != characterList.end(); ++it)
		{
			Character *go = (Character *)*it;
			if(go->getRender())
			{
				// chase after target
				TRS = go->getProperties();
				float theta = Math::RadianToDegree(atan2(go->camera.getView().x, go->camera.getView().z));
				TRS.rotation.SetToRotation(theta, 0, 1, 0);
				go->setTRS(TRS);
				if (go->camera.getTarget() != go->camera.getPosition())
				{
					go->camera.moveForward(dt, TERRAIN_SCALE.y * ReadHeightMap(m_heightMap, go->camera.getPosition().x/TERRAIN_SCALE.x, go->camera.getPosition().z/TERRAIN_SCALE.z) - 5.f);
				}
				go->camera.setTarget(player.getPosition());
				go->setPosition(go->camera.getPosition());

				go->updateHitbox();

				if(go->m_iHealth <= 0)
				{
					go->setRender(false);

					int dropBonus = Math::RandIntMinMax(1, 3);

					if (dropBonus == 3)
					{
						itemBonus = Math::RandIntMinMax(1, 3);

						// increase pistol ammo
						if (itemBonus == 1)
						{
							player.bagpack.pistol.setAmmo(player.bagpack.pistol.getAmmo() + 30);
						}

						// increase rifle ammo
						else if (itemBonus == 2)
						{
							player.bagpack.rifle.setAmmo(player.bagpack.rifle.getAmmo() + 30);
						}

						else if(player.m_iHealth < 100)
						{
							// increase health by 30 if health less than 70
							if (player.m_iHealth < 70)
							{
								player.m_iHealth += 10;
							}

							// recover health to full health
							else
							{
								player.m_iHealth = 100;
							}
						}

						UpdateSoundStatus('p');
					}

					else
					{
						itemBonus = 0;
					}

					//remove enemy from minimap
					int pos = it - characterList.begin();

					m_Minimap->enemyList[pos].setRender(false);

					--enemyCount;
				}
			}
		}
	}
}
Exemplo n.º 8
0
// Check height of terrain
const float CPhysics::GetHeightMapY(float x, float z, std::vector<unsigned char> &heightMap,const Vector3& terrainSize )
{
	return m_fOffset* (ReadHeightMap(heightMap, x/terrainSize.x, z/terrainSize.z));
}