예제 #1
0
    public void SwitchItem(Vector2 mousepos, EntityType et, string asset, int boundingy = 0)
    {
        //check selected entity
        Vector2 vpos   = GridPosition(mousepos + new Vector2(0, cellHeight / 2));
        Point   pos    = new Point((int)vpos.X, (int)vpos.Y);
        Entity  entity = Get(pos.X, pos.Y) as Entity;

        //replace entity
        if (entity != null)
        {
            Remove(entity.Id, pos.X, pos.Y);
            Entity newentity = new Entity(pos, asset, boundingy, et);
            if (et == EntityType.Enemy)
            {
                //get additional information from the mouse
                GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
                newentity.EnemyType = mouse.EnemyType;
            }
            else if (et == EntityType.AnimatedItem || et == EntityType.SpriteItem)
            {
                //get additional information from the mouse
                GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
                newentity.ItemType = mouse.ItemType;
            }
            Add(newentity, pos.X, pos.Y);
            newentity.InitializeTile();
        }
    }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            if (GetInformation != null)
            {
                Information = GetInformation();
            }

            if (GetRectangle != null)
            {
                Rectangle = GetRectangle();
            }

            if (GameMouse.Intersects(Rectangle))
            {
                OnHover?.Invoke();
                IsHover = true;

                if (GameMouse.IsLeftClicked)
                {
                    OnSelected?.Invoke();
                    IsSelected = true;
                }
            }
            else
            {
                OffHover.Invoke();
                IsHover = false;

                if (GameMouse.IsLeftClicked && !GameKeyboard.IsKeyDown(Keys.LeftShift))
                {
                    OffSelected?.Invoke();
                    IsSelected = false;
                }
            }
        }
예제 #3
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            MusicManager.Update();

            GameMouse.Update(gameTime);
            Camera.Update(gameTime);

            foreach (BaseScreen screen in ScreensToAdd)
            {
                Screens.Add(screen);
            }

            ScreensToAdd.Clear();

            foreach (BaseScreen screen in Screens)
            {
                // Update before handling input - otherwise if we select something the WhileSelected method will be called straightaway, which is usually undesired
                if (screen.Active)
                {
                    screen.Update(gameTime);
                }
            }

            foreach (BaseScreen screen in ScreensToRemove)
            {
                Screens.Remove(screen);
            }

            ScreensToRemove.Clear();
        }
    // Update is called once per frame
    void Update()
    {
        if (trevelState == e_travelState.TRAVELING)
        {
            if (IsInTravelTargetRadius())
            {
                trevelState = e_travelState.NOT_TRAVELING;
                //if(GameMouse.GetRefrence().curSpriteId == GameMouse.MOUSE_IMG.WAITING)
                //this check will maybe be done since we can iteract with something else and mouse will change even if we are waiting for travel to be completed
                GameMouse.GetRefrence().SetMouseSprite(GameMouse.MOUSE_STATE.NORMAL);
            }
            else if (IsInSlowDownRadius())
            {
                transform.Translate(Vector2.up * GetCurrentTravelSpeed() * Time.deltaTime * GetSLownDownFactor());
            }
            else
            {
                transform.Translate(Vector2.up * GetCurrentTravelSpeed() * Time.deltaTime);
            }
        }
        else
        {
        }

        if (Input.GetMouseButtonDown(0) && trevelState == e_travelState.NOT_TRAVELING && GameMouse.GetRefrence().IsMouseOnAnyPlanet())
        {
            pointToTravelTo = GameMouse.GetRefrence().lastHoveredPlanet.transform.position;
            RotateTowardsTarget();
            ResetMovementStartTime();
            trevelState = e_travelState.TRAVELING;
            GameMouse.GetRefrence().SetMouseSprite(GameMouse.MOUSE_STATE.WAITING);
        }
    }
예제 #5
0
    public void LoadLevel(string path)
    {
        GameObjectList entities = new GameObjectList(2, "entities");

        RootList.Add(entities);

        GameObjectList items = new GameObjectList(1, "items");

        entities.Add(items);

        GameObjectList enemies = new GameObjectList(1, "enemies");

        entities.Add(enemies);

        Camera camera = new Camera("player", 0, "camera");

        RootList.Add(camera);

        GameMouse mouse = new GameMouse();

        RootList.Add(mouse);

        LoadOverlays();

        LoadFile(path);
    }
