コード例 #1
0
void SpaceShip::update(float elapsedTime)
{
	// Example on how to accelerate SpaceShip
	if (!ia) {
		if(thrust){
			addThrust(5);
		} 
		else 
		{
			//addThrust(-2);
			speed = 0;
		}
	}

	// How firing could be handled with events
	if(isFiring)
	{
		ofSpaceShipFireEventArgs e = {position, ofPoint(cos(rotation), sin(rotation))};
		ofNotifyEvent(spaceShipFires, e, this);
		invulnerable = false;
		this->createBullets();
	}

	// TODO
	// - add spaceship state update
	// - control spacehsip and window boundaries (i.e. marginSwap)

	if (isTurning) {
		float temp = PI / (speed+10);
		if (turningRight) rotation += temp;
		else rotation -= temp;
	}

	direction = ofPoint( cos(rotation), sin(rotation) );

	position.x -= speed*direction.x*elapsedTime/2;
	position.y -= speed*direction.y*elapsedTime/2;

	marginsWrap();

	// each player updates its own bullets
	for (Bullet* bullet : bullets) bullet->update(elapsedTime);
}
コード例 #2
0
ファイル: SpaceShip.cpp プロジェクト: Getuba/OFAsteroids
void SpaceShip::update(float elapsedTime)
{
	if(turnLeft)
	{
		addRotation(-0.090);

	}

	if(turnRight)
	{
		addRotation(0.090);
	}

	if(thrust){
		addThrust(5);
	} 
	else 
	{
		addThrust(-2);
	}

	if(backThrust)
	{
		addThrust(-1.5);
	}
	
	if(thrust || turnLeft || turnRight)
	{
		direction.x = cos(rotation);
		direction.y = sin(rotation);
	}

	if(isFiring)
	{
		if(bulletCount < 1)
		{
			ofSpaceShipFireEventArgs e = {position, ofPoint(cos(rotation), sin(rotation))};
			ofNotifyEvent(spaceShipFires, e, this);
			bulletCount++;
		}
	}
	
	if(timeIsDestroyed >= 0)
	{
		if(timeIsDestroyed >= 1)
		{
			resetSpaceShip();
		}
		else
		{
			timeIsDestroyed += 0.05;
		}
		
	}
	else
	{
		position += -(direction) * speed * elapsedTime;
	}

	
	marginsWrap();
}