Example #1
0
        private void SpawnAllEnemies()
        {
            for (int i = 0; i < 4; i++)
            {
                int          randX      = random.Next(200, GalagaGame.GAME_WIDTH - 200);
                int          randY      = random.Next(500, GalagaGame.GAME_HEIGHT);
                List <Point> bezierMove = QuadraticBezier.CalculatePoints(
                    new Point(-200 + (i * 600), -100),
                    //new Point(GalagaGame.GAME_WIDTH / 2, GalagaGame.GAME_HEIGHT),
                    //new Point(randX, randY),
                    getRandomPointOnScreen(),
                    new Point(GalagaGame.GAME_WIDTH / 2, 700),
                    30);

                for (int j = 0; j < 6; j++)
                {
                    int   tempJ         = j;
                    int   tempI         = i;
                    Timer firstRowTimer = new Timer((t) =>
                    {
                        EnemyShip en                 = new EnemyShip(-200 + (i * 600), -100, (ShipTypeEnum)(tempI + 2), 0);
                        en.PositionOnGrid.X          = tempJ;
                        en.PositionOnGrid.Y          = tempI;
                        List <Point> moveWithLanding = new List <Point>(bezierMove);

                        en.BeginMovingOnCurve(moveWithLanding, 1.0f);
                    }, 200 * j + 1500 * i, false);
                }
            }
        }
Example #2
0
        public override void Update(int deltaTime)
        {
            Bullet.UpdateBulletsPosition(deltaTime, this);
            EnemyShip.UpdateEnemyPosition(deltaTime, this);

            // random shooting
            if (!playerIsDead && random.Next() % 50 == 5)
            {
                foreach (RotatingShip ship in RotatingShip.ListOfShips)
                {
                    if (ship is EnemyShip)
                    {
                        if (random.Next() % 70 == 6)
                        {
                            Bullet b = new Bullet(ship.Hitbox.Center.X - 2 * RotatingShip.Scale, ship.Position.Y, BulletType.ENEMY);
                        }
                    }
                }
            }

            // choose one enemy on grid and do random movement
            if (!playerIsDead && random.Next() % 60 == 5)
            {
                foreach (RotatingShip ship in RotatingShip.ListOfShips)
                {
                    if (ship is EnemyShip)
                    {
                        EnemyShip enemy = (EnemyShip)ship;
                        if (random.Next() % 30 == 6 && enemy.MovingOnGrid)
                        {
                            List <Point> road_1 = QuadraticBezier.CalculatePoints(
                                new Point((int)enemy.Position.X, (int)enemy.Position.Y),
                                getRandomPointOnScreen(),
                                getRandomPointOnScreen(), 30);
                            enemy.BeginMovingOnCurve(road_1, 1.0f);
                        }
                    }
                }
            }
        }