Esempio n. 1
0
 public GameConsole()
 {
     _configuration.Setup();
     _gameover = false;
     _score    = 0;
     _lives    = 3;
     AddHeader(_score, _lives);
     _ship         = new Ship();
     _enemies      = new Enemies();
     _enemyBullets = new EnemyBullets();
 }
    // 敵弾発射関数
    protected void ShotBullet(GameObject bullet, Vector3 pos, float speed, float angle, float size, bool rank = false)
    {
        if (pos.y >= GameController.window_RBPos.y / 2.0f)
        {
            EnemyBullets e_bullet = Object.Instantiate(bullet, pos, Quaternion.identity).GetComponent <EnemyBullets>();

            if (rank)
            {
                speed += (float)GameController.Instance.gameRank / GameController.Instance.gameRank_Max * 3.0f - 1.5f;
            }

            e_bullet.SetUp(speed, angle, size);
        }
    }
Esempio n. 3
0
        private void UpdateEnemies()
        {
            foreach (var enemy in Enemies)
            {
                enemy.PreciseX += enemy.Speed * FrameTime.TotalSeconds;
                var eBullet = ((Enemy)enemy).Fire();
                if (eBullet != null)
                {
                    EnemyBullets.Add(eBullet);
                    Creatures.Add(eBullet);
                }
            }

            UpdateEnemyBullets();
        }
Esempio n. 4
0
        /// <summary>
        /// 画面を描画する。
        /// </summary>
        public void Draw()
        {
            // 背景
            DX.SetDrawBright(BackR, BackG, BackB);
            DX.DrawGraph(0, 0, imgBack, DX.FALSE);
            DX.SetDrawBright(255, 255, 255);

            Enemies.ForEach(enemy => enemy.Draw());
            OwnBullets.ForEach(bullet => bullet.Draw());
            EnemyBullets.ForEach(bullet => bullet.Draw());
            OwnChar.Draw();
            if (Boss != null)
            {
                Boss.Draw();
                DX.DrawFillBox(bossHpX1, bossHpY1, bossHpX1 + bossHpW, bossHpY1 + bossHpH, bossHpColBack);
                DX.DrawFillBox(bossHpX1, bossHpY1, bossHpX1 + Boss.HP * bossHpW / Boss.MaxHP, bossHpY1 + bossHpH, bossHpCol);
            }
        }
Esempio n. 5
0
        private void UpdateEnemyBullets()
        {
            for (int bulletIndex = 0; bulletIndex < EnemyBullets.Count; bulletIndex++)
            {
                var enemyBullet = EnemyBullets[bulletIndex];

                if (enemyBullet.X <= 0)
                {
                    Creatures.Remove(enemyBullet);
                    EnemyBullets.Remove(enemyBullet);
                    continue;
                }

                enemyBullet.PreciseX += enemyBullet.Speed * FrameTime.TotalSeconds;

                if (Character.IsEntityInBounds(enemyBullet.X, enemyBullet.Y))
                {
                    Character.Health -= enemyBullet.Damage;
                    EnemyBullets.Remove(enemyBullet);
                    Creatures.Remove(enemyBullet);
                }
            }
        }
