private void Animation(ComponentPosition position, ComponentDirection direction, ComponentAnimation animation)
        {
            float currentTime = animation.CurrentTime;
            float period      = animation.Period;
            float dt          = SceneManager.dt;
            float timeOver    = 0.0f;

            currentTime += dt;

            if (currentTime > period)
            {
                timeOver = (currentTime - period) % period;
                animation.CurrentTime = timeOver;
            }
            else
            {
                animation.CurrentTime = currentTime;
            }

            AnimationType type = animation.Type;

            if (type == AnimationType.ROTATION_Y)
            {
                Matrix3 rot = Matrix3.CreateRotationY(DegreeToRadians(360 / period) * SceneManager.dt);
                direction.Direction = rot * direction.Direction;
            }
            else if (type == AnimationType.OSCILLATION_Y)
            {
                float   angle     = (currentTime / period) * 360;
                float   height    = (float)Math.Cos(angle / 180 * Math.PI);
                Vector3 positionV = position.Position;
                positionV.Y       = position.StartPosition.Y + animation.MaxHeight * (-(height - 1) / 2f);
                position.Position = positionV;
            }
        }
        private void GoToTarget(ComponentDirection direction, ComponentVelocity velocity, ComponentPosition position, Vector3 target, float fullSpeed, Vector3 playerPosition)
        {
            Vector3 directionBetween = position.Position - target;
            Vector3 directionGhost   = direction.Direction;

            directionBetween.Y = 0.0f;
            directionGhost.Y   = 0.0f;

            if (directionBetween.Length < 0.1)
            {
                position.Position = target;
                return;
            }
            Vector3 ghostToPlayer = position.Position - playerPosition;

            ghostToPlayer.Y = 0.0f;
            float ghostDistance = (float)Math.Sqrt(Math.Pow(ghostToPlayer.X, 2) + Math.Pow(ghostToPlayer.Z, 2));

            directionBetween = Vector3.Normalize(directionBetween);
            directionGhost   = Vector3.Normalize(directionGhost);
            double angleBetween = Math.Atan2(directionBetween.Z, directionBetween.X);
            double angleGhost   = Math.Atan2(directionGhost.Z, directionGhost.X);
            double angle        = RadiansToDegree(angleBetween) - RadiansToDegree(angleGhost);

            if (angle > 180)
            {
                angle = 180 - angle;
            }
            else if (angle < -180)
            {
                angle = -180 - angle;
            }

            if (angle > 10)
            {
                direction.DirectionChange = 1 * direction.MaxChange;
            }
            else if (angle < -10)
            {
                direction.DirectionChange = -1 * direction.MaxChange;
            }
            else
            {
                direction.Direction = directionBetween;
                float speed = 1f;
                if ((position.Position - target).Length < 1)
                {
                    speed = directionBetween.Length * 0.5f;
                }

                if (ghostDistance < fullSpeed)
                {
                    velocity.Velocity = -1f * speed * velocity.MaxVelocity;
                }
                else
                {
                    velocity.Velocity = -0.5f * speed * velocity.MaxVelocity;
                }
            }
        }
Example #3
0
        private void Input(ComponentVelocity velocity, ComponentDirection direction)
        {
            if (input.GetKeyState(Keys.DOWN) > 0)
            {
                velocity.Velocity = -(input.GetKeyState(Keys.DOWN) * velocity.MaxVelocity);
            }
            else if (input.GetKeyState(Keys.UP) > 0)
            {
                velocity.Velocity = input.GetKeyState(Keys.UP) * velocity.MaxVelocity;
            }
            else
            {
                velocity.Velocity = 0;
            }

            if (input.GetKeyState(Keys.LEFT) > 0)
            {
                direction.DirectionChange = -(input.GetKeyState(Keys.LEFT) * direction.MaxChange);
            }
            else if (input.GetKeyState(Keys.RIGHT) > 0)
            {
                direction.DirectionChange = input.GetKeyState(Keys.RIGHT) * direction.MaxChange;
            }
            else
            {
                direction.DirectionChange = 0;
            }
        }
        public void Motion(ComponentPosition position, float velocity, ComponentDirection direction)
        {
            Matrix3 rot = Matrix3.CreateRotationY(DegreeToRadians(direction.DirectionChange) * SceneManager.dt);

            direction.Direction = rot * direction.Direction;

            position.Position += direction.Direction * velocity * SceneManager.dt;
        }
        //----------------------------------------------------------

        //Constructor
        public GridSpot(GameObject obj, IVector3 pos)
        {
            _direction         = ComponentDirection.LEFT;
            _position          = pos;
            _componentAttached = null;
            _obj                = obj;
            _type               = SpotType.EMPTY;
            _siblings           = new List <GridSpot>();
            _eldest             = pos;
            _secondaryDirection = ComponentDirection.FRONT;
        }