예제 #6
0
파일: Scrollbar.cs 프로젝트: Oyyou/Flounchy
        public void Update(GameTime gameTime)
        {
            _previousScrollValue = _currentScrollValue;
            _currentScrollValue  = GameMouse.ScrollWheelValue;

            if (GameMouse.Intersects(_innerRectangle) && GameMouse.IsLeftPressed)
            {
                _isSelected = true;
            }

            if (GameMouse.IsLeftReleased)
            {
                _isSelected = false;
            }

            if (_isSelected)
            {
                _innerY = GameMouse.Y - (_innerRectangle.Height / 2);
            }

            if (_previousScrollValue != _currentScrollValue && GameMouse.Intersects(ScrollArea))
            {
                _innerY += (_previousScrollValue - _currentScrollValue) / 10;
            }

            _innerY = MathHelper.Clamp(_innerY, (int)Position.Y + _padding, ((int)Position.Y + _outer.Height - _padding) - _innerRectangle.Height);
        }
예제 #7
0
 //select entity
 private void EntitySelection(InputHelper inputHelper)
 {
     if (inputHelper.KeyPressed(Keys.Z))
     {
         GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
         selected = mouse.SelectEntity();
     }
 }
예제 #8
0
파일: Game1.cs 프로젝트: Oyyou/Flounchy
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            GameMouse.Update(gameTime);
            GameKeyboard.Update(gameTime);

            _homeStateGUI.Update(gameTime);

            base.Update(gameTime);
        }
예제 #9
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            GameMouse.Update();
            GameKeyboard.Update();

            _battleGUI.Update(gameTime, new System.Collections.Generic.List <Lib.Models.UnitModel>());

            base.Update(gameTime);
        }
예제 #10
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            GameMouse.Update();
            GameKeyboard.Update();

            _state.Update(gameTime);

            base.Update(gameTime);
        }
예제 #11
0
        protected override void LoadContent()
        {
            base.LoadContent();

            Options.Load();
            AssetManager.LoadAssets(Content);
            MusicManager.LoadAssets(Content);
            SFX.LoadContent(Content);
            GameMouse.LoadContent();
            GameMouse.Initialize();
        }
예제 #12
0
        public override void Update(GameTime gameTime)
        {
            PreviousMouseState = CurrentMouseState;
            CurrentMouseState  = GameMouse.GetState();

            if (!Enabled)
            {
                return;
            }
            UpdateCamera();
            FireMouseEvents();
        }
예제 #13
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            GameKeyboard.Update(gameTime);
            GameMouse.Update(gameTime);

            if (GameKeyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.G))
            {
                Settings.ShowCollidingBoxes = !Settings.ShowCollidingBoxes;
            }
        }
예제 #14
0
        public void DrawScreenUI()
        {
            foreach (BaseScreen screen in Screens)
            {
                if (screen.Visible)
                {
                    screen.DrawScreenUI();
                }
            }

            GameMouse.Draw(SpriteBatch);
        }
