예제 #1
0
 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;
         }
     }
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
        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
                    }
                }
            }
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
파일: FsmEditor.cs 프로젝트: Alan-Baylis/11
		private void OnPlayModeStateChanged(){
			if (ActiveGameObject != null) {
				ICodeBehaviour behaviour=ActiveGameObject.GetComponent<ICodeBehaviour>();
				if(behaviour != null){
					SelectStateMachine(behaviour.stateMachine);
				}
			}	
		}
예제 #6
0
파일: Unit.cs 프로젝트: rdgoetz/LessThanOk
        private void init()
        {
            velocity      = new Vector2();
            target        = null;
            activeCommand = null;
            aggressive    = false;
            pursue        = false;

            engine = (Engine)((UnitType)Type).Engine.create();
        }
예제 #7
0
        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;
        }
예제 #8
0
        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;
            }
        }
예제 #9
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;
        }
예제 #10
0
        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;
            }
        }
예제 #11
0
파일: Unit.cs 프로젝트: rdgoetz/LessThanOk
 public void setTarget(ActiveGameObject targ)
 {
     target     = targ;
     aggressive = true;
 }
예제 #12
0
파일: Unit.cs 프로젝트: rdgoetz/LessThanOk
 public void idle()
 {
     target = null;
     state  = UnitState.IDLE;
 }
예제 #13
0
 public void AddEnemy(ActiveGameObject item)
 {
     _enemyList.Add(item);
 }
예제 #14
0
 public void AddFriendly(ActiveGameObject item)
 {
     _friendlyList.Add(item);
 }
예제 #15
0
 public Strategy()
 {
     Owner = null;
 }
예제 #16
0
        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;
        }
예제 #17
0
 public VirusAssimilateStrategy(ActiveGameObject target)
 {
     Target = target;
 }
예제 #18
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;
        }
예제 #19
0
 public VirusAssimilateStrategy(ActiveGameObject target)
 {
     Target = target;
 }