Example #6
0
        public Voltmeter(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            ImageUp    = Resources.VoltmeterV;
            ImageRight = Resources.Voltmeter;
            ImageDown  = Resources.VoltmeterV;
            ImageLeft  = Resources.Voltmeter;

            ComponentType = ComponentType.Voltmeter;
            Direction     = direction;
        }
Example #7
0
        public Wire(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            ImageUp    = Resources.Wire_Vertical;
            ImageRight = Resources.Wire_Horizontal;
            ImageDown  = Resources.Wire_Vertical;
            ImageLeft  = Resources.Wire_Horizontal;

            ComponentType = ComponentType.WireStraight;
            Direction     = direction;
        }
 public void SetComponentDirection(ComponentDirection dir, int X, int Y, int Z)
 {
     if (isOnGrid(X, Y, Z))
     {
         _grid [X, Y, Z].Direction = dir;
         //Debug.Log ("Direction changed to " + dir + " at " + new IVector3 (X, Y, Z));
     }
     else
     {
         Debug.LogError("OMG Off the grid error");
     }
 }
Example #9
0
        public Resistor(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            ImageUp = Resources.Resistor;
            ImageUp.RotateFlip(RotateFlipType.Rotate90FlipNone);
            ImageRight = Resources.Resistor;
            ImageDown  = Resources.Resistor;
            ImageDown.RotateFlip(RotateFlipType.Rotate90FlipNone);
            ImageLeft = Resources.Resistor;

            ComponentType = ComponentType.Resistor;
            Direction     = direction;
        }
Example #10
0
        public WireFourWay(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            //Direction is where the most anti clockwise wire is facing.
            //E.g. For up right, the most anti clockwise wire is facing to the right.
            ImageUp    = Resources._4_way;
            ImageRight = Resources._4_way;
            ImageDown  = Resources._4_way;
            ImageLeft  = Resources._4_way;

            ComponentType = ComponentType.WireFourWay;
            Direction     = direction;
        }
Example #11
0
        public Cell(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            ImageUp = Resources.Power_Supply;
            ImageUp.RotateFlip(RotateFlipType.Rotate90FlipY);
            ImageRight = Resources.Power_Supply;
            ImageDown  = Resources.Power_Supply;
            ImageDown.RotateFlip(RotateFlipType.Rotate90FlipNone);
            ImageLeft = Resources.Power_Supply;
            ImageLeft.RotateFlip(RotateFlipType.RotateNoneFlipX);

            ComponentType = ComponentType.Cell;
            Direction     = direction;
        }
Example #12
0
        public WireTwoWayAlt(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            //Direction is where the most clockwise wire is facing.
            //E.g. For up right, the most clockwise wire is facing to the right.

            ImageRight = Resources._2_Way_Up_Right;
            ImageDown  = Resources._2_Way_Right_Down;
            ImageLeft  = Resources._2_Way_Right_Up;
            ImageUp    = Resources._2_Way_Down_Right;

            ComponentType = ComponentType.WireTwoAlternate;
            Direction     = direction;
        }
Example #13
0
        public BaseComponent(ComponentDirection direction, double resistance, double voltage, double current)
        {
            if (IDs == null)
            {
                IDs = new List <int>();
            }

            //An ID is created so I can find a created picturebox by comparing the ID of a Component object and a PictureBox on screen.
            ID = CreateId();

            Resistance = resistance;
            Current    = voltage;
            Voltage    = current;
        }
