Example #1
0
 /// <summary>
 /// The Ballmanager's constructor is used to inject required references.
 /// </summary>
 /// <param name="inInputManager">The input manager reference to determine the mouse position etc</param>
 /// <param name="inStateManager">The state manager for declaring victory conditions</param>
 /// <param name="inLandscape">The landscape reference </param>
 /// <param name="inStartingBalls">The number of balls to start with this game</param>
 public BallManager(InputManager inInputManager, StateManager inStateManager, Landscape inLandscape, int inStartingBalls, KeyPlayer inPlayer)
 {
     ballCount    = inStartingBalls;
     player       = inPlayer;
     stateManager = inStateManager;
     inputManager = inInputManager;
     landscape    = inLandscape;
 }
Example #2
0
        public static void startup(int ballNum, Managers.InputManager inputManager, Managers.StateManager stateManager)
        {
            List <GameObjects.IGameObject> StartingObjectList = new List <GameObjects.IGameObject>();

            //Create Gameobjects present at Game Start
            GameObjects.ObjectTypes.Landscape landscape = new GameObjects.ObjectTypes.Landscape(50, 100, 10, 5, 3, 4);
            StartingObjectList.Add(landscape);
            GameObjects.ObjectTypes.KeyPlayer   player     = new GameObjects.ObjectTypes.KeyPlayer(inputManager, stateManager, landscape, 4);
            GameObjects.ObjectTypes.BallManager BallPlayer = new GameObjects.ObjectTypes.BallManager(inputManager, stateManager, landscape, ballNum, player);
            StartingObjectList.Add(player);
            StartingObjectList.Add(BallPlayer);
            //End startup objects

            stateManager.setObjectList(StartingObjectList, ballNum);
        }
Example #3
0
        /// <summary>
        /// doMove handles the moving of the ball, checking whether the ball has been clicked, starting its explosion
        /// determining collisions with the walls, and collisions with the keyboard player.
        /// </summary>
        /// <param name="player">Player reference handed in from the BallManager</param>
        /// <param name="landscape">Landscape reference from the BallManager</param>
        /// <param name="inputManager">InputManager reference from the BallManager</param>
        /// <param name="stateManager">StateManager reference from the BallManager</param>
        /// <param name="threshold">explode and solidify threshold passed in from the BallManager</param>
        public void DoMove(KeyPlayer player, Landscape landscape, InputManager inputManager, StateManager stateManager, int threshold)
        {
            bounceTime++;
            bounds.Width  = landscape.pixelWidthPerTile;
            bounds.Height = landscape.pixelWidthPerTile;

            //handle E x p l o s i o n s
            if (exploding == threshold)
            {
                if ((landscapeCol > 2 && landscapeCol < landscape.landscapeWidth - 2) &&
                    (landscapeRow > 2 && landscapeRow < landscape.landscapeHeight - 2))
                {
                    for (int row = -2; row < 3; row++)
                    {
                        for (int col = -1; col < 2; col++)
                        {
                            landscape.tilesMap[landscapeRow + row][landscapeCol + col].tileType = LandscapeType.dirt;
                        }
                    }
                }
                exploding++;
            }
            else if (exploding == 1)
            {
                bounds.Width  *= 5;
                bounds.Height *= 5;
                exploding++;
            }
            else if (exploding > 0)
            {
                exploding++;
            }

            //handle S o l i d i f y i n g
            if (solidifying == threshold)
            {
                if ((landscapeCol > 2 && landscapeCol < landscape.landscapeWidth - 2) &&
                    (landscapeRow > 2 && landscapeRow < landscape.landscapeHeight - 2))
                {
                    for (int row = -2; row < 3; row++)
                    {
                        for (int col = -1; col < 2; col++)
                        {
                            landscape.tilesMap[landscapeRow + row][landscapeCol + col].tileType = LandscapeType.bedrock;
                        }
                    }
                }
                solidifying++;
            }
            else if (solidifying > 0)
            {
                solidifying++;
            }

            //on spawn set the bounds to the correct location
            if (bounds.X < 0 && bounds.Y < 0 && landscape.pixelHeightPerTile > 0)
            {
                bounds.X = (landscapeCol * landscape.pixelWidthPerTile);
                bounds.Y = (landscapeRow * landscape.pixelHeightPerTile);
            }
            else
            {
                if (bounceTime > bounceCooldown)
                {
                    if (bounds.X <= 0 || bounds.Right >= landscape.landscapeWidth * landscape.pixelWidthPerTile)
                    {
                        headingDirection[0] *= -1;
                        bounceTime           = 0;
                    }
                    if (bounds.Y <= 0 || bounds.Bottom >= landscape.landscapeHeight * landscape.pixelHeightPerTile)
                    {
                        headingDirection[1] *= -1;
                        bounceTime           = 0;
                    }
                }
                bounds.X = (int)(bounds.X + headingDirection[0]);
                bounds.Y = (int)(bounds.Y + headingDirection[1]);
                //mouse influence (IT'S A FEATURE)
                //bounds.X = (int)(bounds.X + (inputManager.mouseCoords[0] - bounds.X) * 0.008);
                //bounds.Y = (int)(bounds.Y + (inputManager.mouseCoords[1] - bounds.Y) * 0.008);
            }
            if (landscape.pixelWidthPerTile != 0 && landscape.pixelHeightPerTile != 0)
            {
                landscapeCol = (bounds.X + (bounds.Width / 2)) / landscape.pixelWidthPerTile;
                landscapeRow = (bounds.Y + (bounds.Height / 2)) / landscape.pixelHeightPerTile;
            }
            //Mouse clicking on ball
            if ((inputManager.mouseCoords[0] > bounds.X && inputManager.mouseCoords[0] < bounds.X + bounds.Width) &&
                (inputManager.mouseCoords[1] > bounds.Y && inputManager.mouseCoords[1] < bounds.Y + bounds.Height))
            {
                if (inputManager.clickDown && exploding == 0 && solidifying == 0)
                {
                    exploding = 1;
                }
                else if (inputManager.rightClickDown && exploding == 0 && solidifying == 0)
                {
                    solidifying = 1;
                }
            }
            //ball hitting player
            if (!player.invincible && bounds.IntersectsWith(player.bounds))
            {
                player.invincible = true;
                player.health    -= 1;
                if (player.health <= 0)
                {
                    stateManager.ballVictory();
                }
                else
                {
                    player.image = Image.FromFile(String.Format("../../images/charHealth-{0}.png", player.health));
                }
            }
        }