Example #1
0
	void Bullet::update(unsigned int timeSinceLastFrame){

		position += direction*speed*timeSinceLastFrame/1000;

		float w = 13.2, h = 7.7;

		if (position.x < -w ) this->isDead = true;
		if (position.x >  w ) this->isDead = true;
		if (position.y >  h  ) this->isDead = true;
		if (position.y < -h ) this->isDead = true;

		EnemyFactory *ef = ObjectFactory::getSingletonPtr()->enemyFactory;

		for(std::list<SimpleEnemy*>::iterator it = ef->senemy.begin(); it != ef->senemy.end(); ++it )
		{
			if (hit(*it)){
				onHit(*it);
				(*it)->onHit(this);
				break;
			}
		}

		for(std::list<BlueEnemy*>::iterator it = ef->benemy.begin(); it != ef->benemy.end(); ++it )
		{
			if (hit(*it)){
				onHit(*it);
				(*it)->onHit(this);
				break;
			}
		}

	};
Example #2
0
void OsuCircle::onClickEvent(std::vector<OsuBeatmap::CLICK> &clicks)
{
	if (m_bFinished)
		return;

	const Vector2 cursorPos = m_beatmap->getCursorPos();

	const Vector2 pos = m_beatmap->osuCoords2Pixels(m_vRawPos);
	const float cursorDelta = (cursorPos - pos).length();

	if (cursorDelta < m_beatmap->getHitcircleDiameter()/2.0f)
	{
		// note blocking & shake
		if (m_bBlocked)
		{
			m_fShakeAnimation = engine->getTime() + osu_circle_shake_duration.getFloat();
			return; // ignore click event completely
		}

		const long delta = (long)clicks[0].musicPos - (long)m_iTime;

		OsuScore::HIT result = OsuGameRules::getHitResult(delta, m_beatmap);
		if (result != OsuScore::HIT::HIT_NULL)
		{
			const float targetDelta = cursorDelta / (m_beatmap->getHitcircleDiameter()/2.0f);
			const float targetAngle = rad2deg(atan2(cursorPos.y - pos.y, cursorPos.x - pos.x));

			m_beatmap->consumeClickEvent();
			onHit(result, delta, targetDelta, targetAngle);
		}
	}
}
void JoyStickPanel::onButtonDown(cocos2d::Ref *ref, ui::Widget::TouchEventType touchType)
{
	if(onHit)
	{
		onHit(ref,touchType);
	}
}
Example #4
0
void Projectile::update() {
	Unit* target = checkForHit();
	if (target == NULL) {
		if (this->isActionsFinished())
			remove();
		return;
	}

	onHit(target);
	remove();
}
Example #5
0
void Plane::Hit(GameEntity *pSender)
{
    if (this->getState() == DEAD || this->getState() == INVINCIBLE)
        return;

    this->_nLife -= pSender->getDamage();
    if (this->_nLife <= 0)
        this->setState(DEAD);
    else
        this->setState(HIT);

    if (onHit) onHit(this);
}
void
PowerUp::updateState( void )
{
    if ( NetworkState::status == _network_state_server
         && life_cycle_state == _power_up_lifecycle_state_active )
    {
        UnitID unit_id;
        if( isPowerUpHit( &unit_id ) == true )
        {
            onHit( unit_id );
        }
    }
}
Example #7
0
void EnemyMelee::Update(Player* player, World* currentWorld, double dt)
{

	AccumulatedTime += dt; 

	this->colData = currentWorld->collisionData;

	SetDestination(player->getPosition().x, player->getPosition().y);

	Pat(player);

	onHit(player);

}
Example #8
0
void OsuCircle::update(long curPos)
{
	OsuHitObject::update(curPos);

	// if we have not been clicked yet, check if we are in the timeframe of a miss, also handle auto and relax
	if (!m_bFinished)
	{
		if (m_beatmap->getOsu()->getModAuto())
		{
			if (curPos >= m_iTime)
				onHit(OsuScore::HIT::HIT_300, 0);
		}
		else
		{
			const long delta = curPos - m_iTime;

			if (m_beatmap->getOsu()->getModRelax() || m_beatmap->getOsu()->isInVRMode())
			{
				if (curPos >= m_iTime + (long)m_osu_relax_offset_ref->getInt())
				{
					const Vector2 pos = m_beatmap->osuCoords2Pixels(m_vRawPos);
					const float cursorDelta = (m_beatmap->getCursorPos() - pos).length();

					float vrCursor1Delta = 0.0f;
					float vrCursor2Delta = 0.0f;
					bool vrCursor1Inside = false;
					bool vrCursor2Inside = false;
					if (m_beatmap->getOsu()->isInVRMode())
					{
						vrCursor1Delta = (m_beatmap->getOsu()->getVR()->getCursorPos1() - m_beatmap->osuCoords2VRPixels(m_vRawPos)).length();
						vrCursor2Delta = (m_beatmap->getOsu()->getVR()->getCursorPos2() - m_beatmap->osuCoords2VRPixels(m_vRawPos)).length();
						vrCursor1Inside = vrCursor1Delta < ((m_beatmap->getRawHitcircleDiameter()/2.0f) * m_beatmap->getOsu()->getVR()->getCircleHitboxScale());
						vrCursor2Inside = vrCursor2Delta < ((m_beatmap->getRawHitcircleDiameter()/2.0f) * m_beatmap->getOsu()->getVR()->getCircleHitboxScale());
					}

					if ((cursorDelta < m_beatmap->getHitcircleDiameter()/2.0f && m_beatmap->getOsu()->getModRelax()) || (vrCursor1Inside || vrCursor2Inside))
					{
						OsuScore::HIT result = OsuGameRules::getHitResult(delta, m_beatmap);

						if (result != OsuScore::HIT::HIT_NULL)
						{
							const float targetDelta = cursorDelta / (m_beatmap->getHitcircleDiameter()/2.0f);
							const float targetAngle = rad2deg(atan2(m_beatmap->getCursorPos().y - pos.y, m_beatmap->getCursorPos().x - pos.x));

							if (m_beatmap->getOsu()->isInVRMode())
							{
								// distance to circle
								if (vrCursor1Delta < vrCursor2Delta)
									m_bOnHitVRLeftControllerHapticFeedback = true;
								else
									m_bOnHitVRLeftControllerHapticFeedback = false;

								// distance to playfield, if both cursors were valid (overrides distance to circle for haptic feedback)
								if (vrCursor1Inside && vrCursor2Inside)
								{
									if (m_beatmap->getOsu()->getVR()->getCursorDist1() < m_beatmap->getOsu()->getVR()->getCursorDist2())
										m_bOnHitVRLeftControllerHapticFeedback = true;
									else
										m_bOnHitVRLeftControllerHapticFeedback = false;
								}
							}

							onHit(result, delta, targetDelta, targetAngle);
						}
					}
				}
			}

			if (delta >= 0)
			{
				m_bWaiting = true;

				// if this is a miss after waiting
				if (delta > (long)OsuGameRules::getHitWindow50(m_beatmap))
					onHit(OsuScore::HIT::HIT_MISS, delta);
			}
			else
				m_bWaiting = false;
		}
	}
}