Example #14
0
        public WireThreeWay(ComponentDirection direction, double resistance, double voltage, double current)
            : base(direction, resistance, voltage, current)
        {
            //Direction is where the most anti clockwise wire is facing.
            //E.g. For up right, the most anti clockwise wire is facing to the right.
            ImageUp = Resources._3_Way_Up;
            ImageUp.RotateFlip(RotateFlipType.Rotate90FlipNone);
            ImageRight = Resources._3_Way_Up;
            ImageDown  = Resources._3_Way_Down;
            ImageDown.RotateFlip(RotateFlipType.Rotate90FlipNone);
            ImageLeft = Resources._3_Way_Down;


            ComponentType = ComponentType.WireThreeWay;
            Direction     = direction;
        }
 public void SetSiblingsForComponent(int X, int Y, int Z, List <GridSpot> sib, ComponentDirection dir1, ComponentDirection dir2)
 {
     _grid [X, Y, Z].Siblings.Clear();
     //Debug.Log (sib.Count);
     SetComponentDirection(dir1, sib [0].Position.x, sib [0].Position.y, sib [0].Position.z);
     SetComponentDirection(dir2, sib [1].Position.x, sib [1].Position.y, sib [1].Position.z);
     SetSpotToType(SpotType.OR_LEFT, sib [0].Position.x, sib [0].Position.y, sib [0].Position.z);
     SetSpotToType(SpotType.OR_RIGHT, sib [1].Position.x, sib [1].Position.y, sib [1].Position.z);
     AttachComponent(sib [0].Position.x, sib [0].Position.y, sib [0].Position.z);
     AttachComponent(sib [1].Position.x, sib [1].Position.y, sib [1].Position.z);
     foreach (GridSpot s in sib)
     {
         if (isOnGrid(s.Position.x, s.Position.y, s.Position.z))
         {
             _grid [X, Y, Z].Siblings.Add(s);
         }
         //Debug.Log (_grid [X, Y, Z].Siblings.Count);
     }
 }
Example #16
0
 public void Motion(ComponentPosition pPos, ComponentVelocity pVel, ComponentDirection pDir)
 {
     pPos.Position += pDir.Direction * (pVel.Velocity * GameScene.dt);
 }
Example #17
0
 public static TOption LocaleDirection <TOption>(this TOption option, ComponentDirection direction) where TOption : DateRangePickerOption
 {
     option.LocaleAttributes["direction"] = string.Format("'{0}'", direction.ToDisplayName());
     return(option);
 }
