私のゲームの最大の側面が機能していないように見えるので、大きな苦境のビット. 私は 3D スペース インベーダー ゲームを作成しており、プレイヤー (および敵) に互いに弾丸を発射させようとしています。しかし、どちらもそうしていないようです。
両方のコードを処理する攻撃マネージャーがあります。
/**
* Prepares a bullet for firing if the current time is greater than
* the last fired time + the firing delay. This purpose of this is to
* put a delay between each bullet as it is fired. A bullet is only
* 'readied' for firing if it is available, i.e. it's alive property
* is set to false.
*
*/
void PlayerAttackManager::fireBullet() {
if ( mCurrentTime > ( mLastFiredTime + sFIRE_DELAY ) ) {
// Find the next available bullet (if one exists)
std::vector<Bullet>::iterator end = mBullets.end();
std::vector<Bullet>::iterator curr = mBullets.begin();
for ( ; curr != end && (*curr).alive() == true; ++curr );
// If there is a bullet available.
if ( curr != end ) {
// Move bullet to firing location and set alive.
Vector3 bulletPos = mSceneMgr->getSceneNode( "PlayerParentNode" )->getPosition();
Vector3 bulletDir = mSceneMgr->getSceneNode( "PlayerParentNode" )->getOrientation() * Vector3::UNIT_Z;
// Pass the initial screen position and direction of travel for the bullet.
(*curr).reset( bulletPos, bulletDir );
}
mLastFiredTime = mCurrentTime;
}
}
上記のメソッドは、スペースバーが押されるたびに呼び出されますが、プレイヤーの位置から下に移動する敵弾と、プレイヤーの上から下に移動する別の敵弾を送信します。
敵は、EnemyAttackManager が main.cpp frameRenderingQueued メソッドから起動するために呼び出される (1 秒ごとに 1 回) 攻撃する必要があります。EnemyAttackManager の更新は次のとおりです。
void EnemyAttackManager::update(Real const & timeSinceLastFrame, string name)
{
mName = name;
std::vector<Bullet>::iterator end = mBullets.end();
std::vector<Bullet>::iterator curr = mBullets.begin();
for ( ; curr != end && (*curr).alive() == true; ++curr ) {
if ( curr != end ) {
// Move bullet to firing location and set alive.
Vector3 bulletPos = mSceneMgr->getSceneNode( mName + "Node" )->getPosition();
Vector3 bulletDir =mSceneMgr->getSceneNode(mName+ "Node" )->getOrientation() * Vector3::UNIT_Z;
// Pass the initial screen position and direction of travel for the bullet.
(*curr).reset( bulletPos, bulletDir );
(*curr).update(timeSinceLastFrame);
}
}
// Add time since last frame.
mCurrentTime += timeSinceLastFrame;
}
そして、弾丸の更新機能とリセット機能はそれぞれ次のとおりです。
void Bullet::update( Real const & timeSinceLastFrame ) {
mTtl -= timeSinceLastFrame;
if ( mTtl <= 0 ) {
mNode->setVisible( false );
}
else {
Enemy* enem = new Enemy();
mNode->translate( sMOVE * mDir * timeSinceLastFrame, Node::TS_LOCAL );
// Retrieve a list of possible enemies.
std::vector<Enemy *> enemyVec = enem->getEnemies();
std::vector<Enemy *>::iterator curr = enemyVec.begin();
std::vector<Enemy *>::iterator end = enemyVec.end();
// Check if the ray intersected any of the enemies
for ( ; curr != end && !CollisionManager::instance()->rayIntersects( mNode->getPosition(), 0, (*curr)->meshName(), mDir )
; ++curr );
if ( curr != end ) { // if bullet has collided with an enemy.
//(*curr)->applyDamage();
mTtl = 0;
//JetPack3D::score += 10;
mNode->setVisible( false );
}
//Check the current bullet pos vs. player
}
}
void Bullet::reset( Vector3 const & bulletPos, Vector3 const & bulletDir ) {
mNode->setPosition( bulletPos );
mNode->setVisible( true );
mTtl = sLIFE_TIME;
mDir = bulletDir;
// Need to reverse x and z components so bullet fires forward into the scene.
//now need it to fire right?
mDir.z *= -1;
mDir.x *= -1;
}
だから私の質問は次のとおりです:敵とプレイヤーに弾丸を発射させるにはどうすればよいですか(敵はまったく発砲し、プレイヤーは正しい方向に発砲します)