Esempio n. 6
0
        // An Elapsed time ticker based on SetTimer,
        private void ATimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                foreach (SpaceObject r in Rocks.ToList())
                {
                    if (r != null)
                    {
                        r.XCoordinate += r.Velocity * Math.Cos(Math.PI * r.OriginalAngle / 180);
                        r.YCoordinate += r.Velocity * Math.Sin(Math.PI * r.OriginalAngle / 180);
                        r.Theta       += 3 * Math.Cos(Math.PI * r.OriginalAngle / 180);

                        if (r.XCoordinate > WINDOWWIDTH - 50)
                        {
                            r.XCoordinate = -50;
                        }
                        else if (r.XCoordinate < -50)
                        {
                            r.XCoordinate = WINDOWWIDTH - 50;
                        }
                        if (r.YCoordinate > WINDOWHEIGHT - 50)
                        {
                            r.YCoordinate = -50;
                        }
                        else if (r.YCoordinate < -50)
                        {
                            r.YCoordinate = WINDOWHEIGHT - 50;
                        }
                    }
                }
                // Player1 Score increases for every mili second your alive
                Player1Ship.Score++;

                //// Move player 1
                if (accel)
                {
                    if (Player1Ship.Velocity <= 3 * VELOCITY)
                    {
                        Player1Ship.Velocity += .1;
                    }
                }
                else
                {
                    if (Player1Ship.Velocity <= 0)
                    {
                        Player1Ship.Velocity = 0;
                    }
                    else
                    {
                        Player1Ship.Velocity -= .08;
                    }
                }

                if (left)
                {
                    Player1Ship.Theta -= 3;
                }
                if (right)
                {
                    Player1Ship.Theta += 3;
                }

                if (shoot)  // add a bullet
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        var bullet = new SpaceObject('B', Player1Ship.XCoordinate + 8, Player1Ship.YCoordinate + 8, 10, 4 * VELOCITY, Player1Ship.Theta);
                        listOfSpaceObjects.Add(bullet);
                    }));
                }


                Player1Ship.XCoordinate += Player1Ship.Velocity * Math.Cos((Math.PI * Player1Ship.Theta / 180));
                Player1Ship.YCoordinate += Player1Ship.Velocity * Math.Sin((Math.PI * Player1Ship.Theta / 180));
                if (Player1Ship.XCoordinate > WINDOWWIDTH - 50)
                {
                    Player1Ship.XCoordinate = -50;
                }
                else if (Player1Ship.XCoordinate < -50)
                {
                    Player1Ship.XCoordinate = WINDOWWIDTH - 50;
                }
                if (Player1Ship.YCoordinate > WINDOWHEIGHT - 50)
                {
                    Player1Ship.YCoordinate = -50;
                }
                else if (Player1Ship.YCoordinate < -50)
                {
                    Player1Ship.YCoordinate = WINDOWHEIGHT - 50;
                }

                // Score increases for every millisecodn you're alive
                Player2Ship.Score++;
                // Move player 2 Ship
                if (enemyAccel)
                {
                    if (Player2Ship.Velocity <= 3 * VELOCITY)
                    {
                        Player2Ship.Velocity += .1;
                    }
                }
                else
                {
                    if (Player2Ship.Velocity <= 0)
                    {
                        Player2Ship.Velocity = 0;
                    }
                    else
                    {
                        Player2Ship.Velocity -= .08;
                    }
                }

                if (enemyLeft)
                {
                    Player2Ship.Theta -= 3;
                }
                if (enemyRight)
                {
                    Player2Ship.Theta += 3;
                }
                if (enemyShoot)  // add a enemy bullet
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        var bullet = new SpaceObject('F', Player2Ship.XCoordinate + 8, Player2Ship.YCoordinate + 8, 10, 4 * VELOCITY, Player2Ship.Theta);
                        listOfSpaceObjects.Add(bullet);
                    }));
                }
                Player2Ship.XCoordinate += Player2Ship.Velocity * Math.Cos((Math.PI * Player2Ship.Theta / 180));
                Player2Ship.YCoordinate += Player2Ship.Velocity * Math.Sin((Math.PI * Player2Ship.Theta / 180));
                if (Player2Ship.XCoordinate > WINDOWWIDTH - 50)
                {
                    Player2Ship.XCoordinate = -50;
                }
                else if (Player2Ship.XCoordinate < -50)
                {
                    Player2Ship.XCoordinate = WINDOWWIDTH - 50;
                }
                if (Player2Ship.YCoordinate > WINDOWHEIGHT - 50)
                {
                    Player2Ship.YCoordinate = -50;
                }
                else if (Player2Ship.YCoordinate < -50)
                {
                    Player2Ship.YCoordinate = WINDOWHEIGHT - 50;
                }


                ////  Move the player1Bullets
                for (int i = 0; i < Bullets.Count(); i++)

                {
                    var b = Bullets.Skip(i).First();
                    if (b != null)
                    {
                        b.XCoordinate += b.Velocity * Math.Cos(Math.PI * b.Theta / 180);
                        b.YCoordinate += b.Velocity * Math.Sin(Math.PI * b.Theta / 180);
                        if (b.XCoordinate > WINDOWWIDTH - 50 || b.XCoordinate < -50 || b.YCoordinate > WINDOWHEIGHT - 50 || b.YCoordinate < -50)
                        {
                            RemoveSpaceObject(b);
                        }
                    }
                }
                // Move enemy bullets
                for (int i = 0; i < EnemyBullets.Count(); i++)

                {
                    var b = EnemyBullets.Skip(i).First();
                    if (b != null)
                    {
                        b.XCoordinate += b.Velocity * Math.Cos(Math.PI * b.Theta / 180);
                        b.YCoordinate += b.Velocity * Math.Sin(Math.PI * b.Theta / 180);
                        if (b.XCoordinate > WINDOWWIDTH - 50 || b.XCoordinate < -50 || b.YCoordinate > WINDOWHEIGHT - 50 || b.YCoordinate < -50)
                        {
                            RemoveSpaceObject(b);
                        }
                    }
                }


                // Check for collisions. If bullet hits rock, remove/split rock if rock hits ship, reset ship
                foreach (SpaceObject rock in Rocks.ToList())
                {
                    if (rock != null)
                    {
                        foreach (SpaceObject b in Bullets.ToList())
                        {
                            //var b = Bullets.Skip(j).First();
                            if (b != null)
                            {
                                if (((b.XCoordinate > rock.XCoordinate && b.XCoordinate < rock.XCoordinate + rock.Height) ||
                                     (b.XCoordinate + 5 > rock.XCoordinate && b.XCoordinate + 5 < rock.XCoordinate + rock.Height)) &&
                                    ((b.YCoordinate > rock.YCoordinate && b.YCoordinate < rock.YCoordinate + rock.Height) ||
                                     (b.YCoordinate + 5 > rock.YCoordinate && b.YCoordinate + 5 < rock.YCoordinate + rock.Height)))
                                {
                                    Player1Ship.Score += Math.Pow((rock.NumberOfHits + 1), 2) * 100;
                                    RemoveSpaceObject(rock);
                                    RemoveSpaceObject(b);
                                }
                            }
                        }

                        // Chcek against Player2 Bullets
                        foreach (SpaceObject b in EnemyBullets.ToList())
                        //for (int j = 0; j < EnemyBullets.Count(); j++)
                        {
                            //var b = EnemyBullets.Skip(j).First();
                            if (b != null)
                            {
                                if (((b.XCoordinate > rock.XCoordinate && b.XCoordinate < rock.XCoordinate + rock.Height) ||
                                     (b.XCoordinate + 5 > rock.XCoordinate && b.XCoordinate + 5 < rock.XCoordinate + rock.Height)) &&
                                    ((b.YCoordinate > rock.YCoordinate && b.YCoordinate < rock.YCoordinate + rock.Height) ||
                                     (b.YCoordinate + 5 > rock.YCoordinate && b.YCoordinate + 5 < rock.YCoordinate + rock.Height)))
                                {
                                    Player2Ship.Score += Math.Pow((rock.NumberOfHits + 1), 2) * 100;
                                    RemoveSpaceObject(rock);
                                    RemoveSpaceObject(b);
                                }
                            }
                        }

                        if (((Player1Ship.XCoordinate > rock.XCoordinate && Player1Ship.XCoordinate < rock.XCoordinate + rock.Height) ||
                             (Player1Ship.XCoordinate + Player1Ship.Height > rock.XCoordinate && Player1Ship.XCoordinate + Player1Ship.Height < rock.XCoordinate + rock.Height)) &&
                            ((Player1Ship.YCoordinate > rock.YCoordinate && Player1Ship.YCoordinate < rock.YCoordinate + rock.Height) ||
                             (Player1Ship.YCoordinate + Player1Ship.Height > rock.YCoordinate && Player1Ship.YCoordinate + Player1Ship.Height < rock.YCoordinate + rock.Height)))
                        {
                            ShipHit();
                        }
                        if (((Player2Ship.XCoordinate > rock.XCoordinate && Player2Ship.XCoordinate < rock.XCoordinate + rock.Height) ||
                             (Player2Ship.XCoordinate + Player2Ship.Height > rock.XCoordinate && Player2Ship.XCoordinate + Player2Ship.Height < rock.XCoordinate + rock.Height)) &&
                            ((Player2Ship.YCoordinate > rock.YCoordinate && Player2Ship.YCoordinate < rock.YCoordinate + rock.Height) ||
                             (Player2Ship.YCoordinate + Player2Ship.Height > rock.YCoordinate && Player1Ship.YCoordinate + Player1Ship.Height < rock.YCoordinate + rock.Height)))
                        {
                            EnemyShipHit();
                        }
                    }
                }
                foreach (SpaceObject b in Bullets)
                {
                    if (((b.XCoordinate > Player2Ship.XCoordinate && b.XCoordinate < Player2Ship.XCoordinate + Player2Ship.Height) ||
                         (b.XCoordinate + 5 > Player2Ship.XCoordinate && b.XCoordinate + 5 < Player2Ship.XCoordinate + Player2Ship.Height)) &&
                        ((b.YCoordinate > Player2Ship.YCoordinate && b.YCoordinate < Player2Ship.YCoordinate + Player2Ship.Height) ||
                         (b.YCoordinate + 5 > Player2Ship.YCoordinate && b.YCoordinate + 5 < Player2Ship.YCoordinate + Player2Ship.Height)))
                    {
                        RemoveSpaceObject(b);
                        Player1Ship.Score += 500;
                        EnemyShipHit();
                    }
                }
                foreach (SpaceObject b in EnemyBullets)
                {
                    if (((b.XCoordinate > Player1Ship.XCoordinate && b.XCoordinate < Player1Ship.XCoordinate + Player1Ship.Height) ||
                         (b.XCoordinate + 5 > Player1Ship.XCoordinate && b.XCoordinate + 5 < Player1Ship.XCoordinate + Player1Ship.Height)) &&
                        ((b.YCoordinate > Player1Ship.YCoordinate && b.YCoordinate < Player1Ship.YCoordinate + Player1Ship.Height) ||
                         (b.YCoordinate + 5 > Player1Ship.YCoordinate && b.YCoordinate + 5 < Player1Ship.YCoordinate + Player1Ship.Height)))
                    {
                        RemoveSpaceObject(b);
                        Player2Ship.Score += 5000;
                        ShipHit();
                    }
                }
            }
            catch (System.InvalidOperationException)
            {
                return;
            }

            // Checking for bullets hitting ships and ships hitting ships.
        }
