示例#1
0
void Bullet::Render()
{
	if (!visible)
		return;
	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;
	}

	//GraphicsManager::GetInstance()->DrawRectangle(GetRect(), SGD::Color(0, 200, 125));
	if (owner->GetGunType() == Weapon::GunType::chainsawLauncher)
		GraphicsManager::GetInstance()->DrawTexture(saw, SGD::Point{ m_ptPosition.x - 32.0f, m_ptPosition.y + 32.0f }, 0, {}, {}, SGD::Size{ 0.25f*dist, 0.25f*dist });
	else if (owner->GetGunType() != Weapon::GunType::meleeWeapon && owner->GetOwner() && owner->GetOwner()->GetClass() != ClassType::Mutant)
		GraphicsManager::GetInstance()->DrawTexture(m_hImage, m_ptPosition, m_fRotation + (PI*0.5f), SGD::Vector(m_szSize.width*0.5f, m_szSize.height*0.5f), {}, SGD::Size{ 0.175f*dist, 0.25f*dist });
	else if (spit)
		GraphicsManager::GetInstance()->DrawTexture(spittle, m_ptPosition, m_fRotation + PI, SGD::Vector(32.0f, 32.0f), {}, SGD::Size{ 0.5f, 0.5f });
}
void FireTrap::Render(void)
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();

	SGD::Point point = { m_ptPosition.x - GameplayState::GetInstance()->GetWorldCam().x, m_ptPosition.y - GameplayState::GetInstance()->GetWorldCam().y };

	if (GameplayState::GetInstance()->GetDebugState())
	{
		SGD::Rectangle rec = GetRect();
		rec.Offset(-GameplayState::GetInstance()->GetWorldCam().x, -GameplayState::GetInstance()->GetWorldCam().y);
		pGraphics->DrawRectangle(rec, SGD::Color(0, 0, 255));
	}

	// - Temp Code till we have sprites.
	//SGD::Rectangle rec = GetRect();
	//	rec.Offset( -GameplayState::GetInstance()->GetWorldCam().x, -GameplayState::GetInstance()->GetWorldCam().y );
	// - Collision Rectangle

	pGraphics->DrawTexture(m_hImage, point);

	if (m_bStartTimer)
		m_pParticle.RenderPoint(point);
	//pGraphics->DrawRectangle( rec, SGD::Color( 255, 0, 0 ) );
	

}
示例#3
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();
		}
	}
}
SGD::Rectangle AnimationSystem::GetRect(const AnimationTimestamp& _info, float _PosX, float _PosY, SGD::Size _scale)
{
	SGD::Point pt = { (float)_PosX, (float)_PosY };
	SGD::Rectangle crect = m_Loaded[_info.GetCurrAnim()].GetFrames()[_info.GetCurrFrame()].GetCollisionRect();
	float x = crect.left + pt.x;
	float y = crect.top + pt.y;
	float width = (crect.left + pt.x) + crect.ComputeWidth() * _scale.width;
	float height = (crect.top + pt.y) + crect.ComputeHeight() * _scale.height;
	return SGD::Rectangle{ x, y, width, height };
}
示例#5
0
void Player::Render(void) {

	if (m_pCharaterAnim != nullptr) {


		// Validate the image
		SGD_ASSERT(m_hImage != SGD::INVALID_HANDLE, "Entity::Render - image was not set!");

		SGD::Point ptOffset = SGD::Point{ 
			(m_ptPosition /*- m_szSize / 2*/).x - GameplayState::GetInstance()->GetWorldCamPosition().x,
			(m_ptPosition /*- m_szSize / 2*/).y - GameplayState::GetInstance()->GetWorldCamPosition().y 
		};
		SGD::Rectangle rectOffset = GetRect();
		rectOffset.Offset(-GameplayState::GetInstance()->GetWorldCamPosition().x, -GameplayState::GetInstance()->GetWorldCamPosition().y);

		// Draw the image
		SGD::GraphicsManager::GetInstance()->DrawRectangle(rectOffset, SGD::Color(255, 255, 0));
		//SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, ptOffset, m_fRotation, m_szSize / 2, SGD::Color{ 255, 255, 255 });
		//SGD::GraphicsManager::GetInstance()->DrawTextureSection(m_hImage, ptOffset, {0.0f, 0.0f, 64.0f, 64.0f}, m_fRotation, m_szSize / 2, SGD::Color{ 255, 255, 255 });
		m_pCharaterAnim->Render(ptOffset, m_bIsFlipped);

	}

}
void AnimationSystem::Render(AnimationTimestamp& _info, float _PosX, float _PosY, SGD::Size _scale, float rotation)
{

	SGD::Point temppt = SGD::Point((float)_PosX, (float)_PosY);
	SGD::Point pt = m_Loaded[_info.GetCurrAnim().c_str()].GetFrames()[_info.GetCurrFrame()].GetAnchorPt();
	SGD::Rectangle crect = m_Loaded[_info.GetCurrAnim()].GetFrames()[_info.GetCurrFrame()].GetCollisionRect();
	//GM->DrawRectangle(GetRect(_info, _PosX, _PosY), SGD::Color(255, 0, 0));
	SGD::Rectangle rect = m_Loaded[_info.GetCurrAnim().c_str()].GetFrames()[_info.GetCurrFrame()].GetDrawFrame();
	temppt.x += rect.left * _scale.width;
	temppt.y += rect.top * _scale.height;
	if (_info.GetOwner()->GetType() == Actor::ENT_FATHER)
		GM->DrawTextureSection(m_Imgs[0], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_SON)
		GM->DrawTextureSection(m_Imgs[1], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_CANNONBALL)
		GM->DrawTextureSection(m_Imgs[2], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_ARROW)
		GM->DrawTextureSection(m_Imgs[3], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_SWORDSMAN)
		GM->DrawTextureSection(m_Imgs[4], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_AUTO_LOCK_DOOR)
		GM->DrawTextureSection(m_Imgs[5], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_BOWMAN)
		GM->DrawTextureSection(m_Imgs[6], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_SMASHING_COLUMNS)
		GM->DrawTextureSection(m_Imgs[7], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_FALLING_ROCK)
		GM->DrawTextureSection(m_Imgs[8], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_ROLLING_BOULDER)
		GM->DrawTextureSection(m_Imgs[9], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, rotation, { 32, 32 }, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_POPUPSPIKES)
		GM->DrawTextureSection(m_Imgs[10], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_LEVERS)
		GM->DrawTextureSection(m_Imgs[11], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
	else if (_info.GetOwner()->GetType() == Actor::ENT_PLATES)
		GM->DrawTextureSection(m_Imgs[12], temppt, SGD::Rectangle{ rect.left + pt.x, rect.top + pt.y, (rect.left + pt.x) + rect.ComputeWidth(), (rect.top + pt.y) + rect.ComputeHeight() }, 0.0f, {}, {}, _scale);
}
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);
}