Esempio n. 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 });
}
Esempio n. 2
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();
		}
	}
}