Exemplo n.º 1
0
 /// <summary>
 /// Handles the locking on and off of an object
 /// </summary>
 /// <param name="mousePosition">Vector2 of the mouse position used to find the object</param>
 public void handleMouseClick(Vector2 mousePosition)
 {
     if (this.lockedOnObject == null)
     {
         //find our registered object by the mouse position and padded a bit
         PropertyInfo property;
         MethodInfo   method;
         Vector2      registeredPosition;
         Rectangle    paddedInput = new Rectangle
                                        ((int)mousePosition.X - LOCK_ON_PADDING, (int)mousePosition.Y - LOCK_ON_PADDING, (int)mousePosition.X + LOCK_ON_PADDING, (int)mousePosition.Y + LOCK_ON_PADDING);
         foreach (RegisteredObject registeredObject in this.registeredObjects)
         {
             property = registeredObject.Reference.GetType().GetProperty("Position");
             if (property != null)
             {
                 method = property.GetGetMethod();
                 if (method != null)
                 {
                     registeredPosition = (Vector2)method.Invoke(registeredObject.Reference, null);
                     if (PickingUtils.pickRectangle(registeredPosition, paddedInput))
                     {
                         this.lockedOnObject = registeredObject;
                         Console.WriteLine("Locked onto " + this.lockedOnObject.ReferenceName);
                         break;
                     }
                 }
             }
         }
     }
     else
     {
         Console.WriteLine("Releasing lock from " + this.lockedOnObject.ReferenceName);
         this.lockedOnObject = null;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Determines if the actor is over the button
        /// </summary>
        /// <param name="actorsPosition">Actors current position</param>
        /// <returns>boolean based on whether the actor is over the button</returns>
        public bool isActorOver(Vector2 actorsPosition)
        {
            int x1 = (int)(base.position.X - base.origin.X);
            int y1 = (int)(base.position.Y - base.origin.Y);
            int x2 = (int)(base.texture.Width);
            int y2 = (int)(base.texture.Height);

            return(PickingUtils.pickRectangle(actorsPosition, new Rectangle(x1, y1, x2, y2)));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Determines if the actor is over the button
 /// </summary>
 /// <param name="actorsPosition">Actors current position</param>
 /// <returns>boolean based on whether the actor is over the button</returns>
 public bool isActorOver(Vector2 actorsPosition)
 {
     return(PickingUtils.pickRectangle(actorsPosition, this.pickableArea));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Determines if the actor is over the button
 /// </summary>
 /// <param name="actorsPosition">Actors current position</param>
 /// <returns>boolean based on whether the actor is over the button</returns>
 public bool isActorOver(Vector2 actorsPosition)
 {
     return(PickingUtils.pickRectangle(actorsPosition, this.renderingRectangle));
 }
Exemplo n.º 5
0
        public override void update(float elapsed)
        {
            if (this.flowers != null)
            {
                foreach (Flower flower in this.flowers)
                {
                    flower.update(elapsed);
                    flower.updateColour(base.currentTransitionTime);
                }
                if (StateManager.getInstance().CurrentState == StateManager.GameState.InitGameOver)
                {
                    StateManager.getInstance().CurrentState = StateManager.GameState.GameOver;
                }
            }

            if (this.computer != null)
            {
                this.computer.update(elapsed);
                this.computer.updateColour(base.currentTransitionTime);
            }
            if (this.player != null)
            {
                this.player.update(elapsed);
                this.player.updateColour(base.currentTransitionTime);
            }

            MouseState currentState = Mouse.GetState();

            // accept input to the tiles if the game is running
            if (StateManager.getInstance().CurrentState == StateManager.GameState.Active)
            {
                if (StateManager.getInstance().WhosTurnIsIt == StateManager.TurnType.Players)
                {
                    if (currentState.LeftButton == ButtonState.Pressed && base.previousMouseState.LeftButton == ButtonState.Released)                      // first press
                    // find the tile we clicked
                    {
                        Vector2 mousePos = new Vector2(currentState.X, currentState.Y);
                        Flower  flower   = null;
                        for (int i = 0; i < this.flowers.Length; i++)
                        {
                            flower = this.flowers[i];
                            if (flower.Type == Flower.FlowerType.None)
                            {
                                if (PickingUtils.pickRectangle(mousePos, FlowerBuilder.SpritePositioner.getInstance().getPositionsRectangle(flower.Index)))
                                {
                                    if (StateManager.getInstance().WhosTurnIsIt == StateManager.TurnType.Players)
                                    {
                                        SoundManager.getInstance().SFXEngine.playSoundEffect(this.diggingSFX);
                                        flower.initSprites(this.player);
                                        StateManager.getInstance().WhosTurnIsIt = StateManager.TurnType.Computers;
                                        this.currentDelay = 0f;
                                    }                                     /*else {// player two if we implement it
                                                                           * flower.initSprites(Flower.FlowerType.Daisy, this.computersAliveTexture, this.computersDyingTexture);
                                                                           * StateManager.getInstance().WhosTurnIsIt = StateManager.TurnType.Players;
                                                                           * }*/
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (StateManager.getInstance().WhosTurnIsIt == StateManager.TurnType.Computers)
                {
                    if (this.currentDelay >= DELAY)
                    {
                        int move = StateManager.getInstance().ActiveDifficulty.getMove(this.flowers);
                        SoundManager.getInstance().SFXEngine.playSoundEffect(this.diggingSFX);
                        this.flowers[move].initSprites(this.computer);
                        StateManager.getInstance().WhosTurnIsIt = StateManager.TurnType.Players;
                    }
                }
                Winner winner;
                if (LogicUtils.isGameOver(this.flowers, out winner))
                {
                    StateManager.getInstance().CurrentState = StateManager.GameState.InitGameOver;
                    StateManager.getInstance().Winner       = winner;
                    if (winner.winningType == LogicUtils.COMPUTERS_TYPE)
                    {
                        this.computer.Score++;
                    }
                    else if (winner.winningType == LogicUtils.PLAYERS_TYPE)
                    {
                        this.player.Score++;
                    }
                }
            }
            else if (StateManager.getInstance().CurrentState == StateManager.GameState.GameOver)
            {
                Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                this.replayButton.processActorsMovement(mousePos);
                if (this.replayButton.isActorOver(mousePos))
                {
                    if (currentState.LeftButton == ButtonState.Pressed && base.previousMouseState.LeftButton == ButtonState.Released)                      // first press
                    {
                        reset(false);
                    }
                }
            }

            if (StateManager.getInstance().CurrentTransitionState != StateManager.TransitionState.None)
            {
                Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
                if (StateManager.getInstance().CurrentTransitionState == StateManager.TransitionState.TransitionIn)
                {
                    if (this.replayButton.isActorOver(mousePos))
                    {
                        ((ColouredButton)this.replayButton).updateColours(base.fadeIn(ResourceManager.getInstance().ButtonsMouseOverColour));
                    }
                    else
                    {
                        ((ColouredButton)this.replayButton).updateColours(base.fadeIn(ResourceManager.getInstance().TextColour));
                    }
                }
                else if (StateManager.getInstance().CurrentTransitionState == StateManager.TransitionState.TransitionOut)
                {
                    if (this.replayButton.isActorOver(mousePos))
                    {
                        ((ColouredButton)this.replayButton).updateColours(base.fadeOut(ResourceManager.getInstance().ButtonsMouseOverColour));
                    }
                    else
                    {
                        ((ColouredButton)this.replayButton).updateColours(base.fadeOut(ResourceManager.getInstance().TextColour));
                    }
                }

                // if the fade ins/outs are complete we change the state
                if (base.transitionTimeElapsed())
                {
                    if (StateManager.getInstance().CurrentTransitionState == StateManager.TransitionState.TransitionIn)
                    {
                        StateManager.getInstance().CurrentTransitionState = StateManager.TransitionState.None;
                    }
                    else if (StateManager.getInstance().CurrentTransitionState == StateManager.TransitionState.TransitionOut)
                    {
                        // we need to transition in our in game menu screen
                        StateManager.getInstance().CurrentTransitionState = StateManager.TransitionState.TransitionIn;
                    }
                }
            }
            // At any time if we press escape we need to go to the in game menu
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) && base.previousKeyboardState.IsKeyUp(Keys.Escape))
            {
                StateManager.getInstance().CurrentState           = StateManager.GameState.InGameMenu;
                StateManager.getInstance().CurrentTransitionState = StateManager.TransitionState.TransitionOut;
            }
            if (StateManager.getInstance().CurrentState == StateManager.GameState.Active)
            {
                this.currentDelay += elapsed;
            }
            base.update(elapsed);
        }