コード例 #1
0
void Boss::vectorTrack()//We're going to want to change this so that it takes an argument that is what we want to track
{
	VECTOR2 vel = getCenterPoint()-targetEntity.getCenterPoint();
	if(vel.x == 0 && vel.y==0)
		return;
	VECTOR2* foo = D3DXVec2Normalize(&vel, &vel);
	setVelocity(-vel);
	setRadians((atan((targetEntity.getCenterY()-getCenterY())/(targetEntity.getCenterX()-getCenterX())))-PI/2);
	if(targetEntity.getCenterX()>getCenterX())
		setRadians(getRadians()+PI);
}
コード例 #2
0
ファイル: power.cpp プロジェクト: Cusimonster/Asteroids
void Power::update(float frameTime)
{
	Entity::update(frameTime);

	spriteData.x += frameTime * velocity.x;
    spriteData.y += frameTime * velocity.y;

	setRadians(getRadians()+POWERUP_ROTATION_SPEED);

	if (spriteData.x > GAME_WIDTH+powerNS::WIDTH*getScale())
    {
		setActive(false);
    }
    else if (spriteData.x < 0)
    {
        setActive(false);
	}
    if (spriteData.y > GAME_HEIGHT+powerNS::HEIGHT*getScale())
    {
        setActive(false);
	}
	else if (spriteData.y < 0)
	{
		setActive(false);
	}
}
コード例 #3
0
ファイル: hmath.cpp プロジェクト: Sourec/Infscroll-Comic
 /** \brief Constructor - sets the initial angle.
  * \param angle Accepts either radians or degrees
  * \param rad If true, the constructor sets the angle as radians. Else, degrees.
  */
 Angle::Angle(double angle, bool rad)
 {
     if (!rad)
         setDegrees(angle);
     else
         setRadians(angle);
 }
コード例 #4
0
//------------------------------------------------------------------------------
// setDegrees() -- sets angle of object in (degrees):
//------------------------------------------------------------------------------
bool AngularVelocity::setDegrees(const LCreal newAngle)
{
    //Set the angle in radians:
    bool ok = setRadians( newAngle * static_cast<LCreal>(Angle::D2RCC) );

    return ok;
}
コード例 #5
0
ファイル: Asteroid.cpp プロジェクト: JSybrandt/REDSPACE
void Asteroid::update(float frameTime) {
	if(active)
	{
		dir += ((rand()%100)/100.0)*3*frameTime;
		setRadians(dir);
		Planet::update(frameTime);
	}
}
コード例 #6
0
void Vision::stickToEntity(const Entity& e)
{
	setScale(e.getScale());
	setRadians(e.getRadians());
	spriteData.x = (e.getX() + e.getWidth() / 2);
	spriteData.y = (e.getY() + e.getHeight() / 2);
	spriteData.x -= getWidth() / 2;
	spriteData.y -= getHeight() / 2;
}
コード例 #7
0
ファイル: Boat.cpp プロジェクト: dbrowndan/Fish-and-Ships
 void Boat::update(float frameTime){
	Entity::update(frameTime);
	// arrow keys to move boat
	if (input->isKeyDown(VK_LEFT)) velocity.x = -boatNS::SPEED;
	else if (input->isKeyDown(VK_RIGHT)) velocity.x = boatNS::SPEED;
	else velocity.x = 0;

	spriteData.x +=  velocity.x * frameTime;

	// don't let the boat go off the screen
	if (spriteData.x < 0) spriteData.x = 0;
	if (spriteData.x + spriteData.width * BOAT_IMAGE_SCALE > GAME_WIDTH) spriteData.x = GAME_WIDTH - spriteData.width * BOAT_IMAGE_SCALE;

	if (getRadians() > PI / 64) rotationDir = false;
	if (getRadians() < -PI / 64) rotationDir = true;
	if (rotationDir) setRadians(getRadians() + (PI / 64 * frameTime));
	else setRadians(getRadians() - (PI / 64 * frameTime));

 }
