示例#1
0
        public virtual MoveModeType HitTest(Point Location)
        {
            Rectangle    rectangle    = Rectangle.Inflate(this.Bounds, 3, 3);
            MoveModeType moveModeType = MoveModeType.None;

            if (rectangle.Contains(Location))
            {
                moveModeType = MoveModeType.Move;
            }
            return(moveModeType);
        }
示例#2
0
        public override MoveModeType HitTest(Point Location)
        {
            Rectangle    rectangle1   = Rectangle.Inflate(this.Bounds, 4, 4);
            MoveModeType moveModeType = MoveModeType.None;

            if (rectangle1.Contains(Location))
            {
                moveModeType = MoveModeType.Move;
            }
            if (this.mSelected)
            {
                Rectangle rectangle2 = new Rectangle(rectangle1.X - 2, rectangle1.Y - 2, 5, 5);
                Rectangle rectangle3 = new Rectangle((int)Math.Round((double)rectangle1.X + (double)rectangle1.Width / 2.0 - 2.0), rectangle1.Y - 2, 5, 5);
                Rectangle rectangle4 = new Rectangle(rectangle1.X + rectangle1.Width - 2, rectangle1.Y - 2, 5, 5);
                Rectangle rectangle5 = new Rectangle(rectangle1.X + rectangle1.Width - 2, (int)Math.Round((double)rectangle1.Y + (double)rectangle1.Height / 2.0 - 2.0), 5, 5);
                Rectangle rectangle6 = new Rectangle(rectangle1.X + rectangle1.Width - 2, rectangle1.Y + rectangle1.Height - 2, 5, 5);
                Rectangle rectangle7 = new Rectangle((int)Math.Round((double)rectangle1.X + (double)rectangle1.Width / 2.0 - 2.0), rectangle1.Y + rectangle1.Height - 2, 5, 5);
                Rectangle rectangle8 = new Rectangle(rectangle1.X - 2, rectangle1.Y + rectangle1.Height - 2, 5, 5);
                Rectangle rectangle9 = new Rectangle(rectangle1.X - 2, (int)Math.Round((double)rectangle1.Y + (double)rectangle1.Height / 2.0 - 2.0), 5, 5);
                if (rectangle6.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeBottomRight;
                }
                if (rectangle2.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeTopLeft;
                }
                if (rectangle4.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeTopRight;
                }
                if (rectangle8.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeBottomLeft;
                }
                if (rectangle9.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeLeft;
                }
                if (rectangle3.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeTop;
                }
                if (rectangle5.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeRight;
                }
                if (rectangle7.Contains(Location))
                {
                    moveModeType = MoveModeType.ResizeBottom;
                }
            }
            return(moveModeType);
        }