예제 #15
0
        public void HandleInput()
        {
            GameMouse.HandleInput();

            foreach (BaseScreen screen in Screens)
            {
                // Update before handling input - otherwise if we select something the WhileSelected method will be called straightaway, which is usually undesired
                if (screen.Active)
                {
                    screen.HandleInput();
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            IsMouseVisible = true;

            Random       = new Random();
            GameMouse    = new GameMouse();
            GameKeyboard = new GameKeyboard();

            ScreenWidth  = _graphics.PreferredBackBufferWidth;
            ScreenHeight = _graphics.PreferredBackBufferHeight;

            base.Initialize();
        }
예제 #17
0
 public override void HandleInput(InputHelper inputHelper)
 {
     //give information to the mouse
     base.HandleInput(inputHelper);
     if (pressed)
     {
         GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
         mouse.Asset       = asset;
         mouse.TileType    = tiletype;
         mouse.TextureType = texturetype;
         mouse.TileObject  = tileobject;
         mouse.Tile        = true;
     }
 }
예제 #18
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            _showBorder = false;

            if (GameMouse.Intersects(this.Rectangle))
            {
                _showBorder = true;

                if (GameMouse.IsLeftClicked)
                {
                }
            }
        }
예제 #19
0
        public override void Update(GameTime gameTime)
        {
            var mouseState = GameMouse.GetState();

            if (mouseState.LeftButton == ButtonState.Released && _previousMouseState.LeftButton == ButtonState.Pressed)
            {
                if (!(CurrentlySelectedNode != null && CurrentlySelectedNode.IsMouseDown))
                {
                    // Create a new node, and also set it to be the newest created node
                    if (CurrentlySelectedNode != null)
                    {
                        CurrentlySelectedNode.SetColorState(ColorState.None);
                    }
                    CurrentlySelectedNode = CreateNode((int)World.MouseInWorld.X, (int)World.MouseInWorld.Y);
                    CurrentlySelectedNode.SetColorState(ColorState.DarkDark);
                }
            }
            _previousMouseState = mouseState;
        }
예제 #20
0
 public override void HandleInput(InputHelper inputHelper)
 {
     base.HandleInput(inputHelper);
     if (pressed)
     {
         GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
         mouse.Asset           = asset;
         mouse.EntityBoundingy = boundingy;
         mouse.EntityType      = entitytype;
         mouse.Item            = true;
         if (entitytype == EntityType.Enemy)
         {
             mouse.EnemyType = enemytype;
         }
         else if (entitytype == EntityType.AnimatedItem || entitytype == EntityType.SpriteItem)
         {
             mouse.ItemType = itemtype;
         }
     }
 }
예제 #21
0
        public ScreenManager(Game game, GraphicsDeviceManager graphicsDeviceManager)
            : base(game)
        {
            Screens         = new List <BaseScreen>();
            ScreensToAdd    = new List <BaseScreen>();
            ScreensToRemove = new List <BaseScreen>();

            GameRef = game;
            Content = GameRef.Content;
            GraphicsDeviceManager = graphicsDeviceManager;
            Viewport = GameRef.GraphicsDevice.Viewport;

            Camera    = new Camera();
            Input     = new InputHandler(game);
            GameMouse = new GameMouse();
            SFX       = new SFXManager();

            GameRef.Components.Add(this);
            GameRef.Components.Add(Input);
        }
예제 #22
0
        public void Update(GameTime gameTime)
        {
            if (GameMouse.Intersects(ClickRectangle, true))
            {
                GameMouse.AddObject(this);
            }
            else
            {
                GameMouse.ClickableObjects.Remove(this);
            }

            foreach (var component in Components)
            {
                component.Update(gameTime);
            }

            foreach (var entity in Entities)
            {
                entity.Update(gameTime);
            }
        }
예제 #23
0
        public override List <Actor> GetTargets(IEnumerable <Actor> enemies)
        {
            var targets = new List <Actor>();

            var enemy = enemies.Where(c => GameMouse.Intersects(c.Rectangle)).FirstOrDefault();

            if (enemy != null)
            {
                switch (_ability.TargetType)
                {
                case AbilityModel.TargetTypes.Single:

                    enemy.ShowBorder = true;

                    targets.Add(enemy);

                    break;

                case AbilityModel.TargetTypes.All:

                    foreach (var target in enemies)
                    {
                        target.ShowBorder = true;
                        targets.Add(target);
                    }

                    break;

                default:
                    break;
                }

                if (GameMouse.IsLeftClicked)
                {
                    ActionResult.State = Engine.ActionStates.Running;
                }
            }

            return(targets);
        }
예제 #24
0
파일: Enemy.cs 프로젝트: nasr250/Valkan
 private void CheckDie()
 {
     if (health <= 0)
     {
         die = true;
         if (die_anim)
         {
             SwitchAnimation("die", "D");
             velocity = Vector2.Zero;
             GameEnvironment.AssetManager.PlaySound(die_sound);
         }
         else
         {
             RemoveSelf();
         }
         if (selected)
         {
             GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
             mouse.RemoveSelectedEntity();
         }
         (GameWorld as Level).EnemyCount--;
     }
 }
예제 #25
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            GameMouse.Update(gameTime);
            GameKeyboard.Update(gameTime);

            switch (_currentState)
            {
            case RoamingState roamingState:

                //if (roamingState.EnterBattle)
                //{
                //  roamingState.EnterBattle = false;

                //  _transition.Start();
                //}

                //if (_transition.State == Transition.States.Middle)
                //{
                //  _currentState = new BattleState(_gameModel, _players);
                //  _currentState.LoadContent();
                //}

                break;

            //case BattleState battleState:

            //  if (battleState.BattleFinished)
            //  {
            //    if (!(_transition is FourCornersTransition))
            //      _transition = new FourCornersTransition(_gameModel);
            //    _transition.Start();
            //  }

            //  if (_transition.State == Transition.States.Middle)
            //  {
            //    _currentState = new AfterBattleState(_gameModel, _players);
            //    _currentState.LoadContent();
            //  }

            //  break;

            //case AfterBattleState afterBattleState:

            //  if (afterBattleState.Continue)
            //  {
            //    _transition.Start();
            //  }

            //  if (_transition.State == Transition.States.Middle)
            //  {
            //    _currentState = new RoamingState(_gameModel, _players);
            //    _currentState.LoadContent();
            //  }

            //  break;

            case OpeningState openingState:

                if (openingState.State == OpeningState.States.Fade)
                {
                    _transition.Start();
                }

                if (_transition.State == Transition.States.Middle)
                {
                    _currentState = new BattleState(_gameModel, _players, new List <string>()
                    {
                        "Glenda: Any reason why you're completely nude, and surrounded by vampire snakes?",
                        "Nude man: A really fun night I guess..?",
                        "Glenda: Uugh. Just kill them!",
                    });
                    _currentState.LoadContent();
                }

                break;

            default:
                //throw new Exception("Unexpected state: " + _currentState.ToString());
                break;
            }

            _transition.Update(gameTime);
            _currentState.Update(gameTime);

            base.Update(gameTime);
        }
