void BattleCommanderStateDirection::CheckPointingActor(void){ Cursor3D* cursor3d(_accessor->GetCursor3D()); if(!cursor3d->GetVisible()){ _pointing_actor = nullptr; return; } D3DXVECTOR3 cursor_position(cursor3d->GetPosition()); HitSphere cursor_hit(nullptr, cursor_position, 5.0f); //敵と味方を全部辿って、当たっている奴の中で一番近いやつを指す _pointing_actor = nullptr; float min_length(1000.0f); int player_count(_accessor->GetPlayerCount()); for(int i=0; i<player_count; i++){ BattleActor* player(_accessor->GetPlayer(i)); Hit* player_hit(player->GetCursorHit()); bool hit(player_hit->HitCheck(&cursor_hit)); if(hit){ D3DXVECTOR3 player_position(player->GetPosition()); D3DXVECTOR3 v(player_position - cursor_position); float length(D3DXVec3Length(&v)); if(min_length > length){ min_length = length; _pointing_actor = player; } } } int enemy_count(_accessor->GetEnemyCount()); for(int i=0; i<enemy_count; i++){ BattleActor* enemy(_accessor->GetEnemy(i)); Hit* enemy_hit(enemy->GetCursorHit()); bool hit(enemy_hit->HitCheck(&cursor_hit)); if(hit){ D3DXVECTOR3 enemy_position(enemy->GetPosition()); D3DXVECTOR3 v(enemy_position - cursor_position); float length(D3DXVec3Length(&v)); if(min_length > length){ min_length = length; _pointing_actor = enemy; } } } }
void explosion_bullet_hit (int index) { explosion_bullets[index].live = 0; //Do explosion effect on the next frame explosion_bullets[index].explode = 1; //Do the actual damage(damaging all nearby enemy ships): int i; for (i = 0; i < NUM_ENEMIES; i++) { if (detect_inside_area (explosion_bullets[index].location.x + EXPLOSION_BULLET_W / 2, explosion_bullets[index].location.y + EXPLOSION_BULLET_H / 2, EXPLOSION_W, EXPLOSION_H, enemies[i].location.x, enemies[i].location.y, ENEMY_W, ENEMY_H)) { //An enemy was found within explosion area. enemy_hit (i, EXPLOSION); } } }