Exemple #1
0
    public void Serve()
    {
        if (!InPlay && !servePrepped)
        {
            PrepServe();
            return;
        }

        Collider     paddleCol = player.GetComponent <Collider>();
        Vector3      paddleCtr = player.gameObject.transform.position;
        PaddlePlayer paddle    = player.GetComponent <PaddlePlayer>();

        float paddleX = paddleCol.bounds.extents.x;
        float paddleY = paddleCol.bounds.extents.y;

        if (launchPoint.x <= paddleCtr.x + paddleX && launchPoint.x >= paddleCtr.x - paddleX &&     // between x direction
            launchPoint.y <= paddleCtr.y + paddleY && launchPoint.y >= paddleCtr.y - paddleY)       // between y direction
        {
            GameBall.Serve(paddle.Velocity);

            InPlay       = true;
            servePrepped = false;
        }
    }
Exemple #2
0
        public GameController(ChangeGame gameIn, GraphicsController graphicsControllerIn, InputController inputControllerIn)
        {
            // Set references.
            game = gameIn;
            graphicsController = graphicsControllerIn;
            inputController    = inputControllerIn;

            // Add reference to graphics controller.
            graphicsController.SetGameControllerReference(this);

            // Define state definitions (with references to this GameController instance's content).
            #region State definitions
            GameState.Title = new GameState("title")
            {
                OnEnterState  = ResetContent,
                OnStateUpdate = UpdateMainMenu
            };
            GameState.MapControls = new GameState("mapcontrols")
            {
                OnEnterState  = StartMappingControls,
                OnStateUpdate = UpdateMapControls
            };
            GameState.Playing = new GameState("playing")
            {
                OnEnterState  = OnStartPlaying,
                OnStateUpdate = UpdatePlay
            };
            GameState.BetweenStages = new GameState("betweenstages")
            {
                OnEnterState  = () => { },
                OnStateUpdate = (GameTime gameTime) =>
                {
                    UpdatePlay(gameTime);
                    UpdateBetweenStages(gameTime);
                }
            };
            GameState.GameOver = new GameState("gameover")
            {
                OnEnterState = () =>
                {
                    gameOverMenu.Drop();

                    bestCoinScore = Math.Max(bestCoinScore, currentCoinScore);

                    laserPlayer.FiringLaser = false;
                    SoundController.StopAllLoops();
                },
                OnStateUpdate = UpdateGameOverMenu
            };
            #endregion

            // Set up controllers.
            coinBackgroundController = new CoinBackgroundController();

            // Set up menus.
            mainMenu          = new MainMenu(game, this);
            gameOverMenu      = new GameOverMenu(this);
            stageCompleteMenu = new StageCompleteMenu();

            // Set up players.
            laserPlayer  = new LaserPlayer(this);
            paddlePlayer = new PaddlePlayer();

            // Define collections.
            enemies     = new List <Enemy>();
            corpses     = new List <EnemyCorpse>();
            notes       = new List <Note>();
            notesOnFire = new List <NoteOnFire>();

            // Define timers.
            piggyBankSpawner          = new Timer(30000);
            piggyBankSpawner.Elapsed += (a, b) => ReadyToSpawnPiggyBank = true;

            vacuumSpawner          = new Timer();
            vacuumSpawner.Elapsed += (a, b) => ReadyToSpawnVacuum = true;

            noteSpawner          = new Timer();
            noteSpawner.Elapsed += (a, b) => ReadyToSpawnNote = true;
        }