X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。
| Revision | 129 (tree) |
|---|---|
| Time | 2016-04-24 23:32:59 |
| Author | |
同じ人に対して銃弾の当たり判定が2回以上行われることがある問題の修正。「フリーカメラ」での発砲機能を削除。
| @@ -46,6 +46,7 @@ | ||
| 46 | 46 | Human_kill = new int[MAX_HUMAN]; |
| 47 | 47 | Human_headshot = new int[MAX_HUMAN]; |
| 48 | 48 | Human_ShotFlag = new bool[MAX_HUMAN]; |
| 49 | + BulletObj_HumanIndex = new BulletObjectHumanIndex[MAX_BULLET]; | |
| 49 | 50 | FriendlyFire = false; |
| 50 | 51 | Player_HumanID = 0; |
| 51 | 52 | AddHumanIndex_TextureID = -1; |
| @@ -74,6 +75,7 @@ | ||
| 74 | 75 | if( Human_kill != NULL ){ delete [] Human_kill; } |
| 75 | 76 | if( Human_headshot != NULL ){ delete [] Human_headshot; } |
| 76 | 77 | if( Human_ShotFlag != NULL ){ delete [] Human_ShotFlag; } |
| 78 | + if( BulletObj_HumanIndex != NULL ){ delete [] BulletObj_HumanIndex; } | |
| 77 | 79 | } |
| 78 | 80 | |
| 79 | 81 | //! @brief 参照するクラスを設定 |
| @@ -603,6 +605,7 @@ | ||
| 603 | 605 | //使用されていない弾丸ならば、処理せずに返す。 |
| 604 | 606 | if( in_bullet->GetEnableFlag() == false ){ return false; } |
| 605 | 607 | |
| 608 | + int objectID; | |
| 606 | 609 | float bx, by, bz; |
| 607 | 610 | float brx, bry; |
| 608 | 611 | int attacks; |
| @@ -626,6 +629,9 @@ | ||
| 626 | 629 | int id, face; |
| 627 | 630 | float Dist; |
| 628 | 631 | |
| 632 | + //弾オブジェクトのデータ番号を取得 | |
| 633 | + objectID = GetBulletObjectID(in_bullet); | |
| 634 | + | |
| 629 | 635 | //弾丸の座標を取得し、ベクトルを算出。 |
| 630 | 636 | in_bullet->GetPosData(&bx, &by, &bz, &brx, &bry); |
| 631 | 637 | in_bullet->GetParamData(&attacks, &penetration, &speed, &teamid, &humanid); |
| @@ -675,6 +681,9 @@ | ||
| 675 | 681 | if( HumanIndex[i].GetEnableFlag() == false ){ continue; } |
| 676 | 682 | if( HumanIndex[i].GetHP() <= 0 ){ continue; } |
| 677 | 683 | |
| 684 | + //既に当たった人なら、処理しない。 | |
| 685 | + if( BulletObj_HumanIndex[objectID].GetIndexFlag(i) == true ){ continue; } | |
| 686 | + | |
| 678 | 687 | //座標を取得 |
| 679 | 688 | float ox, oy, oz; |
| 680 | 689 | int h_teamid; |
| @@ -774,6 +783,9 @@ | ||
| 774 | 783 | //人に当たった処理 |
| 775 | 784 | HitBulletHuman(HumanHead_id, 0, bx + vx*(HumanHead_Dist+TotalDist), by + vy*(HumanHead_Dist+TotalDist), bz + vz*(HumanHead_Dist+TotalDist), brx, attacks, humanid); |
| 776 | 785 | |
| 786 | + //対人判定用リスト設定 | |
| 787 | + BulletObj_HumanIndex[objectID].SetIndexFlag(HumanHead_id); | |
| 788 | + | |
| 777 | 789 | //攻撃力と貫通力を計算 |
| 778 | 790 | attacks = (int)((float)attacks * 0.6f); |
| 779 | 791 | penetration -= 1; |
| @@ -786,6 +798,9 @@ | ||
| 786 | 798 | //人に当たった処理 |
| 787 | 799 | HitBulletHuman(HumanUp_id, 1, bx + vx*(HumanUp_Dist+TotalDist), by + vy*(HumanUp_Dist+TotalDist), bz + vz*(HumanUp_Dist+TotalDist), brx, attacks, humanid); |
| 788 | 800 | |
| 801 | + //対人判定用リスト設定 | |
| 802 | + BulletObj_HumanIndex[objectID].SetIndexFlag(HumanUp_id); | |
| 803 | + | |
| 789 | 804 | //攻撃力と貫通力を計算 |
| 790 | 805 | attacks = (int)((float)attacks * 0.6f); |
| 791 | 806 | penetration -= 1; |
| @@ -798,6 +813,9 @@ | ||
| 798 | 813 | //人に当たった処理 |
| 799 | 814 | HitBulletHuman(HumanLeg_id, 2, bx + vx*(HumanLeg_Dist+TotalDist), by + vy*(HumanLeg_Dist+TotalDist), bz + vz*(HumanLeg_Dist+TotalDist), brx, attacks, humanid); |
| 800 | 815 | |
| 816 | + //対人判定用リスト設定 | |
| 817 | + BulletObj_HumanIndex[objectID].SetIndexFlag(HumanLeg_id); | |
| 818 | + | |
| 801 | 819 | //攻撃力と貫通力を計算 |
| 802 | 820 | attacks = (int)((float)attacks * 0.7f); |
| 803 | 821 | penetration -= 1; |
| @@ -1500,6 +1518,20 @@ | ||
| 1500 | 1518 | return &(BulletIndex[id]); |
| 1501 | 1519 | } |
| 1502 | 1520 | |
| 1521 | +//! @brief 指定したbulletポインタのデータ番号を取得 | |
| 1522 | +//! @param object 弾オブジェクトのポインタ | |
| 1523 | +//! @return データ番号 (エラー:-1) | |
| 1524 | +int ObjectManager::GetBulletObjectID(bullet* object) | |
| 1525 | +{ | |
| 1526 | + for(int i=0; i<MAX_BULLET; i++){ | |
| 1527 | + if( &(BulletIndex[i]) == object ){ | |
| 1528 | + return i; | |
| 1529 | + } | |
| 1530 | + } | |
| 1531 | + | |
| 1532 | + return -1; | |
| 1533 | +} | |
| 1534 | + | |
| 1503 | 1535 | //! @brief 使用されていないbulletクラスを取得 |
| 1504 | 1536 | //! @return 現在未使用の弾オブジェクトのポインタ (失敗すると NULL) |
| 1505 | 1537 | bullet* ObjectManager::GetNewBulletObject() |
| @@ -1722,6 +1754,9 @@ | ||
| 1722 | 1754 | newbullet->SetPosData(pos_x, pos_y + WEAPONSHOT_HEIGHT, pos_z, rx, ry); |
| 1723 | 1755 | newbullet->SetParamData(attacks, ParamData.penetration, ParamData.speed * BULLET_SPEEDSCALE, teamid, human_id, true); |
| 1724 | 1756 | newbullet->SetEnableFlag(true); |
| 1757 | + | |
| 1758 | + //対人判定用リスト初期化 | |
| 1759 | + BulletObj_HumanIndex[ GetBulletObjectID(newbullet) ].Init(); | |
| 1725 | 1760 | } |
| 1726 | 1761 | else{ |
| 1727 | 1762 | //発射する未使用のオブジェクトを取得 |
| @@ -2550,4 +2585,43 @@ | ||
| 2550 | 2585 | { |
| 2551 | 2586 | //ポイントデータ解放 |
| 2552 | 2587 | CleanupPointDataToObject(); |
| 2588 | +} | |
| 2589 | + | |
| 2590 | +//! @brief コンストラクタ | |
| 2591 | +BulletObjectHumanIndex::BulletObjectHumanIndex() | |
| 2592 | +{ | |
| 2593 | + HumanIndex = new bool[MAX_HUMAN]; | |
| 2594 | + | |
| 2595 | + Init(); | |
| 2596 | +} | |
| 2597 | + | |
| 2598 | +//! @brief ディストラクタ | |
| 2599 | +BulletObjectHumanIndex::~BulletObjectHumanIndex() | |
| 2600 | +{ | |
| 2601 | + if( HumanIndex == NULL ){ delete [] HumanIndex; } | |
| 2602 | +} | |
| 2603 | + | |
| 2604 | +//! @brief 初期化 | |
| 2605 | +void BulletObjectHumanIndex::Init() | |
| 2606 | +{ | |
| 2607 | + for(int i=0; i<MAX_HUMAN; i++){ | |
| 2608 | + HumanIndex[i] = false; | |
| 2609 | + } | |
| 2610 | +} | |
| 2611 | + | |
| 2612 | +//! @brief フラグを取得 | |
| 2613 | +//! @param id 人のデータ番号 | |
| 2614 | +//! @return フラグ値 | |
| 2615 | +bool BulletObjectHumanIndex::GetIndexFlag(int id) | |
| 2616 | +{ | |
| 2617 | + if( (id < 0)||(MAX_HUMAN <= id) ){ return false; } | |
| 2618 | + return HumanIndex[id]; | |
| 2619 | +} | |
| 2620 | + | |
| 2621 | +//! @brief フラグを有効化 | |
| 2622 | +//! @param id 人のデータ番号 | |
| 2623 | +void BulletObjectHumanIndex::SetIndexFlag(int id) | |
| 2624 | +{ | |
| 2625 | + if( (id < 0)||(MAX_HUMAN <= id) ){ return; } | |
| 2626 | + HumanIndex[id] = true; | |
| 2553 | 2627 | } |
| \ No newline at end of file |
| @@ -1292,7 +1292,6 @@ | ||
| 1292 | 1292 | void maingame::Input() |
| 1293 | 1293 | { |
| 1294 | 1294 | time = GetTimeMS(); |
| 1295 | - static unsigned int bullettime = 0; | |
| 1296 | 1295 | |
| 1297 | 1296 | //プレイヤーのクラスを取得 |
| 1298 | 1297 | human *myHuman = ObjMgr.GetPlayerHumanObject(); |
| @@ -1438,34 +1437,7 @@ | ||
| 1438 | 1437 | } |
| 1439 | 1438 | |
| 1440 | 1439 | if( Camera_Debugmode == true ){ //デバックモードならば |
| 1441 | - //発砲操作かチェック | |
| 1442 | - if( CheckInputControl(KEY_Shot, 0) ){ | |
| 1443 | - //前回の発射より、4フレーム分よりも時間が経っていれば | |
| 1444 | - if( bullettime + 4*((int)GAMEFPS) < GetTimeMS() ){ | |
| 1445 | - float x, y, z, rx, ry; | |
| 1446 | - x = camera_x; | |
| 1447 | - y = camera_y; | |
| 1448 | - z = camera_z; | |
| 1449 | - rx = camera_rx; | |
| 1450 | - ry = camera_ry; | |
| 1451 | - | |
| 1452 | - //未使用の弾オブジェクトを取得 | |
| 1453 | - bullet* newbullet = ObjMgr.GetNewBulletObject(); | |
| 1454 | - if( newbullet != NULL ){ | |
| 1455 | - //弾オブジェクトを設定 | |
| 1456 | - newbullet->SetPosData(x, y, z, rx, ry); | |
| 1457 | - newbullet->SetParamData(40, 5, 10, 1024, ObjMgr.GetPlayerID(), true); | |
| 1458 | - newbullet->SetEnableFlag(true); | |
| 1459 | - GameSound->ShotWeapon(x, y, z, 0, 1024, true); | |
| 1460 | - | |
| 1461 | - //スコアに加算 | |
| 1462 | - MainGameInfo.fire += 1; | |
| 1463 | - | |
| 1464 | - //発射時間を記憶(連射間隔判定用) | |
| 1465 | - bullettime = GetTimeMS(); | |
| 1466 | - } | |
| 1467 | - } | |
| 1468 | - } | |
| 1440 | + // | |
| 1469 | 1441 | } |
| 1470 | 1442 | else{ //デバックモードでなければ |
| 1471 | 1443 | HumanParameter humandata; |
| @@ -81,6 +81,7 @@ | ||
| 81 | 81 | int *Human_kill; //!< 倒した敵の数 |
| 82 | 82 | int *Human_headshot; //!< 敵の頭部に命中した数 |
| 83 | 83 | bool *Human_ShotFlag; //!< 発砲フラグ(マズルフラッシュ用) |
| 84 | + class BulletObjectHumanIndex *BulletObj_HumanIndex; //!< 弾対人判定用オブジェクト | |
| 84 | 85 | |
| 85 | 86 | bool FriendlyFire; //!< FF(同士討ち)有効化 |
| 86 | 87 |
| @@ -134,6 +135,7 @@ | ||
| 134 | 135 | weapon* GetWeaponObject(int id); |
| 135 | 136 | smallobject* GetSmallObject(int id); |
| 136 | 137 | bullet* GetBulletObject(int id); |
| 138 | + int GetBulletObjectID(bullet* object); | |
| 137 | 139 | bullet* GetNewBulletObject(); |
| 138 | 140 | grenade* GetNewGrenadeObject(); |
| 139 | 141 | human* SearchHuman(signed char p4); |
| @@ -163,4 +165,18 @@ | ||
| 163 | 165 | void Cleanup(); |
| 164 | 166 | }; |
| 165 | 167 | |
| 168 | +//! @brief 弾対人判定用クラス | |
| 169 | +//! @details 弾と人の当たり判定の有無を管理するクラスです。ObjectManagerクラス内で使用します。 | |
| 170 | +class BulletObjectHumanIndex | |
| 171 | +{ | |
| 172 | + bool *HumanIndex; //!< リスト | |
| 173 | + | |
| 174 | +public: | |
| 175 | + BulletObjectHumanIndex(); | |
| 176 | + ~BulletObjectHumanIndex(); | |
| 177 | + void Init(); | |
| 178 | + bool GetIndexFlag(int id); | |
| 179 | + void SetIndexFlag(int id); | |
| 180 | +}; | |
| 181 | + | |
| 166 | 182 | #endif |
| \ No newline at end of file |