コード例 #8
0
ファイル: fish.cpp プロジェクト: dbrowndan/Fish-and-Ships
void Fish::setTowards(Entity &boat) {
	
	// Set vel towards boat
	velocity.x = boat.getCenterX() - getCenterX();
	velocity.y = boat.getY() + boat.getHeight() * BOAT_IMAGE_SCALE - spriteData.y;

	D3DXVec2Normalize(&velocity, &velocity);

	velocity *= speed;

	// Set texture to face boat
	if(!spriteData.flipHorizontal && spriteData.x > boat.getCenterX()) spriteData.flipHorizontal = true;
	if(spriteData.flipHorizontal && spriteData.x + getWidth() < boat.getCenterX()) spriteData.flipHorizontal = false;

	// Set angle towards boat
	if(spriteData.flipHorizontal) setRadians(atan(spriteData.y / (spriteData.x + getHeight())));
	else setRadians(-atan(spriteData.y / (spriteData.x + getHeight())));

}
コード例 #9
0
ファイル: shuriekn_STU.cpp プロジェクト: stuartsoft/Rogue
void Shuriken::update(float frameTime){
	Entity::update(frameTime);
	setRadians(getRadians()+0.05);
	//update position based on velocity changes
	incPosition(D3DXVECTOR2(velocity*frameTime));

	//apply new position
	spriteData.x = getPositionX();
	spriteData.y = getPositionY();
}
コード例 #10
0
void Gun::recoil(float frameTime)
{
	if(mag != 0)
	{
		frameTime = 1;
		int recoil = mag->recoil - recoilReduction;
		if(recoil > 0)
		{
			setRadians(getRadians() + frameTime*((rand()%recoil)-(510*recoil/1000))*PI/180);
		}
	}
}
コード例 #11
0
//------------------------------------------------------------------------------
// setSlotAngle() -- sets angle based on input object and its value:
//------------------------------------------------------------------------------
bool AngularVelocity::setSlotAngle(const Angle* const msg)
{
    bool ok = false;

    //Try to convert Number to an angle:
    if(msg != nullptr)
    {
        LCreal finalNumber = static_cast<LCreal>(Radians::convertStatic(*msg));
        ok = setRadians(finalNumber);
    }
    return ok;
}
コード例 #12
0
//------------------------------------------------------------------------------
// setRadiansPerSecond() -- sets our angularVelocity:
//------------------------------------------------------------------------------
bool AngularVelocity::setRadiansPerSecond(const LCreal newAngularVelocity)
{

    //Set angle and time - units in radians per second -> num = input; den = 1:
    bool ok1 = setRadians(newAngularVelocity);
    bool ok2 = setSeconds(1);

    //Check both values for ok:
    ok1 = (ok1)&&(ok2);

    return ok1;
}
コード例 #13
0
ファイル: particle.cpp プロジェクト: stuartsoft/Rogue
void Particle::update(float frametime)
{
	if (!active)
		return;
	timeAlive += frametime;
	if (timeAlive >= maxTimeAlive)
	{
		resetParticle();
		return;
	}
	// update physics and drawing stuff

	setX(getX() + velocity.x * frametime);
	setY(getY() + velocity.y * frametime);
	rotationValue += frametime;
	if (rotationValue> 2*2.14159) //prevent overrotation
		rotationValue = 0;
	setRadians(rotationValue);

}
コード例 #14
0
AngularVelocity::AngularVelocity(const Angle* const newAngle, const Time* const newTime)
{
    STANDARD_CONSTRUCTOR()

    //Set a default angle, time, and angularVelocity
    angle = 1;
    time = 1;
    val = 1;

    //Set Checks to false:
    bool okAngle = false;
    bool okTime = false;

    //Check and convert the angle to radians
    if (newAngle != nullptr)
    {
        LCreal finalAngle = static_cast<LCreal>(Radians::convertStatic(*newAngle));
        okAngle = setRadians(finalAngle);
    }

    //Check and convert the time to seconds
    if (newTime != nullptr)
    {
        LCreal finaltime = Seconds::convertStatic( *newTime );
        okTime = setSeconds(finaltime);
    }

    //Check that both were set correctly - if not give error:
    if ( !okTime || !okAngle )
    {
        //Give error if something was not set correctly:
        std::cerr << "Angle or Time not set correctly - new AngularVelocity Object bad." << std::endl;

    }

}