示例#3
0
文件: AstarAI.cs 项目: mdeegler/xeno
    public void FixedUpdate()
    {
        bool isAlienTurn = TurnManager.Instance.currentTurn == TurnManager.TurnTypes.ALIEN? true : false;

        if (path == null) {
            //We have no path to move after yet
            return;
        }

        // don't move aliens if its not their turn to move
        if(isAlienTurn && (gameObject.GetComponent<AlienData>().unitStatus != AlienData.UnitStatus.MOVING))
            return;

        if(IsDoneMoving(false))
            return;

        // should we jump to the next waypoint?
        Vector3 currentWPVector = path.vectorPath[currentWaypoint];

        //Direction to the next waypoint

        //Debug.Log ("Current Waypoint: "+currentWPVector);
        //	Debug.Log ("Current Position: "+transform.position);
        Vector3 dir = (currentWPVector-transform.position).normalized;

        //Debug.Log ("moving: "+dir);

        // rotate //
        dir.y = 0;
        Quaternion rotation = Quaternion.LookRotation(dir);
        float str = Mathf.Min (rotationSpeed * Time.deltaTime, 1);
        transform.rotation = Quaternion.Lerp(transform.rotation, rotation, str);

        // Check direction angle. If greater than 60° then first turn without moving, otherwise full throttle ahead.
        var angle = Vector3.Angle(dir, transform.forward);
        if (angle > 60.0 && !(ReadyForNextWaypoint(currentWPVector))) {
            moveMode = MoveModeType.STOP;
            //Debug.Log("stopangle="+angle);
        } else {
            moveMode = MoveModeType.FORWARD;
        }

        // move //
        dir *= speed * Time.fixedDeltaTime;
        int moveforward=1;
        if(moveMode == MoveModeType.STOP)
            moveforward = 0;
        controller.SimpleMove (dir * moveforward);
        //transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
        //Check if we are close enough to the next waypoint
        //If we are, proceed to follow the next waypoint

        if(ReadyForNextWaypoint(currentWPVector)) {
            currentWaypoint++;
            if(currentWaypoint >= path.vectorPath.Length)
                return;

            currentWPVector = path.vectorPath[currentWaypoint];
            if(IsPathBlocked(currentWPVector)) {
                Debug.Log("Marine Blocking Me! Kill It!");
                IsDoneMoving(true);
            }
        }
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        if(moveToDestination == true){

            //Orientacion del Tanque
            //Sacamos el angulo entre dos puntos
            Quaternion rotationDestino = Quaternion.LookRotation(posicionDestino - this.transform.position);
                                    //Interpolacion para angulos (anguloOrigen,anguloDestino,Tiempo)
            this.transform.rotation = Quaternion.Lerp(this.transform.rotation, rotationDestino, fuerzaRotacionTanque * Time.deltaTime);

            //Arreglo para que el tanque no gire cuando esté cerca del destino
            Vector3 destinoDir = posicionDestino - this.transform.position;
            Vector3 forwardTanque = this.transform.forward;

            float angleEuler = Vector3.Angle(destinoDir,forwardTanque);

            if(angleEuler > 60.0f){
                moveMode = MoveModeType.STOP;
            }
            else{
                moveMode = MoveModeType.FORWARD;
            }

            //Controlamos distancia al destino
            distanciaADestino = Vector3.Distance(posicionDestino , this.transform.position);

            if(distanciaADestino < minDistanciaDestino){
                moveMode = MoveModeType.STOP;
            }
        }

        //Desplazamiento,orientación y ataque al  Enemigo
        //public GameObject enemyTarget;
        //private float distanceEnemyTarget;

        if(enemyTarget != null){

            //Orientacion de Cabeza , YAW -> rotar sobre eje Y
            Vector3 targetVector = enemyTarget.transform.position - cabeza.transform.position; //Orientacion respecto al enemigo Local
            Vector3 localCabezaOrientation = cabeza.transform.InverseTransformDirection(targetVector); //Orientacion Cabeza Local
            float yawCabeza = Mathf.Rad2Deg *  Mathf.Atan2 (localCabezaOrientation.x , localCabezaOrientation.z);//la cantidad de rotacion
            float deltaYaw = Mathf.Clamp((yawCabeza / 10) * fuerzaRotacionCabeza, -45.0f , 45.0f) * Time.deltaTime; //tiempo de rotacion
            cabeza.transform.Rotate(Vector3.up,deltaYaw,Space.Self); //aplicamos la rotacion

            //Orientacion del Cannon, PITCH, eje X
            targetVector = enemyTarget.transform.position - cannon.transform.position;
            Vector3 localCannonOrientation = cannon.transform.InverseTransformDirection(targetVector);
            float pitchCannon = Vector3.Angle(Vector3.up,localCannonOrientation) - 90.0f;
            float deltaPitch = Mathf.Clamp((pitchCannon / 10) * fuerzaRotacionCannon, -45.0f , 45.0f) * Time.deltaTime;
            cannon.transform.Rotate(Vector3.right,deltaPitch,Space.Self);

            //Limitacion de Cannon en PITCH

        //			Vector3 pitchBounds = cannon.transform.localEulerAngles;
        //
        //			if(pitchBounds.x > minRotationCannon && pitchBounds.x < maxRotationCannon){
        //
        //			}

            //Calculamos la distancia al enemigo
            distanceEnemyTarget = Vector3.Distance(this.transform.position , enemyTarget.transform.position);

            if(distanceEnemyTarget < 70){
                fireMainGun();
                moveToDestination = false;
                moveMode = MoveModeType.STOP;
            }
            else{
                posicionDestino = enemyTarget.transform.position;
                moveToDestination = true;
            }

        }
        else{

        }
    }
示例#5
0
    void nuevoDestino(Vector3 destino)
    {
        moveToDestination = true;
        posicionDestino = destino;

        moveMode = MoveModeType.FORWARD; //pasamos a estado Avance
    }