Пример #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);
                }
            }
        }
Пример #2
0
        public static void UpdateEnemyPosition(int deltaTime, GameMode game)
        {
            foreach (RotatingShip ship in ListOfShips)
            {
                if (ship.Type != ShipTypeEnum.PLAYER)
                {
                    EnemyShip enemy = (EnemyShip)ship;
                    if (!enemy.MovingOnCurve)
                    {
                        continue;
                    }

                    if (enemy.landing)
                    {
                        //enemy.currentPath[enemy.currentPath.Count - 1].X = (int)EnemyGrid.Position.X; // doesn't work because Point is struct
                        Point p = enemy.currentPath[enemy.currentPath.Count - 1];
                        p.X = (int)(EnemyGrid.Position.X + enemy.PositionOnGrid.X * (16 + EnemyGrid.gap) * RotatingShip.Scale);
                        enemy.currentPath[enemy.currentPath.Count - 1] = p;
                    }

                    Point src = enemy.currentPath[enemy.currentSection - 1];
                    Point dst = enemy.currentPath[enemy.currentSection];

                    Vector2 moveVector = new Vector2(dst.X - src.X, dst.Y - src.Y);
                    enemy.SetDirection(moveVector);

                    Vector2 normalized = Vector2.Normalize(moveVector);

                    enemy.Position.X += normalized.X * enemy.speed * deltaTime;
                    enemy.Position.Y += normalized.Y * enemy.speed * deltaTime;

                    enemy.traveledDistanceInSection = Vector2.Distance(
                        enemy.Position,
                        new Vector2(src.X, src.Y));

                    if (enemy.traveledDistanceInSection > moveVector.Length())
                    {
                        enemy.currentSection++;
                        enemy.traveledDistanceInSection = 0;
                        if (enemy.currentSection > enemy.currentPath.Count - 1 && !enemy.landing)
                        {
                            // end of road. Start landing procedure
                            enemy.LandOnGrid();
                            enemy.landing = true;
                            //enemy.speed = 1.0f;
                        }
                        else if (enemy.landing)
                        {
                            enemy.SetDirection(new Vector2(0, -1));
                            enemy.landing       = false;
                            enemy.MovingOnCurve = false;
                            enemy.MovingOnGrid  = true;
                            enemy.Position.X    = (int)(EnemyGrid.Position.X + enemy.PositionOnGrid.X * (16 + EnemyGrid.gap) * RotatingShip.Scale);
                            enemy.Position.Y    = (int)(EnemyGrid.Position.Y + enemy.PositionOnGrid.Y * (16 + EnemyGrid.gap) * RotatingShip.Scale);
                        }
                    }
                }
            }
        }
Пример #3
0
        public override void OnEnter()
        {
            EnemyShip.ListOfShips.Clear();
            Bullet.ListOfBullets.Clear();
            explosions.Clear();

            Lifes        = 3;
            Points       = 0;
            playerIsDead = false;
            int playerShipYposition = GalagaGame.GAME_HEIGHT - 200;

#if WINDOWS
            game.KeyboardKeysDown   += KeysHoldDown;
            game.KeyboardKeyClicked += KeyClicked;
#elif ANDROID
            playerShipYposition -= 200;
            game.ScreenTapped   += ScreenTapped;
            game.ScreenTouched  += ScreenTouched;
#endif

            playerShip = new PlayerShip(GalagaGame.GAME_WIDTH / 2, playerShipYposition);

            enemyGrid = new EnemyGrid(new Vector2(100, 200));

            SpawnAllEnemies();

            gridMovingTimer = new Timer((t) => {
                enemyGrid.UpdateEnemyGridPosition(game.deltaTime);
                enemyAnimation = (enemyAnimation == 0) ? 1 : 0;
                foreach (RotatingShip s in RotatingShip.ListOfShips)
                {
                    if (s is EnemyShip)
                    {
                        EnemyShip en = (EnemyShip)s;
                        if (en.MovingOnGrid)
                        {
                            en.SetTexture(6 + enemyAnimation);
                        }
                    }
                }
            }, 800, true);

            // shoot automatically every 0.7s in Android version
#if ANDROID
            shootingTimer = new Timer((el) => {
                if (!RotatingShip.ListOfShips.Contains(playerShip))
                {
                    return;
                }

                Bullet b = new Bullet(playerShip.Hitbox.Center.X - 2 * RotatingShip.Scale, playerShip.Position.Y, BulletType.ALLY);
                GameEvent(GameEventEnum.PLAYER_FIRE);
            }, 700, true);
#endif
        }
Пример #4
0
        public void UpdateEnemyGridPosition(int deltaTime)
        {
            if (movingRight)
            {
                Position.X += Speed * deltaTime;
            }
            else
            {
                Position.X -= Speed * deltaTime;
            }



            if (Position.X < 50)
            {
                Position.X  = 50;
                movingRight = true;
            }
            else if (Position.X > GalagaGame.GAME_WIDTH - COLS * (16 + gap) * RotatingShip.Scale - 20)
            {
                Position.X  = GalagaGame.GAME_WIDTH - COLS * (16 + gap) * RotatingShip.Scale - 20;
                movingRight = false;
            }

            foreach (RotatingShip s in EnemyShip.ListOfShips)
            {
                if (s.Type == ShipTypeEnum.PLAYER)
                {
                    continue;
                }
                EnemyShip ship = (EnemyShip)s;
                if (ship.PositionOnGrid.X != -1 && ship.MovingOnGrid)
                {
                    ship.Position.X = Position.X + ship.PositionOnGrid.X * (16 + gap) * RotatingShip.Scale;
                    ship.Position.Y = Position.Y + ship.PositionOnGrid.Y * (16 + gap) * RotatingShip.Scale;
                }
            }

            //for (int row = 0; row < ROWS; row++)
            //{
            //    for (int col = 0; col < COLS; col++)
            //    {
            //        if (Grid[col, row] != null && Grid[col, row].MovingOnGrid)
            //        {
            //            Grid[col, row].Position.X = Position.X + col *(16+1) * RotatingShip.Scale;
            //            Grid[col, row].Position.Y = Position.Y + row * (16 + 1) * RotatingShip.Scale;
            //        }
            //    }
            //}
        }
Пример #5
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);
                        }
                    }
                }
            }
        }