示例#1
0
	void Plane::init( Vec2f const& v1 , Vec2f const& v2 )
	{
		Vec2f offset = v2 - v1;
		float len = sqrt( offset.length2() );
		normal.x = offset.y / len;
		normal.y = -offset.x / len;
		d = -normal.dot( v1 );
	}
示例#2
0
float Math::normalize( Vec2f& v )
{
    float d = sqrt( v.length2() );

    if(d==0)
        return 0.0f;

    v.x/=d;
    v.y/=d;
    return d;
}
示例#3
0
void MinigunMob::tick()
{
	BaseClass::tick();

	shoot( IBulletFactory::Make< MinigunBullet >() );

	if ( mTarget )
	{
		Vec2f dir = mPosLastView - getPos();
		if( dir.length2() < 300 * 300 )
		{
			mSpeed -= 100*TICK_TIME;
			if( mSpeed < 0 )
				mSpeed = 0;
		}
		else
		{
			mSpeed += 100*TICK_TIME;
			if( mSpeed > mMaxSpeed )
				mSpeed = mMaxSpeed;
		}
	}
}
示例#4
0
void Mob::tick()
{
	BaseClass::tick();

	float MaxMobViewDistance = 1000;

	Player* player = getLevel()->getPlayer();
	Vec2f offset = player->getPos() - getPos();

	if ( offset.length2() < MaxMobViewDistance * MaxMobViewDistance &&
		 !getLevel()->getColManager().rayTerrainTest( getPos() , player->getPos() , COL_VIEW ) )
	{
		mTarget = player;
		mTimeCantView = 0;
		mPosLastView = mTarget->getPos();
	}
	else
	{
		mTimeCantView += TICK_TIME;

		if ( mTimeCantView > 3 )
			mTarget = NULL;
	}

	akceleracija=1;

	if ( mTarget )
	{
		Vec2f dir;
		dir = mPosLastView - getPos();
		Math::normalize( dir );

		rotation = atan2(dir.y,dir.x) + Math::toRad( 90 );

		Vec2f monent;
		float angle = rotation - Math::toRad( 90 );
		monent.x = cos( angle ) * akceleracija;
		monent.y = sin( angle ) * akceleracija;

		Vec2f off = ( mSpeed * TICK_TIME ) * dir;

		Vec2f offset = Vec2f( 0 , 0 );

		offset.y += off.y;
		if( testCollision( offset ) )
			offset.y = 0;
		offset.x += off.x;
		if( testCollision( offset ) )
			offset.x = 0;

		mPos += offset;
	}

	if( punjenje < 100 )
	{
		punjenje += brzinaPunjenja * TICK_TIME;
	}

	if( mHP<=0 )
	{
		destroy();
	}

	akceleracija=0;

}