예제 #26
0
 private void Awake()
 {
     ref_gameMouse = this;
 }
예제 #27
0
    public override void HandleInput(InputHelper inputHelper)
    {
        OverlayManager overlay = GameWorld.GetObject("overlay") as OverlayManager;

        if (!(overlay.CurrentOverlay is Hud))
        {
            velocity = Vector2.Zero;
            wait     = true;
            return;
        }


        Vector2 direction = Vector2.Zero;

        if (inputHelper.IsKeyDown(Keys.A))
        {
            direction.X = -2;
        }
        else if (inputHelper.IsKeyDown(Keys.D))
        {
            direction.X = 2;
        }

        if (inputHelper.IsKeyDown(Keys.W))
        {
            direction.Y = -1;
        }
        else if (inputHelper.IsKeyDown(Keys.S))
        {
            direction.Y = 1;
        }

        float totalDir = (float)Math.Sqrt(direction.X * direction.X + direction.Y * direction.Y);

        if (totalDir != 0)
        {
            velocity = new Vector2(speed * (direction.X / totalDir), speed * (direction.Y / totalDir));

            if (selected)
            {
                Selected icon           = GameWorld.GetObject("selected") as Selected;
                Vector2  difirence      = icon.Position - position;
                float    totaldifirence = (float)Math.Sqrt(difirence.X * difirence.X + difirence.Y * difirence.Y);
                if (totaldifirence <= 10 && velocity.Y < 0)
                {
                    velocity.Y = 0;
                }
                velocity = new Vector2(-velocity.X * difirence.Y / totaldifirence - velocity.Y * difirence.X / totaldifirence, velocity.X * difirence.X / totaldifirence - velocity.Y * difirence.Y / totaldifirence);
            }
        }
        else
        {
            velocity = Vector2.Zero;
        }

        if (inputHelper.MouseLeftButtonPressed() && !wait)
        {
            GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse;
            if (selected)
            {
                Selected icon = GameWorld.GetObject("selected") as Selected;
                icon.Position = mouse.MousePos;
            }
            else
            {
                Selected icon = new Selected(1, "selected");
                icon.Position = mouse.MousePos;
                Level level = GameWorld as Level;
                level.RootList.Add(icon);
                selected = true;
            }
        }

        if (inputHelper.MouseRightButtonPressed())
        {
            if (selected)
            {
                Selected icon  = GameWorld.GetObject("selected") as Selected;
                Level    level = GameWorld as Level;
                level.RootList.Remove(icon.Id);
                selected = false;
            }
        }
        wait = false;

        //test
        if (inputHelper.ScrolDown())
        {
            Stamina--;
        }
        else if (inputHelper.ScrolUp())
        {
            Stamina++;
        }

        if (inputHelper.ScrolPressed())
        {
            MaxStamina = 1;
        }
    }