Exemple #1
0
/*virtual*/ void Bullet::Update(float dt) /*override*/
{
	SGD::Rectangle rect;
	rect.top = m_ptPosition.y;
	rect.left = m_ptPosition.x;
	rect.Resize(bulletSize*dist);
	TileLayer *layer0 = World::GetInstance()->GetTileLayers()[0];
	if (rect.top < 0.0f
		|| rect.left < 0.0f
		|| rect.bottom >= layer0->layerRows * layer0->GetTileSize().width
		|| rect.right >= layer0->layerColumns * layer0->GetTileSize().height
		)
	{
		return;
	}

	// if this bullet goes outside bullet dropoff range...
	if (owner->GetOwner() && (m_ptPosition - startPoint).ComputeLength() > bulletDropOff)
	{
		// create a message to destroy this bullet
		DestroyEntityMsg* msg = new DestroyEntityMsg(this);

		// dispatch the destroy message
		SGD::MessageManager::GetInstance()->GetInstance()->QueueMessage(msg);
	}

	if (gunActive)
	{
		dist += 0.075f;
		if (dist > 1.75f)
			dist = 1.75f;
	}

	// if bullet collides with tile, play collision sound
	//if (owner->GetGunType() != Weapon::GunType::meleeWeapon)
		
	// if not, update bullet
	Entity::Update(dt);

	TileLayer* collisionLayer = GameplayState::GetInstance()->GetWorld()->GetTileLayers()[1];
	const SGD::Point ref_position = { m_ptPosition.x + m_szSize.width*0.5f, m_ptPosition.y + m_szSize.height*0.5f };
	const int tileSize_width = (int)collisionLayer->GetTileSize().width;
	const int tileSize_height = (int)collisionLayer->GetTileSize().height;
	const int tilesWide = collisionLayer->layerColumns - 1;
	const int tilesHigh = collisionLayer->layerRows - 1;
	SGD::Point index = { Math::Clamp((ref_position.x / (float)tileSize_width), 0.f, (float)tilesWide), Math::Clamp(ref_position.y / (float)tileSize_height, 0.f, (float)tilesHigh) };

	Tile* tile_at = collisionLayer->GetTileAt(int(index.x), int(index.y));

	if (tile_at && !tile_at->isPassable)
	{
		if (tile_at->event != "bp" && owner->GetGunType() != Weapon::GunType::meleeWeapon && owner->GetGunType() != Weapon::GunType::MutantAtk)
		{
			SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->bulletImpact);
			DestroyEntityMsg* msg = new DestroyEntityMsg(this);
			msg->QueueMessage();
		}
	}
}
void EntityManager::RenderMinimap(void)
{
	// store default values for this function
	const SGD::Point scr_offset = SGD::Point(Game::GetInstance()->GetScreenWidth() - 200.0f, Game::GetInstance()->GetScreenHeight() - 160.f);
	const SGD::Size map_size = { 0.14f, 0.14f };

	// get a pointer to the camera
	Camera* camera = World::GetInstance()->GetCamera();

	// create matricies to translate from world space to screen space
	D3DXMATRIX scale;
	D3DXMatrixScaling(&scale, map_size.width, map_size.height, 0.f);
	D3DXMATRIX offset;
	D3DXMatrixTranslation(&offset, scr_offset.x, scr_offset.y, 0.f);
	D3DXMATRIX transform = World::GetInstance()->GetCamera()->GetMatrix() * scale * offset;

	// send the transform to the graphics manager
	SGD::GraphicsManager::GetInstance()->SetTransform(transform);

	// get the clipping rectangle for the mini map
	SGD::Rectangle rect = camera->GetRect();
	rect.Inflate(SGD::Size(200.f, 200.f));

	// draw the background of the mini map
	SGD::GraphicsManager::GetInstance()->DrawRectangle(rect, SGD::Color::Black);

	// store the collision layer
	TileLayer* collisionLayer = World::GetInstance()->GetTileLayers()[1];
	// store the visual layer
	TileLayer* visualLayer = World::GetInstance()->GetTileLayers()[0];

	// store tile width and height values
	float tile_width = collisionLayer->GetTileSize().width;
	float tile_height = collisionLayer->GetTileSize().height;

	// iterate y
	for (unsigned int y = (unsigned int)fabs(rect.top / tile_height); y < rect.bottom / tile_height; y++)
	{
		// iterate x
		for (unsigned int x = (unsigned int)fabs(rect.left / tile_width); x < rect.right / tile_width; x++)
		{

			// store the tile we're on now
			Tile* tile = collisionLayer->GetTileAt(x, y);

			if (!tile || !tile->isPassable)
				continue;

			// find the boundind rect of this tile
			SGD::Rectangle tile_rect = { x * tile_width, y * tile_height, x * tile_width + tile_width, y * tile_height + tile_height };

			// store alpha values for the edges of the screen
			float alpha_left = Math::Ceiling(Math::distance(tile_rect.left, rect.left), 100.f) / 10.f;
			float alpha_right = Math::Ceiling(Math::distance(tile_rect.right, rect.right), 100.f) / 10.f;
			float alpha_top = Math::Ceiling(Math::distance(tile_rect.top, rect.top), 100.f) / 10.f;
			float alpha_down = Math::Ceiling(Math::distance(tile_rect.bottom, rect.bottom), 100.f) / 10.f;
			float alpha_road = 1.f;

			// check to see if this is a road on the visual layer
			if (visualLayer->GetTileAt(x, y)->tileNumber == 6)
				alpha_road = 0.8f;

			// alpha_left = Math::lerp(1.f, 0.f, alpha_left);
			// alpha_right = Math::lerp(1.f, 0.f, alpha_right);
			// alpha_top = Math::lerp(1.f, 0.f, alpha_top);
			// alpha_down = Math::lerp(1.f, 0.f, alpha_down);

			float alpha_total = alpha_left + alpha_right + alpha_top + alpha_down;
			alpha_total /= 40.f;

			alpha_total *= alpha_road;

			SGD::Color blend_color = SGD::Color::White;
			blend_color.alpha = char(255.f * alpha_total);

			// if the tile is passible, and visible on the minimap and not clipping 
			// the clipping rectangle, draw the visible tile
			if (tile->isPassable && tile_rect.IsIntersecting(rect) && !tile_rect.IsClipping(rect))
				SGD::GraphicsManager::GetInstance()->DrawTexture(passableTileTex, SGD::Point(x * collisionLayer->GetTileSize().width, y * collisionLayer->GetTileSize().height), 0.f, { 0.f, 0.f }, blend_color);
		}
	}


	// for all buckets of entities
	for (unsigned int i = 0; i < m_tEntities.size(); i++)
	{
		// get the current bucket we're on
		std::vector<IEntity*>& bucket = m_tEntities[i];
		for (unsigned int ii = 0; ii < bucket.size(); ii++)
		{
			// store what object we're on right now
			IEntity* at = bucket[ii];
			// try to cast the entity to an IMinimapvisible
			IMinimapVisible* ent = dynamic_cast<IMinimapVisible*>(at);

			// if the current entity is intersecting the camera rect
			if (ent && at->GetRect().IsIntersecting(rect) && !at->GetRect().IsClipping(rect))
			{
				// render the entity on the minimap
				ent->RenderMiniMap();
			}
		}
	}

	// reset camera matrix
	D3DXMATRIX identity;
	D3DXMatrixIdentity(&identity);
	SGD::GraphicsManager::GetInstance()->SetTransform(identity);
}