Exemplo n.º 1
0
        /// <summary>
        /// 当たり判定を行う
        /// </summary>
        /// <param name="ch">当たり判定を行うキャラクタ</param>
        private void HitTest(GameCharacter ch)
        {
            // 当たり判定
            var checkChara = hitTestArray[ch.GetIndex()];

            // 何にも当たっていなかった場合
            if (checkChara == null)
            {
                hitTestArray[ch.GetIndex()] = ch;
                return;
            }

            // 当たっていた場合
            checkChara.UpdateHitPoint(ch);

            // もともとindexの位置にあったキャラクタ
            if (!checkChara.IsAlive())
            {
                hitTestArray[ch.GetIndex()] = null;
            }

            // 当たり判定対象のキャラクタ
            if (ch.IsAlive())
            {
                hitTestArray[ch.GetIndex()] = ch;
            }

            // indexの位置のキャラクタのHPが残っていた場合、同じ位置に描画しなおす
            if (hitTestArray[ch.GetIndex()] != null)
            {
                hitTestArray[ch.GetIndex()].UpdateDrawing();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 自機以外のキャラクタの移動
        /// </summary>
        private void MoveCharacterExceptShip()
        {
            foreach (var ch in gameCharacters)
            {
                // 速度変更が必要な場合はキャラクタの移動速度を変える
                if (changeSpeed)
                {
                    ch.ChangeSpeed(CalcMoveSpeed());
                }

                // 移動前のindexの配列の中身を消す
                hitTestArray[ch.GetIndex()] = null;

                ch.Move();

                if (!ch.IsAlive())
                {
                    continue;
                }

                HitTest(ch);
            }

            // 画面にShipの弾は一つだけ
            if (shipBullet != null && !shipBullet.IsAlive())
            {
                shipBullet = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// キャラクタを初期化する
        /// </summary>
        private void InitializeCharacters()
        {
            Console.Clear();

            // Shipの作成
            ship = new Ship();

            // 弾を撃っていない状態にする
            shipBullet = null;

            // キャラクタリストの初期化
            gameCharacters = new List <GameCharacter>();
            hitTestArray   = new GameCharacter[1000];
            var point = 60;

            shotBulletInterval = moveSpeed / 2;

            // 敵軍の作成
            // ステージごとに開始位置を変更
            for (int line = (stage % 7 + 3); line < (stage % 7 + 2 * 6 + 3); line += 2)
            {
                for (int column = 0; column < 4 * 12; column += 4)
                {
                    var inv = new Enemy(column, line, point, moveSpeed);
                    gameCharacters.Add(inv);
                }
                point -= 10;
            }

            // ブロックの作成
            for (int y = 20; y < 24; y++)
            {
                for (int x = 4; x < 14; x += 2)
                {
                    var block = new Block(x, y);
                    gameCharacters.Add(block);
                }

                for (int x = 20; x < 30; x += 2)
                {
                    var block = new Block(x, y);
                    gameCharacters.Add(block);
                }

                for (int x = 36; x < 46; x += 2)
                {
                    var block = new Block(x, y);
                    gameCharacters.Add(block);
                }

                for (int x = 52; x < 62; x += 2)
                {
                    var block = new Block(x, y);
                    gameCharacters.Add(block);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 当たり判定
        /// </summary>
        /// <param name="ch">判定するキャラクタ</param>
        public override void UpdateHitPoint(GameCharacter ch)
        {
            if (ch.GetType() == typeof(EnemyBullet))
            {
                return;
            }

            Erase(xPos, yPos);
            hitPoint -= ch.AttackPower;
            ch.ReduceHitPoint(AttackPower);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 自機の移動、自弾の発射の処理を行う
        /// </summary>
        private void RunShipEvent()
        {
            while (!isGameOver)
            {
                lock (ship)
                {
                    if (!Console.KeyAvailable)
                    {
                        continue;
                    }
                    if (isGameOver)
                    {
                        break;
                    }

                    var key = Console.ReadKey(true).Key;
                    switch (key)
                    {
                    case ConsoleKey.LeftArrow:
                        ship.MoveLeft();
                        if (ship.HitTest(hitTestArray))
                        {
                            isGameOver = true;
                            break;
                        }
                        continue;

                    case ConsoleKey.RightArrow:
                        ship.MoveRight();
                        if (ship.HitTest(hitTestArray))
                        {
                            isGameOver = true;
                            break;
                        }
                        continue;

                    case ConsoleKey.Spacebar:
                        if (shipBullet != null)
                        {
                            break;;
                        }
                        shipBullet = ship.ShotBullet();

                        // 弾を作成した位置に敵・敵弾があった場合は対消滅させる
                        if (hitTestArray[shipBullet.GetIndex()] != null)
                        {
                            hitTestArray[shipBullet.GetIndex()].UpdateHitPoint(shipBullet);
                            shipBullet = null;
                            continue;;
                        }
                        gameCharacters.Add(shipBullet);
                        continue;
                    }
                }
            }

            // ゲームオーバー後の処理
            while (isGameOver)
            {
                if (!Console.KeyAvailable)
                {
                    continue;
                }
                var key = Console.ReadKey(true).Key;

                switch (key)
                {
                case ConsoleKey.Q:     // ゲームをやめる
                    return;

                case ConsoleKey.Enter:     // 新しくゲームを始める
                    GameStart();
                    return;

                default:
                    continue;
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// ヒットポイントの更新を行う
 /// </summary>
 /// <param name="ch">当たった相手のキャラクタ</param>
 public abstract void UpdateHitPoint(GameCharacter ch);