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(); } }
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; } } }
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); } }
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); }
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); }
//select entity private void EntitySelection(InputHelper inputHelper) { if (inputHelper.KeyPressed(Keys.Z)) { GameMouse mouse = GameWorld.GetObject("mouse") as GameMouse; selected = mouse.SelectEntity(); } }
/// <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); }
/// <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); }
/// <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); }
protected override void LoadContent() { base.LoadContent(); Options.Load(); AssetManager.LoadAssets(Content); MusicManager.LoadAssets(Content); SFX.LoadContent(Content); GameMouse.LoadContent(); GameMouse.Initialize(); }
public override void Update(GameTime gameTime) { PreviousMouseState = CurrentMouseState; CurrentMouseState = GameMouse.GetState(); if (!Enabled) { return; } UpdateCamera(); FireMouseEvents(); }
/// <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; } }
public void DrawScreenUI() { foreach (BaseScreen screen in Screens) { if (screen.Visible) { screen.DrawScreenUI(); } } GameMouse.Draw(SpriteBatch); }
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(); } } }
/// <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(); }
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; } }
public override void Update(GameTime gameTime) { base.Update(gameTime); _showBorder = false; if (GameMouse.Intersects(this.Rectangle)) { _showBorder = true; if (GameMouse.IsLeftClicked) { } } }
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; }
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; } } }
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); }
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); } }
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); }
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--; } }
/// <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); }
private void Awake() { ref_gameMouse = this; }
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; } }