Example #18
0
        private void AddComponent(ComponentType componentType, int posX, int posY,
                                  ComponentDirection direction = ComponentDirection.Right, double resistance = 0, double voltage = 0,
                                  double current = 0)
        {
            //Ensures that the PictureBox that is to be created will be on a square.
            posX = RoundDownToNearest(posX, 50);
            posY = RoundDownToNearest(posY, 50);

            BaseComponent component;

            try
            {
                //Sets the component as a specific component, depending on the ComponentType the method receives.
                switch (componentType)
                {
                case ComponentType.Resistor:
                    component = new Resistor(direction, resistance, current, voltage);
                    break;

                case ComponentType.Voltmeter:
                    component = new Voltmeter(direction, resistance, current, voltage);
                    break;

                case ComponentType.Ammeter:
                    component = new Ammeter(direction, resistance, current, voltage);
                    break;

                case ComponentType.Cell:
                    component = new Cell(direction, resistance, current, voltage);
                    break;

                case ComponentType.WireStraight:
                    component = new Wire(direction, resistance, current, voltage);
                    break;

                case ComponentType.WireTwoAlternate:
                    component = new WireTwoWayAlt(direction, resistance, current, voltage);
                    break;

                case ComponentType.WireThreeWay:
                    component = new WireThreeWay(direction, resistance, current, voltage);
                    break;

                case ComponentType.WireFourWay:
                    component = new WireFourWay(direction, resistance, current, voltage);
                    break;

                default:
                    throw new ArgumentNullException();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            //Sets the location of component.
            component.Location = Location;

            var pictureBox = new PictureBox
            {
                Tag = component.ID,
                //Sets the location of the PictureBox.
                Location  = new Point(posX, posY),
                BackColor = Color.Transparent,
                SizeMode  = PictureBoxSizeMode.AutoSize
            };

            //Events.
            pictureBox.MouseMove  += p_MouseMove;
            pictureBox.MouseClick += P_MouseClick;
            pictureBox.MouseWheel += P_MouseWheel;
            pictureBox.MouseHover += P_MouseHover;
            pictureBox.Image       = component.CurrentImage;

            Components.Add(component);
            //Adds the component to the main panel.
            panelCircuitBoard.Controls.Add(pictureBox);
        }
        public override void OnAction()
        {
            List <IComponent> components = player.Components;

            IComponent positionComponent = components.Find(delegate(IComponent component)
            {
                return(component.ComponentType == ComponentTypes.COMPONENT_POSITION);
            });

            Vector3  positionPlayer = ((ComponentPosition)positionComponent).Position;
            Location playerLocation = new Location();

            playerLocation.mapXPosition = (int)Math.Abs((map.GetStartX() - 0.5f) - positionPlayer.X);
            playerLocation.mapYPosition = (int)Math.Abs((map.GetStartY() - 0.5f) - positionPlayer.Z);

            List <IntelligenceSetUp> setUps = new List <IntelligenceSetUp>();

            foreach (Entity entity in entities)
            {
                components = entity.Components;

                positionComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_POSITION);
                });

                IComponent directionComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_DIRECTION);
                });

                IComponent velocityComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_VELOCITY);
                });

                ComponentVelocity velocity = (ComponentVelocity)velocityComponent;

                ComponentDirection direction = (ComponentDirection)directionComponent;
                direction.DirectionChange = 0;
                velocity.Velocity         = 0;


                if (!hasMovement)
                {
                    continue;
                }

                if (playerLocation.mapXPosition < 0 || playerLocation.mapXPosition > map.GetWidth() - 1 || playerLocation.mapYPosition < 0 || playerLocation.mapYPosition > map.GetWidth() - 1)
                {
                    //Don't do anything the player is outside the map
                    continue;
                }

                IComponent artificalComponent = components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_ARTIFICAL);
                });

                ComponentArtificalInput componentArtifical = (ComponentArtificalInput)artificalComponent;

                Vector3 positionGhost = ((ComponentPosition)positionComponent).Position;

                Location ghostPosition = new Location();

                ghostPosition.mapXPosition = (int)Math.Abs((map.GetStartX() - 0.5f) - positionGhost.X);
                ghostPosition.mapYPosition = (int)Math.Abs((map.GetStartY() - 0.5f) - positionGhost.Z);

                if (ghostPosition.mapXPosition < 0 || ghostPosition.mapXPosition > map.GetWidth() || ghostPosition.mapYPosition < 0 || ghostPosition.mapYPosition > map.GetWidth())
                {
                    //Don't do anything the player is outside the map
                    map.KillGhost(entity);
                    continue;
                }

                IntelligenceSetUp setUp = new IntelligenceSetUp();
                setUp.velocity           = velocity;
                setUp.direction          = direction;
                setUp.ghostLocation      = ghostPosition;
                setUp.algorithm          = componentArtifical.GetAlgorithm();
                setUp.preferredDirection = componentArtifical.GetPreferredDirection();
                setUp.position           = (ComponentPosition)positionComponent;
                setUp.fullSpeed          = componentArtifical.FullSpeed();

                setUps.Add(setUp);
            }

            for (int i = 0; i < setUps.Count; i++)
            {
                Vector2 ghostMapLocation = new Vector2(setUps[i].position.Position.X, setUps[i].position.Position.Z);

                Vector3 target = setUps[i].algorithm.BuildPath(ghostMapLocation, setUps[i].ghostLocation, map, playerLocation, setUps[i].preferredDirection);
                GoToTarget(setUps[i].direction, setUps[i].velocity, setUps[i].position, target, setUps[i].fullSpeed, positionPlayer);
            }
        }
 private void SetDirectionOfComponent(ComponentDirection dir)
 {
     _direction = dir;
 }