コード例 #1
0
        protected void RestartGame()
        {
            life         = 3;
            points       = 0;
            isSplash     = false;
            isSummary    = false;
            isSpacePress = false;

            isPPress = false;

            nameEnemy.Clear();
            nameBullet.Clear();
            BulletsToRemove.Clear();

            objectsToCheckForCollision.Clear();

            screenManager.moveFontOnTheScreen(GameStatesEnum.GAME, "life_font", new Point(25, 460));
            screenManager.changeTextOfTheFontOnScreen(GameStatesEnum.GAME, "life_font", "Life: " + life);

            screenManager.moveFontOnTheScreen(GameStatesEnum.GAME, "point_font", new Point(85, 460));
            screenManager.changeTextOfTheFontOnScreen(GameStatesEnum.GAME, "point_font", "Points: " + points);

            currentGameState = GameStatesEnum.GAME;
        }
コード例 #2
0
        protected void playGame()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Left) && screenManager.getScreen(GameStatesEnum.GAME).GetGameObject("plane").ObjectShape.X > 0)
            {
                screenManager.getScreen(GameStatesEnum.GAME).GetGameObject("plane").MovmentVector = new MovmentVector(plane_x_direction, plane_y_direction);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right) && screenManager.getScreen(GameStatesEnum.GAME).GetGameObject("plane").ObjectShape.X < width)
            {
                screenManager.getScreen(GameStatesEnum.GAME).GetGameObject("plane").MovmentVector = new MovmentVector(-plane_x_direction, plane_y_direction);
            }
            else
            {
                screenManager.getScreen(GameStatesEnum.GAME).GetGameObject("plane").MovmentVector = new MovmentVector(0, 0);
            }



            if (Keyboard.GetState().IsKeyDown(Keys.Space) && !isSpacePress)
            {
                generateBullet();
                isSpacePress = true;
            }
            else if (Keyboard.GetState().IsKeyUp(Keys.Space) && isSpacePress)
            {
                isSpacePress = false;
            }



            foreach (var bullet in nameBullet)
            {
                List <string> collision_objects = new List <string>();
                current_enemies.ForEach(enemy => collision_objects.Add(enemy));
                collision_objects.Add("plane");
                pottentialCollisionObjectName = screenManager.getScreen(GameStatesEnum.GAME).checkIfObjectIsInCollisionWithOtherObjects(bullet, collision_objects);

                if (pottentialCollisionObjectName != null && pottentialCollisionObjectName != "plane")
                {
                    if (pottentialCollisionObjectName == enemy_selected_to_charge_name)
                    {
                        was_enemy_shoot_down = true;
                    }
                    screenManager.getScreen(GameStatesEnum.GAME).removeObject(pottentialCollisionObjectName);

                    current_enemies.Remove(pottentialCollisionObjectName);
                    RemoveEnemyFromHisDictionnary(pottentialCollisionObjectName);
                    BulletsToRemove.Add(bullet);


                    points++;

                    screenManager.moveFontOnTheScreen(GameStatesEnum.GAME, "point_font", new Point(85, 460));
                    screenManager.changeTextOfTheFontOnScreen(GameStatesEnum.GAME, "point_font", "Points: " + points);
                }
                else if (pottentialCollisionObjectName == "plane")
                {
                    BulletsToRemove.Add(bullet);
                    life--;


                    screenManager.getScreen(GameStatesEnum.GAME).moveObjectToTheMiddleOfTheWidth("plane",
                                                                                                 screenManager.getSelectedScreenHeight(GameStatesEnum.GAME) -
                                                                                                 (screenManager.getGameObjectFromTheScreen(GameStatesEnum.GAME, "plane").ObjectShape.Height + 25));

                    screenManager.moveFontOnTheScreen(GameStatesEnum.GAME, "life_font", new Point(25, 460));
                    screenManager.changeTextOfTheFontOnScreen(GameStatesEnum.GAME, "life_font", "Life: " + life);
                }
            }

            foreach (var bullet in BulletsToRemove)
            {
                screenManager.getScreen(GameStatesEnum.GAME).removeObject(bullet);
                nameBullet.Remove(bullet);
            }
            BulletsToRemove.Clear();


            if (enemy_arrival_dict["left_top"].Count == 0)
            {
                generateEnemiesOnTheMap("left_top");
                left_top_index = 0;
                move_left_top  = true;
            }
            if (enemy_arrival_dict["left_bottom"].Count == 0)
            {
                generateEnemiesOnTheMap("left_bottom");
                left_bottom_index = 0;
                move_left_bottom  = true;
            }
            if (enemy_arrival_dict["right_top"].Count == 0)
            {
                generateEnemiesOnTheMap("right_top");
                right_top_index = 0;
                move_right_top  = true;
            }
            if (enemy_arrival_dict["right_bottom"].Count == 0)
            {
                generateEnemiesOnTheMap("right_bottom");
                right_bottom_index = 0;
                move_right_bottom  = true;
            }
            //TODO: Tymczasowo twardo zakodowane wartości
            if (move_left_top)
            {
                moveEnemiesFromSelectedGroupByCurve("left_top", ref left_top_index);
            }
            if (move_left_bottom)
            {
                moveEnemiesFromSelectedGroupByCurve("left_bottom", ref left_bottom_index);
            }
            if (move_right_top)
            {
                moveEnemiesFromSelectedGroupByCurve("right_top", ref right_top_index);
            }
            if (move_right_bottom)
            {
                moveEnemiesFromSelectedGroupByCurve("right_bottom", ref right_bottom_index);
            }
            if (enemy_movment_counter == 0)
            {
                enemy_x_movment = -enemy_x_movment;
                //ruch przeciwników w lewo i prawo
                foreach (var enemy in current_enemies)
                {
                    screenManager.getGameObjectFromTheScreen(currentGameState, enemy).changeMovementVector(enemy_x_movment,
                                                                                                           screenManager.getGameObjectFromTheScreen(currentGameState, enemy).MovmentVector.Y_movment);
                }

                enemy_movment_counter = 60;
            }
            else
            {
                enemy_movment_counter--;
            }
            if (enemy_charge_counter == 0 && is_enemy_charging == false)
            {
                ChargeEnemy();
                was_enemy_shoot_down   = false;
                lasting_charge_counter = 60;
                enemy_charge_counter   = 240;
            }
            else if (enemy_charge_counter > 0 && is_enemy_charging == false)
            {
                enemy_charge_counter--;
            }
            if (lasting_charge_counter == 0 && is_enemy_charging == true)
            {
                if (was_enemy_shoot_down == false)
                {
                    generate_enemy_bullet();
                }

                make_enemy_return();
                lasting_return_counter = 60;
            }
            else if (lasting_charge_counter > 0 && is_enemy_charging == true)
            {
                lasting_charge_counter--;
            }

            if (lasting_return_counter == 0 && is_enemy_returning == true && is_enemy_charging == false)
            {
                stopEnemy();
            }
            else if (lasting_return_counter > 0 && is_enemy_returning == true && is_enemy_charging == false)
            {
                lasting_return_counter--;
            }


            if (life == 0)
            {
                currentGameState = GameStatesEnum.SUMMARY;
            }
        }