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>
        /// Updates the slider
        /// </summary>
        /// <param name="elapsed">Time elapsed since the last call</param>
        public override void update(float elapsed)
        {
            if (this.alreadyPicked)
            {
                Vector2 delta = InputManager.getInstance().MousePosition - InputManager.getInstance().PreviousMousePosition;
                if (delta.X < 0)
                {
                    this.CurrentValue -= .05f;
                    setPosition();
                }
                else if (delta.X > 0)
                {
                    this.CurrentValue += .05f;
                    setPosition();
                }
            }

            if (InputManager.getInstance().isLeftButtonDown())
            {
                if (PickingUtils.pickVector(InputManager.getInstance().MousePosition, this.bbox))
                {
                    this.alreadyPicked = true;
                }
            }
            else if (!InputManager.getInstance().isLeftButtonDown())
            {
                this.alreadyPicked = false;
            }
            this.bar.update(elapsed);
            this.ball.update(elapsed);
            this.text.WrittenText = getValue();
            this.text.update(elapsed);
        }
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)
        {
            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.º 4
0
 public void update(float elapsed)
 {
     foreach (var icon in icons)
     {
         if (icon != null)
         {
             icon.update(elapsed);
         }
     }
     for (int i = 0; i < selected.Count; i++)
     {
         if (InputManager.getInstance().wasLeftButtonPressed())
         {
             if (PickingUtils.pickVector(InputManager.getInstance().MousePosition, selected[i].BBox))
             {
                 this.changeSelected.Invoke(i);
                 break;
             }
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Updates the Checkbox
        /// </summary>
        /// <param name="elapsed">Time elapsed since the last call</param>
        public override void update(float elapsed)
        {
            if (InputManager.getInstance().wasLeftButtonPressed())
            {
                // if we were inside the checkbox
                if (PickingUtils.pickVector(InputManager.getInstance().MousePosition, this.bbox))
                {
                    this.Checked = !this.Checked;
                }
            }


            if (this.Checked)
            {
                this.activeImg = this.checkedBoxImag;
            }
            else
            {
                this.activeImg = this.uncheckedBoxImag;
            }

            this.activeImg.update(elapsed);
            this.text.update(elapsed);
        }
Exemplo n.º 6
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.º 7
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.º 8
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.pickVector(actorsPosition, this.bbox));
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public virtual void update(float elapsed)
        {
            linesOfSight.Clear();
            closestsGhosts.Clear();

            foreach (var mob in mobs)
            {
                mob.update(elapsed);
            }
            foreach (var dead in this.theDead)
            {
                if (dead != null)
                {
                    dead.update(elapsed);
                }
            }
            foreach (var ghost in this.allGhosts)
            {
                ghost.update(elapsed);
            }

            updateFieldOfView(elapsed);
            updateSkills(elapsed);
            this.hud.updateSkills(this.selectedGhosts);
            this.hud.update(elapsed);

            CombatManager.getInstance().update(elapsed);
            EffectsManager.getInstance().update(elapsed);
            SoundManager.getInstance().update();

            if (looseConditionDetected())
            {
                ((GameDisplayState)GameStateMachine.getInstance().CurrentState).goToGameOver();
            }
            else if (winConditionAchieved())
            {
                LevelContext context = new LevelContext()
                {
                    Ghosts   = allGhosts,
                    MapIndex = GameStateMachine.getInstance().LevelContext.MapIndex
                };
                GameStateMachine.getInstance().LevelContext = context;
                GameStateMachine.getInstance().goToNextState();
            }

            if (InputManager.getInstance().wasLeftButtonPressed())
            {
                if (!InputManager.getInstance().isKeyDown(Keys.LeftShift))
                {
                    clearSelectedGhosts();
                }

                foreach (var ghost in allGhosts)
                {
                    if (PickingUtils.pickVector(InputManager.getInstance().MousePosition, ghost.BBox) && !ghost.Selected)
                    {
                        selectGhost(ghost);
                    }
                }
            }

            // ghosts spawned as part of this cycle are not applicable to the current frame so add them here
            if (this.recentlySpawned != null && this.recentlySpawned.Count > 0)
            {
                this.allGhosts.AddRange(this.recentlySpawned);
                this.recentlySpawned = new List <Ghost>();
            }
#if DEBUG
            /*Point mouse = InputManager.getInstance().MousePosition.toPoint();
             * GWNorthEngine.AI.AStar.BasePathFinder.TypeOfSpace space = AIManager.getInstance().Board[mouse.Y, mouse.X];
             * Debug.log(space.ToString());*/
            MapEditor.getInstance().update();
#endif
        }