private void setHover(UIElement curElement, ActiveGameObject curObject) { if (_elementHover == null) { _elementHover = curElement; } else if (curElement != null) { if (curElement.Name != _elementHover.Name) { curElement.Image.Hover = true; _elementHover.Image.Hover = false; } } if (_objectHover == null) { _objectHover = curObject; } else if (curObject != null) { if (curObject.ID != _objectHover.ID) { //curObject.Sprite.Hover = true; _elementHover.Image.Hover = false; } } }
/// <summary> /// Method for evaluating the attack command. /// </summary> /// <param name="req">Attack Command</param> /// <param name="rules">Rules for evaluating the command.</param> /// <param name="player">Player requesting the attack command.</param> /// <param name="time">Current game time.</param> /// <returns>Queue of translated commands resulting from the evaluation.</returns> private Queue <Command> evaluateAttack(Command req, RuleBook rules, Player player, TimeSpan time) { Queue <Command> retval = new Queue <Command>(); // Decorate the command to get the required functionallity. // Probably a better solution. Suggestions welcome. Command attack = new AttackDecorator(req); // Get the target of the attack. ActiveGameObject targ = (ActiveGameObject)GameObjectFactory.The.getGameObject(attack.Target); if (targ == null) { // TODO: flush the unit's queue of commands. Signifies the attack is over / target is dead. } // Unit the command is acting on. Unit unit = (Unit)GameObjectFactory.The.getGameObject(attack.Actor); // Pathfind to the target. List <Vector2> waypoints = _explorer.GetPath(unit.getPosition(), targ.getPosition(), _map); Engine engine = unit.Engine; // Time To Destination. // Note for attack commands we only used the first waypoint. float ttd = engine.timeToReach(waypoints[0]); float curt = time.Ticks; retval.Enqueue(new MoveDecorator(req.Actor, (UInt16)targ.getPosition().X, (UInt16)targ.getPosition().Y, curt + ttd, new Command())); // TODO: push an attack on as well. return(retval); }
public void update(GameTime gameTime) { MouseState curMouseState = Mouse.GetState(); KeyboardState curKeyboardState = Keyboard.GetState(); Vector2 mousePos = new Vector2(curMouseState.X, curMouseState.Y); UIElement curElement = UIManager.The.Root.getElementAt(mousePos); ActiveGameObject curObject = null; if (UIManager.The.Root is Frame_Game) { Frame_Game f = (Frame_Game)UIManager.The.Root; curObject = f.getObjectAt(mousePos); } setHover(curElement, curObject); // left click if (curMouseState.LeftButton.Equals(ButtonState.Pressed)) { leftClick = ButtonState.Pressed; } else if (leftClick.Equals(ButtonState.Pressed)) { // Left click detected leftClick = ButtonState.Released; if (curElement != null) { curElement.LeftClickEvent.click(curElement); } else if (curObject != null) { _selected = curObject; } } // right click if (curMouseState.RightButton.Equals(ButtonState.Pressed)) { rightClick = ButtonState.Pressed; } else if (rightClick.Equals(ButtonState.Pressed)) { // Right click detected rightClick = ButtonState.Released; if (curElement != null) { curElement.RightClickEvent.click(curElement); } else if (curObject != null) { if (_selected != null) { //move logic } } } }
/// <summary> /// Method for evaluating Move Commands. /// </summary> /// <param name="req">Move Command being evaluated.</param> /// <param name="rules">RuleBook for evaluating the command.</param> /// <param name="player">Player who requested the move.</param> /// <param name="time">Current game time.</param> /// <returns>Queue of translated commands resulting from the evaluation.</returns> private Queue <Command> evaluateMove(Command req, RuleBook rules, Player player, TimeSpan time) { Queue <Command> retval = new Queue <Command>(); // Decorate the command to get the required functionality. // Probably a better way to do this... Command move = new MoveDecorator(req); // Unit the command was acting on. ActiveGameObject unit = (ActiveGameObject)GameObjectFactory.The.getGameObject(move.Actor); Vector2 origin = unit.getPosition(); Vector2 dest = new Vector2((long)move.X, (long)move.Y); List <Vector2> waypoints = _explorer.GetPath(origin, dest, _map); // Check that next waypoint is valid. Depending on implimentaiton of PathFinder, this may not be nessisary. if (waypoints.Count > 0 && _map.hasUnitsInPath(origin, waypoints[0])) { Command deny = new DenyDecorator(req.Actor, time.Ticks, new Command()); retval.Enqueue(deny); // TODO: trigger request denied event. return(retval); } Engine engine = ((Unit)unit).Engine; // Build Move Commands out of waypoints. foreach (Vector2 p in waypoints) { float ttd = engine.timeToReach(dest); float curt = time.Ticks; retval.Enqueue(new MoveDecorator(req.Actor, (UInt16)p.X, (UInt16)p.Y, curt + ttd, new Command())); } return(retval); }
private void OnPlayModeStateChanged(){ if (ActiveGameObject != null) { ICodeBehaviour behaviour=ActiveGameObject.GetComponent<ICodeBehaviour>(); if(behaviour != null){ SelectStateMachine(behaviour.stateMachine); } } }
private void init() { velocity = new Vector2(); target = null; activeCommand = null; aggressive = false; pursue = false; engine = (Engine)((UnitType)Type).Engine.create(); }
private void FindTarget(World world) { Vector2 currentPosition = Owner.Position; closestTarget = Owner.PlayWindow.GoodCellList.First(); closestDistance = (currentPosition - closestTarget.Position).LengthSquared(); float boxSideStep = 2; targetFound = false; while (boxSideStep < 64 && targetFound == false) { AABB boundingBox = new AABB(ConvertUnits.ToSimUnits(currentPosition), boxSideStep, boxSideStep); world.QueryAABB(AABBCollision, ref boundingBox); boxSideStep *= 4; } _target = closestTarget; }
public override void Update(GameTime gameTime) { PlayWindow playWindow = Owner.PlayWindow; timer += gameTime.ElapsedGameTime.TotalSeconds; if (_target != null) _targetDistance = (Owner.Position - _target.Position).Length(); else _targetDistance = float.MaxValue; if (timer > 5 && _targetDistance > 2) { if (Owner.PlayWindow.GoodCellList.Count > 0) FindTarget(Owner.PlayWindow.World); else _target = null; timer = 0; } }
private bool AABBCollision(Fixture f) { Object o = f.Body.UserData; if (o == null) return true; if (o is GoodCell) { GoodCell cell = (GoodCell)o; float distance = (Owner.Position - cell.Position).LengthSquared(); if (closestDistance > distance) { closestDistance = distance; closestTarget = cell; } targetFound = true; } return true; }
public override void Update(GameTime gameTime) { PlayWindow playWindow = Owner.PlayWindow; timer += gameTime.ElapsedGameTime.TotalSeconds; if (_target != null) _targetDistance = (Owner.Position - _target.Position).Length(); else _targetDistance = float.MaxValue; if (timer > 5 && _targetDistance > 2) { if (Owner.PlayWindow.GoodCellList.Count > 0) FindTarget(Owner.PlayWindow.World); else _target = null; timer = 0; } }
public void setTarget(ActiveGameObject targ) { target = targ; aggressive = true; }
public void idle() { target = null; state = UnitState.IDLE; }
public void AddEnemy(ActiveGameObject item) { _enemyList.Add(item); }
public void AddFriendly(ActiveGameObject item) { _friendlyList.Add(item); }
public Strategy() { Owner = null; }
private void FindTarget(World world) { Vector2 currentPosition = Owner.Position; closestTarget = Owner.PlayWindow.GoodCellList.First(); closestDistance = (currentPosition - closestTarget.Position).LengthSquared(); float boxSideStep = 2; targetFound = false; while (boxSideStep < 64 && targetFound == false) { AABB boundingBox = new AABB(ConvertUnits.ToSimUnits(currentPosition), boxSideStep, boxSideStep); world.QueryAABB(AABBCollision, ref boundingBox); boxSideStep *= 4; } _target = closestTarget; }
public VirusAssimilateStrategy(ActiveGameObject target) { Target = target; }
private bool AABBCollision(Fixture f) { Object o = f.Body.UserData; if (o == null) return true; if (o is GoodCell) { GoodCell cell = (GoodCell)o; float distance = (Owner.Position - cell.Position).LengthSquared(); if (closestDistance > distance) { closestDistance = distance; closestTarget = cell; } targetFound = true; } return true; }
public VirusAssimilateStrategy(ActiveGameObject target) { Target = target; }