Esempio n. 7
0
        /// <summary>
        /// 1フレームぶんの処理を行う。
        /// </summary>
        public void Update()
        {
            // スクリプト実行
            runner.Step();

            // 自機
            OwnChar.Update(key);

            // 敵
            Enemies.ForEach(enemy => enemy.Update());

            // 自機の弾
            OwnBullets.ForEach(bullet => bullet.Update());

            // 敵の弾
            EnemyBullets.ForEach(bullet => bullet.Update());

            // ボス
            if (Boss != null)
            {
                Boss.Update();
            }

            // 画面外の弾を削除
            OwnBullets.RemoveAll(bullet =>
                                 bullet.Position.X < -bullet.Radius ||
                                 bullet.Position.Y < -bullet.Radius ||
                                 bullet.Position.X > 640 + bullet.Radius ||
                                 bullet.Position.Y > 480 + bullet.Radius);
            EnemyBullets.RemoveAll(bullet =>
                                   bullet.Position.X < -bullet.Radius ||
                                   bullet.Position.Y < -bullet.Radius ||
                                   bullet.Position.X > 640 + bullet.Radius ||
                                   bullet.Position.Y > 480 + bullet.Radius);

            // 敵と弾の当たり判定
            for (var bi = OwnBullets.Count - 1; bi >= 0; --bi)
            {
                var bullet = OwnBullets[bi];
                for (var ei = Enemies.Count - 1; ei >= 0; --ei)
                {
                    var enemy = Enemies[ei];
                    if (collidesCircleCircle(
                            bullet.Position.X, bullet.Position.Y, bullet.Radius,
                            enemy.Position.X, enemy.Position.Y, enemy.Radius))
                    {
                        enemy.OnDamaged(bullet.Power);
                        OwnBullets.RemoveAt(bi);
                        break;
                    }
                }
            }
            Enemies.RemoveAll(enemy => enemy.Dead);

            // ボスと弾の当たり判定
            if (Boss != null)
            {
                for (var bi = OwnBullets.Count - 1; bi >= 0; --bi)
                {
                    var bullet = OwnBullets[bi];
                    if (collidesCircleCircle(
                            bullet.Position.X, bullet.Position.Y, bullet.Radius,
                            Boss.Position.X, Boss.Position.Y, Boss.Radius))
                    {
                        Boss.OnDamaged(bullet.Power);
                        OwnBullets.RemoveAt(bi);
                    }
                }
            }

            // 自機と敵の当たり判定
            foreach (var enemy in Enemies)
            {
                if (collidesCircleCircle(
                        OwnChar.Position.X, OwnChar.Position.Y, OwnChar.Radius,
                        enemy.Position.X, enemy.Position.Y, enemy.Radius))
                {
                    failed = !DebugMode;
                }
            }

            // 自機とボスの当たり判定
            if (Boss != null)
            {
                if (collidesCircleCircle(
                        OwnChar.Position.X, OwnChar.Position.Y, OwnChar.Radius,
                        Boss.Position.X, Boss.Position.Y, Boss.Radius))
                {
                    failed = !DebugMode;
                }
            }

            // 自機と敵の弾の当たり判定
            foreach (var bullet in EnemyBullets)
            {
                if (collidesCircleCircle(
                        OwnChar.Position.X, OwnChar.Position.Y, OwnChar.Radius,
                        bullet.Position.X, bullet.Position.Y, bullet.Radius))
                {
                    failed = !DebugMode;
                }
            }

            // R キーで自滅
            if (key.IsPressed(DX.KEY_INPUT_R))
            {
                failed = true;
            }
        }