Esempio n. 1
0
 public Character(WorldMap worldMap, Vector2 coordinates)
 {
     mCoordinates = coordinates;
     mState = ActionState.Idle;
     mDirection = FacingDirection.Down;
     mWorldMap = worldMap;
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the new facing direction
 /// </summary>
 /// <param name="RotateDirection"></param>
 /// <param name="facingDirection"></param>
 /// <returns></returns>
 public static FacingDirection GetFacingDirection(RotateDirection RotateDirection, FacingDirection facingDirection)
 {
     if (RotateDirection == RotateDirection.Left)
     {
         if (facingDirection == FacingDirection.East)
             facingDirection = FacingDirection.North;
         else if (facingDirection == FacingDirection.North)
             facingDirection = FacingDirection.West;
         else if (facingDirection == FacingDirection.West)
             facingDirection = FacingDirection.South;
         else if (facingDirection == FacingDirection.South)
             facingDirection = FacingDirection.East;
     }
     else if (RotateDirection == RotateDirection.Right)
     {
         if (facingDirection == FacingDirection.East)
             facingDirection = FacingDirection.South;
         else if (facingDirection == FacingDirection.North)
             facingDirection = FacingDirection.East;
         else if (facingDirection == FacingDirection.West)
             facingDirection = FacingDirection.North;
         else if (facingDirection == FacingDirection.South)
             facingDirection = FacingDirection.West;
     }
     return facingDirection;
 }
Esempio n. 3
0
	// Use this for initialization
	void Start () {

        Inventory = new List<Item>();

        if (GodMode)
        {
            Weapon w = new Weapon(WeaponType.Rifle);
            Inventory.Add(w);
        }

        //set active (for now)
        activeItem = Inventory[0];

        Facing = FacingDirection.Left;
        Animation = AnimateState.Down;
        
        PlayerCamera = Camera.main;
        TargetPosition = transform.position;

        PlayerConvText = GameObject.Find("PlayerConvText");

        textures = new Texture[4];

        textures[0] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_back.png", typeof(Texture));
        textures[1] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_front.png", typeof(Texture));
        textures[2] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_left.png", typeof(Texture));
        textures[3] = (Texture)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets\\Resources\\Drawings\\Characters\\theblind_right.png", typeof(Texture));

        GetComponent<Renderer>().material.mainTexture = textures[2];
	}
Esempio n. 4
0
 void LookAt2D(Vector3 vectorToTarget, float theSpeed, FacingDirection facing)
 {
     float angle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
     angle -= (float)facing;
     Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
     transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * theSpeed);
 }
        /// <summary>
        /// Rotate the Robot to the Left
        /// </summary>
        /// <returns>bool</returns>
        public bool Left()
        {
            if (RobotStatus.IsPlacedOnTable(_x, _y,Instruction.Left))
            {

                _facingDirection = RobotStatus.GetFacingDirection(RotateDirection.Left, _facingDirection);
                return true;
            }
            else
            {
                _error = RobotStatus._error;
            }
            return false;
        }
Esempio n. 6
0
 /// <summary>
 /// Gets the new value of x
 /// </summary>
 /// <param name="facingDirection"></param>
 /// <param name="y"></param>
 /// <returns>y</returns>
 public static int GetUpdatedY(FacingDirection facingDirection, int? y)
 {
     if (facingDirection == FacingDirection.North)
     {
         return y.Value + 1;
     }
     else
     {
         if (facingDirection == FacingDirection.South)
         {
             return y.Value - 1;
         }
     }
     return y.Value;
 }
        public static void SwingWeapon(ICanSwing swingingObject, FacingDirection direction)
        {
            switch (direction)
            {
                case FacingDirection.North:
                    break;
                case FacingDirection.South:
                    break;
                case FacingDirection.East:
                    break;
                case FacingDirection.West:
                    break;

            }
        }
Esempio n. 8
0
        public AffordanceTooltipPlacement GetPlacement(FacingDirection direction)
        {
            m_LastFacingDirection = direction;

            foreach (var placement in m_Placements)
            {
                if ((placement.facingDirection & direction) != 0)
                {
                    return(placement);
                }
            }

            Debug.LogWarning(string.Format("No placement matching {0} found in {1}", direction, this), this);
            return(null);
        }
Esempio n. 9
0
 /// <summary>
 /// Gets the new value of x
 /// </summary>
 /// <param name="facingDirection"></param>
 /// <param name="x"></param>
 /// <returns>x</returns>
 public static int GetUpdatedX(FacingDirection facingDirection, int? x)
 {
     if (facingDirection == FacingDirection.East)
     {
         return x.Value + 1;
     }
     else
     {
         if (facingDirection == FacingDirection.West)
         {
             return x.Value - 1;
         }
     }
     return x.Value;
 }
Esempio n. 10
0
    private FacingDirection GetLookUpDirection(Vector3 targetPos)
    {
        FacingDirection direction         = FacingDirection.Forward;
        Vector3         directionToTarget = targetPos - transform.position;
        float           angle             = Vector3.Angle(directionToTarget, Vector3.right);

        if (angle < 90.0f)
        {
            direction = FacingDirection.Right;
        }
        else if (angle > 90.0f)
        {
            direction = FacingDirection.Left;
        }
        return(direction);
    }
Esempio n. 11
0
        private FacingDirection ChooseTunnelDirection(FacingDirection lastDirection)
        {
            int roll = RNG.Roll(0, 100);

            if (roll >= m_CorridorBend)
            {
                return(lastDirection);
            }

            roll = RNG.Roll(0, 3) * 2;
            while (roll == (int)lastDirection)
            {
                roll = RNG.Roll(0, 3) * 2;
            }
            return((FacingDirection)roll);
        }
Esempio n. 12
0
        public void ChangeFacingDirection(FacingDirection newDirection)
        {
            bool changeMade = false;

            if (facingDirection != (float)newDirection)
            {
                changeMade = true;
            }

            facingDirection = (float)newDirection;

            if (changeMade)
            {
                UpdateDirectionAnimator(facingDirection);
            }
        }
Esempio n. 13
0
    void Flip()
    {
        if (facing == FacingDirection.Right)
        {
            facing = FacingDirection.Left;
        }
        else if (facing == FacingDirection.Left)
        {
            facing = FacingDirection.Right;
        }

        var theScale = transform.localScale;

        theScale.x           = (int)facing;
        transform.localScale = theScale;
    }
Esempio n. 14
0
    public int GetFacingIndex(Vector2 direction)
    {
        float           bestDot       = Vector2.Dot(direction, facingDirections[0].direction);
        FacingDirection bestDirection = facingDirections[0];

        for (int i = 1; i < facingDirections.Length; i++)
        {
            float dot = Vector2.Dot(direction, facingDirections[i].direction);
            if (dot > bestDot)
            {
                bestDot       = dot;
                bestDirection = facingDirections[i];
            }
        }
        return(bestDirection.index);
    }
Esempio n. 15
0
        FacingDirection SetRandomFacingDirection()
        {
            int newRandomFacingDirectionInt;

            do
            {
                newRandomFacingDirectionInt = Random.Range(0, 4);
            }while(newRandomFacingDirectionInt == currentRandomFacingDirectionInt);

            currentRandomFacingDirectionInt = newRandomFacingDirectionInt;

            // Explicitly cast FacingDirection as randomFacingDirectionInt to obtain FacingDirection enum.
            FacingDirection newFacingDirection = (FacingDirection)currentRandomFacingDirectionInt;

            return(newFacingDirection);
        }
Esempio n. 16
0
        public RPGObject()
        {
            // start in random place
            size = new Size(25, 40);
            loc  = new Point(new RPGCalc().Roll(PanelAction.PANEL_WIDTH - this.Width),
                             new RPGCalc().Roll(PanelAction.PANEL_HEIGHT - this.Height));
            dir = FacingDirection.South;

            // start with random colors
            Color1 = new RPGCalc().RandomColor();
            Color2 = new RPGCalc().RandomColor();

            currentState = ActionState.Standing;
            Actions      = new ActionQueue(this);
            Effects      = new RPGEffect[RPGEffect.MAX_EFFECTS];
        }
Esempio n. 17
0
    //Función que muetra la sombra del objetivo donde va a ser atraida
    public void ShowGrabShadow(IndividualTiles _referenceTile, FacingDirection _referenceDirection)
    {
        if (currentUnitsAvailableToAttack.Count > 0)
        {
            playerWithShadowActivated = currentUnitsAvailableToAttack[0];

            currentUnitsAvailableToAttack[0].sombraHoverUnit.SetActive(true);

            List <IndividualTiles> tileUnitGrabbed = new List <IndividualTiles>();
            tileUnitGrabbed = _referenceTile.GetTilesInFrontOfTheCharacter(_referenceDirection, 1);

            Vector3 pointPosition = new Vector3(tileUnitGrabbed[0].transform.position.x, tileUnitGrabbed[0].transform.position.y + 0.5f, tileUnitGrabbed[0].transform.position.z);

            currentUnitsAvailableToAttack[0].sombraHoverUnit.transform.position = pointPosition;
        }
    }
Esempio n. 18
0
        public int GetSprite(FacingDirection direction)
        {
            switch (direction)
            {
                case FacingDirection.Up:
                    return Sheet.GidUp;
                case FacingDirection.Down:
                    return Sheet.GidDown;
                case FacingDirection.Left:
                    return Sheet.GidLeft;
                case FacingDirection.Right:
                    return Sheet.GidRight;
            }

            return TextureId;
        }
Esempio n. 19
0
 public void RotateWorldRight()
 {
     player.disableHitBox();
     //If we rotate while on an invisible platform we must move to a physical platform
     //If we don't, then we could be standing in mid air after the rotation
     if (OnInvisiblePlatform())
     {
         //MoveToClosestPlatform();
         MovePlayerDepthToClosestPlatform();
     }
     lastfacing      = facingDirection;
     facingDirection = RotateDirectionRight();
     degree         -= 90f;
     UpdateLevelData(false);
     PlayerController.UpdateToFacingDirection(facingDirection, degree);
 }
Esempio n. 20
0
    public static FacingDirection Opposite(FacingDirection direction)
    {
        switch (direction)
        {
        case FacingDirection.Up:
            return(FacingDirection.Down);

        case FacingDirection.Down:
            return(FacingDirection.Up);

        case FacingDirection.Left:
            return(FacingDirection.Right);

        default:
            return(FacingDirection.Left);
        }
    }
 public virtual void Face(FacingDirection facingDirection)
 {
     if (facingDirection == FacingDirection.Right)
     {
         if (IsFacingRight)
         {
             Flip();
         }
     }
     else
     {
         if (IsFacingRight)
         {
             Flip();
         }
     }
 }
        private void UpdateVisuals(Vector2 input)
        {
            FacingDirection facingDirection = Character.FacingDirection;

            if (input.x < 0f)
            {
                facingDirection = FacingDirection.Left;
            }
            if (input.x > 0f)
            {
                facingDirection = FacingDirection.Right;
            }
            Character.SetFacingDirection(facingDirection);

            Character.Animator.SetBool(ANIM_KEY_WALK, input.x != 0);
            Character.Animator.SetBool(ANIM_KEY_JUMPING, IsJumping);
        }
Esempio n. 23
0
 protected void ChangeFacingDirection(float x)
 {
     if (x == 0)
     {
         return;
     }
     if (x > 0)
     {
         transform.localScale = new Vector3(-0.09f, 0.09f, 0.09f);
         Direction            = FacingDirection.Right;
     }
     else
     {
         transform.localScale = new Vector3(0.09f, 0.09f, 0.09f);
         Direction            = FacingDirection.Left;
     }
 }
Esempio n. 24
0
    public static float GetRotation(FacingDirection direction)
    {
        switch (direction)
        {
        case FacingDirection.Up:
            return(180);

        case FacingDirection.Right:
            return(90);

        case FacingDirection.Left:
            return(-90);

        default:
            return(0);
        }
    }
Esempio n. 25
0
 private void UpdateFacingDirection()
 {
     //  if player's velocity is positive... flip character scale to positive
     if (velocity.x > 0)
     {
         facingDirection = FacingDirection.Right;
         //  Flip the global control rig
         puppet2DGlobalControl.flip = false;
     }
     //  if player's velocity is negative... flip character scale to negative
     else if (velocity.x < 0)
     {
         facingDirection = FacingDirection.Left;
         //  Flip the global control rig
         puppet2DGlobalControl.flip = true;
     }
 }
Esempio n. 26
0
        public static void SwingWeapon(ICanSwing swingingObject, FacingDirection direction)
        {
            switch (direction)
            {
            case FacingDirection.North:
                break;

            case FacingDirection.South:
                break;

            case FacingDirection.East:
                break;

            case FacingDirection.West:
                break;
            }
        }
Esempio n. 27
0
 public bool CanPlayerJump(FacingDirection facingDirection)
 {
     RaycastHit2D[] hits = Physics2D.RaycastAll(this.m_collider.bounds.center, FacingDirectionToVector(facingDirection), m_distanceForEachStep * 1.2f);
     foreach (var hit in hits)
     {
         Ledge ledgeComponent = hit.collider.GetComponent <Ledge>();
         if (ledgeComponent == null)
         {
             continue;
         }
         if (ledgeComponent.GetJumpableDirection() == this.m_facingDirection)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 28
0
    //Metodo assume apenas valores de X e Z não vai ser zero no parametro dir. irá setar o valor z como padrão
    void ChangeFacing(Vector3 dir)
    {
        if (dir.z != 0)
        {
            facing = (dir.z > 0) ? FacingDirection.North : FacingDirection.South;
        }
        else if (dir.x != 0)
        {
            facing = (dir.x > 0) ? FacingDirection.East : FacingDirection.West;
        }

        //chamar o evento de direção
        if (OnFancingChange != null)
        {
            OnFancingChange(facing);
        }
    }
Esempio n. 29
0
    public override void TakeDamage(FacingDirection directionOfDamage, float amountOfDamage, float amountOfKnockback)
    {
        health -= amountOfDamage;
        Vector2 force = new Vector2(0, 0);

        Debug.Log(name + " is taking " + amountOfDamage + " damage");

        switch (directionOfDamage)
        {
        case FacingDirection.North:
            force = new Vector2(0, amountOfKnockback);
            break;

        case FacingDirection.South:
            force = new Vector2(0, -amountOfKnockback);
            break;

        case FacingDirection.East:
            force = new Vector2(amountOfKnockback, 0);
            break;

        case FacingDirection.West:
            force = new Vector2(-amountOfKnockback, 0);
            break;

        case FacingDirection.NorthEast:
            force = new Vector2(amountOfKnockback / 2, amountOfKnockback / 2);
            break;

        case FacingDirection.NorthWest:
            force = new Vector2(-amountOfKnockback / 2, amountOfKnockback / 2);
            break;

        case FacingDirection.SouthEast:
            force = new Vector2(amountOfKnockback, -amountOfKnockback / 2);
            break;

        case FacingDirection.SouthWest:
            force = new Vector2(-amountOfKnockback / 2, -amountOfKnockback / 2);
            break;
        }

        rb2d.AddForce(force);
        Debug.Log(name + " is taking " + amountOfKnockback + " knockback");
    }
Esempio n. 30
0
    public static Vector2 ToVector(this FacingDirection direction)
    {
        switch (direction)
        {
        case FacingDirection.Up:
            return(Vector2.up);

        case FacingDirection.Right:
            return(Vector2.right);

        case FacingDirection.Down:
            return(Vector2.down);

        case FacingDirection.Left:
            return(Vector2.left);
        }
        return(Vector2.down);
    }
        public void Ships_moving_forward_should_be_affected_by_their_direction(FacingDirection facing, int expectedXPos, int expectedYPos)
        {
            var board = new TestSetup()
                        .WithShip(
                new ShipBuilder()
                .At(1, 1)
                .Facing(facing)
                .Moving(Move.Forward)
                .GetShip()
                )
                        .GetBoard();
            var collisionResults = CollisionMechanics.Calculate(board);

            Assert.AreEqual(0, collisionResults.Collisions.Count());
            Assert.AreEqual(expectedXPos, collisionResults.ResultingBoard.PlayerOneShip.XPos);
            Assert.AreEqual(expectedYPos, collisionResults.ResultingBoard.PlayerOneShip.YPos);
            Assert.AreEqual(facing, collisionResults.ResultingBoard.PlayerOneShip.FacingDirection);
        }
Esempio n. 32
0
        public void SetFacingDirection(FacingDirection facingDirection)
        {
            if (facingDirection == FacingDirection)
            {
                return;
            }

            Vector3 scale = Vector3.one;

            if (facingDirection == FacingDirection.Left)
            {
                scale.x = -1f;
            }
            visualsRoot.localScale    = scale;
            visualsRoot.localPosition = scale.x * visualsOffset;

            FacingDirection = facingDirection;
        }
Esempio n. 33
0
    public static Vector3 directionToVector(FacingDirection direction)
    {
        switch (direction)
        {
        case FacingDirection.Up:
            return(new Vector3(0, 1, 0));

        case FacingDirection.Left:
            return(new Vector3(-1, 0, 0));

        case FacingDirection.Down:
            return(new Vector3(0, -1, 0));

        case FacingDirection.Right:
            return(new Vector3(1, 0, 0));
        }
        return(new Vector3(0, 0, 0));
    }
Esempio n. 34
0
    public void ChangeDirection(FacingDirection newDirection)
    {
        //if (newDirection == FacingDirection.LEFT)
        //{
        //    m_FacingDirection = FacingDirection.RIGHT;
        //}
        //else
        //{
        //    m_FacingDirection = FacingDirection.LEFT;
        //}

        m_FacingDirection = newDirection;

        Vector3 scale = m_Transform.localScale;

        scale.x *= -1;
        m_Transform.localScale = scale;
    }
Esempio n. 35
0
    string directionToString(FacingDirection dir)
    {
        switch (dir)
        {
        case FacingDirection.Down:
            return("Down");

        case FacingDirection.Left:
            return("Left");

        case FacingDirection.Right:
            return("Right");

        case FacingDirection.Up:
            return("Up");
        }
        return(null);
    }
Esempio n. 36
0
        public void changeFacingDirection(string direction)
        {
            directionMoving = direction;
            switch (direction)
            {
            case "Up": facing = FacingDirection.North; break;

            case "Down": facing = FacingDirection.South; break;

            case "Left": facing = FacingDirection.West; break;

            case "Right": facing = FacingDirection.East; break;

            default: break;
            }

            standCoolDown = standCoolMax; //halts the player briefly before being able to start moving in that direction
        }
Esempio n. 37
0
 protected void DestroyPlayer(bool front)
 {
     Time.timeScale = 0.2f;
     if (!front)
     {
         if (facing == FacingDirection.East)
         {
             facing = FacingDirection.West;
         }
         else
         {
             facing = FacingDirection.East;
         }
     }
     am.PlayerHit(0);
     dead    = true;
     stunned = true;
 }
    void CalculateFacing(float x, float y)
    {
        if (x > deadSize && x > y)
        {
            facing = FacingDirection.right;
            gameObject.GetComponent <SpriteRenderer> ().sprite = right;
        }
        else if (x < -deadSize && x < y)
        {
            facing = FacingDirection.left;
            gameObject.GetComponent <SpriteRenderer> ().sprite = left;
        }
        else if (y > deadSize)
        {
            facing = FacingDirection.up;
            gameObject.GetComponent <SpriteRenderer> ().sprite = back;
        }
        else if (y < -deadSize)
        {
            facing = FacingDirection.down;
            gameObject.GetComponent <SpriteRenderer> ().sprite = front;
        }


        if (RB.velocity == Vector2.zero)
        {
            if (facing == FacingDirection.left)
            {
                gameObject.GetComponent <SpriteRenderer> ().sprite = left;
            }
            else if (facing == FacingDirection.right)
            {
                gameObject.GetComponent <SpriteRenderer> ().sprite = right;
            }
            else if (facing == FacingDirection.up)
            {
                gameObject.GetComponent <SpriteRenderer> ().sprite = back;
            }
            else if (facing == FacingDirection.down)
            {
                gameObject.GetComponent <SpriteRenderer> ().sprite = front;
            }
        }
    }
Esempio n. 39
0
        public static MapEnemy FromBytes(byte[] bytes)
        {
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                byte[] tempBytes = new byte[sizeof(int)];
                stream.Read(tempBytes, 0, sizeof(int));
                int enemyID = BitConverter.ToInt32(tempBytes, 0);

                stream.Read(tempBytes, 0, sizeof(int));
                int hp = BitConverter.ToInt32(tempBytes, 0);

                stream.Read(tempBytes, 0, sizeof(int));
                int mapX = BitConverter.ToInt32(tempBytes, 0);

                stream.Read(tempBytes, 0, sizeof(int));
                int mapY = BitConverter.ToInt32(tempBytes, 0);

                stream.Read(tempBytes, 0, sizeof(int));
                FacingDirection direction = (FacingDirection)BitConverter.ToInt32(tempBytes, 0);

                tempBytes = new byte[sizeof(float)];
                stream.Read(tempBytes, 0, sizeof(float));
                float realX = BitConverter.ToSingle(tempBytes, 0);

                stream.Read(tempBytes, 0, sizeof(float));
                float realY = BitConverter.ToSingle(tempBytes, 0);


                tempBytes = new byte[sizeof(bool)];
                stream.Read(tempBytes, 0, sizeof(bool));
                bool onBridge = BitConverter.ToBoolean(tempBytes, 0);

                stream.Read(tempBytes, 0, sizeof(bool));
                bool dead = BitConverter.ToBoolean(tempBytes, 0);

                MapEnemy mapEvent = new MapEnemy(enemyID, mapX, mapY, onBridge);
                mapEvent.HP        = hp;
                mapEvent.RealX     = realX;
                mapEvent.RealY     = realY;
                mapEvent.Direction = direction;
                mapEvent.Dead      = dead;
                return(mapEvent);
            }
        }
        public void Move(FacingDirection f, float deltaTime)
        {
            if (currentFacingDirection != f)
            {
                parentActor.Transform.Scale = new Vector2(((int)f) * parentActor.Transform.Scale.X, parentActor.Transform.Scale.Y);
            }
            currentFacingDirection = f;

            var currentPos = parentActor.Transform.Position;
            if (currentFacingDirection == FacingDirection.Left)
            {
                currentPos.X -= movementSpeed * deltaTime;
                parentActor.Transform.Position = currentPos;
            }
            else
            {
                currentPos.X += movementSpeed * deltaTime;
                parentActor.Transform.Position = currentPos;
            }
        }
Esempio n. 41
0
        /// <summary>
        /// Contains all options to run a portrait command.
        /// </summary>
        /// <param name="useDefaultSettings">Will use stage default times for animation and fade</param>
        public PortraitOptions(bool useDefaultSettings = true)
        {
            character = null;
            replacedCharacter = null;
            portrait = null;
            display = DisplayType.None;
            offset = PositionOffset.None;
            fromPosition = null;
            toPosition = null;
            facing = FacingDirection.None;
            shiftOffset = new Vector2(0, 0);
            move = false;
            shiftIntoPlace = false;
            waitUntilFinished = false;
            onComplete = null;

            // Special values that can be overridden
            fadeDuration = 0.5f;
            moveDuration = 1f;
            this.useDefaultSettings = useDefaultSettings;
        }
Esempio n. 42
0
        private void HandleMovement(FacingDirection direction, bool isRunning)
        {
            if (!IsIdle())
                return;

            Vector2 position = Coordinates;
            Direction = direction;
            Vector2 displacement = mDisplacement;
            switch (direction)
            {
                case Character.FacingDirection.Up:
                    position.Y -= 1;
                    displacement.Y -= 1;
                    break;
                case Character.FacingDirection.Down:
                    position.Y += 1;
                    displacement.Y += 1;
                    break;
                case Character.FacingDirection.Left:
                    position.X -= 1;
                    displacement.X -= 1;
                    break;
                case Character.FacingDirection.Right:
                    position.X += 1;
                    displacement.X += 1;
                    break;
            }

            if (CurrentWorld.CollisionCheck(position))
            {
                Character.ActionState action = Character.ActionState.Walk;
                if (isRunning)
                    action = Character.ActionState.Run;

                Coordinates = position;
                mDisplacement = displacement;
                SetActionState(action);
            }
        }
Esempio n. 43
0
        public Teleport(TmxObject obj, Tileset tileset) : base(obj, tileset)
        {
            string[] property = obj.Properties["teleport"].Split(',');
            Map = property[0];
            TeleportPosition = new Vector2(int.Parse(property[1]), int.Parse(property[2]));

            switch (property[3])
            {
                case "up":
                    Direction = FacingDirection.Up;
                    break;
                case "down":
                    Direction = FacingDirection.Down;
                    break;
                case "left":
                    Direction = FacingDirection.Left;
                    break;
                case "right":
                    Direction = FacingDirection.Right;
                    break;
            }
        }
Esempio n. 44
0
 void Turning()
 {
     Vector3 mousePosVector = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     Vector3 playerToMouse = mousePosVector - transform.position;
     playerToMouse.z = 0f;
     if (Mathf.Abs(playerToMouse.y) >= Mathf.Abs(playerToMouse.x))
     {
         if (playerToMouse.y <= 0)
             direction = FacingDirection.Front;
         else direction = FacingDirection.Back;
     }
     else
     {
         if (playerToMouse.x <= 0)
             direction = FacingDirection.Left;
         else direction = FacingDirection.Right;
     }
 }
Esempio n. 45
0
		public override void OnEnter()
		{
			// If no display specified, do nothing
			if (display == DisplayType.None)
			{
				Continue();
				return;
			}

			// If no character specified, do nothing
			if (character == null)
			{
				Continue();
				return;
			}

			// If Replace and no replaced character specified, do nothing
			if (display == DisplayType.Replace && replacedCharacter == null)
			{
				Continue();
				return;
			}

			// Selected "use default Portrait Stage"
			if (stage == null)            // Default portrait stage selected
			{
				if (stage == null)        // If no default specified, try to get any portrait stage in the scene
				{
					stage = GameObject.FindObjectOfType<Stage>();
				}
			}

			// If portrait stage does not exist, do nothing
			if (stage == null)
			{
				Continue();
				return;
			}

			// Use default settings
			if (useDefaultSettings)
			{
				fadeDuration = stage.fadeDuration;
				moveDuration = stage.moveDuration;
				shiftOffset = stage.shiftOffset;
			}

			if (character.state.portraitImage == null)
			{
				CreatePortraitObject(character, stage);
			}

			// if no previous portrait, use default portrait
			if (character.state.portrait == null) 
			{
				character.state.portrait = character.profileSprite;
			}

			// Selected "use previous portrait"
			if (portrait == null) 
			{
				portrait = character.state.portrait;
			}

			// if no previous position, use default position
			if (character.state.position == null)
			{
				character.state.position = stage.defaultPosition.rectTransform;
			}

			// Selected "use previous position"
			if (toPosition == null)
			{
				toPosition = character.state.position;
			}

			if (replacedCharacter != null)
			{
				// if no previous position, use default position
				if (replacedCharacter.state.position == null)
				{
					replacedCharacter.state.position = stage.defaultPosition.rectTransform;
				}
			}

			// If swapping, use replaced character's position
			if (display == DisplayType.Replace)
			{
				toPosition = replacedCharacter.state.position;
			}

			// Selected "use previous position"
			if (fromPosition == null)
			{
				fromPosition = character.state.position;
			}

			// if portrait not moving, use from position is same as to position
			if (!move)
			{
				fromPosition = toPosition;
			}

			if (display == DisplayType.Hide)
			{
				fromPosition = character.state.position;
			}

			// if no previous facing direction, use default facing direction
			if (character.state.facing == FacingDirection.None) 
			{
				character.state.facing = character.portraitsFace;
			}

			// Selected "use previous facing direction"
			if (facing == FacingDirection.None)
			{
				facing = character.state.facing;
			}

			switch(display)
			{
			case (DisplayType.Show):
				Show(character, fromPosition, toPosition);
				character.state.onScreen = true;
				if (!stage.charactersOnStage.Contains(character))
				{
					stage.charactersOnStage.Add(character);
				}
				break;

			case (DisplayType.Hide):
				Hide(character, fromPosition, toPosition);
				character.state.onScreen = false;
				stage.charactersOnStage.Remove(character);
				break;

			case (DisplayType.Replace):
				Show(character, fromPosition, toPosition);
				Hide(replacedCharacter, replacedCharacter.state.position, replacedCharacter.state.position);
				character.state.onScreen = true;
				replacedCharacter.state.onScreen = false;
				stage.charactersOnStage.Add(character);
				stage.charactersOnStage.Remove(replacedCharacter);
				break;

			case (DisplayType.MoveToFront):
				MoveToFront(character);
				break;
			}
			
			if (display == DisplayType.Replace)
			{
				character.state.display = DisplayType.Show;
				replacedCharacter.state.display = DisplayType.Hide;
			}
			else
			{
				character.state.display = display;
			}

			character.state.portrait = portrait;
			character.state.facing = facing;
			character.state.position = toPosition;

			waitTimer = 0f;
			if (!waitUntilFinished)
			{
				Continue();
			}
			else
			{
				StartCoroutine(WaitUntilFinished(fadeDuration));
			}
		}
Esempio n. 46
0
        protected FacingDirection GetFacingDirection(Vector2 moveVectIn)
        {
            // Convert a movement vector to face direction
            float angle = ((float)Math.Atan2(-moveVectIn.Y, -moveVectIn.X) + MathHelper.TwoPi) % MathHelper.TwoPi;
            int polarRegion = (int)Math.Round(angle * 8f / MathHelper.TwoPi) % 8;
            if (polarRegion > 7) polarRegion -= 8;
            switch (polarRegion)
            {
                case 0: facingDirection = FacingDirection.West; break;
                case 1: facingDirection = FacingDirection.NorthWest; break;
                case 2: facingDirection = FacingDirection.North; break;
                case 3: facingDirection = FacingDirection.NorthEast; break;
                case 4: facingDirection = FacingDirection.East; break;
                case 5: facingDirection = FacingDirection.SouthEast; break;
                case 6: facingDirection = FacingDirection.South; break;
                case 7: facingDirection = FacingDirection.SouthWest; break;
                default: facingDirection = FacingDirection.South; break;

            }
            return facingDirection;
        }
Esempio n. 47
0
 void Animating()
 {
     if (prevDirection != direction)
     {
         anim.SetInteger("Direction", (int)direction);
         prevDirection = direction;
     }
 }
Esempio n. 48
0
    public void Patrol()
    {
        poiTimer = 0f;
        if (!ranged)
            destinationReached = false;

        float h = currentPOI.Current.gameObject.transform.position.x;
        float v = currentPOI.Current.gameObject.transform.position.y;
        Move(h - transform.position.x, v - transform.position.y);

        Vector3 facing = currentPOI.Current.gameObject.transform.position - transform.position;
        facing.z = 0f;
        if (Mathf.Abs(facing.y) >= Mathf.Abs(facing.x))
        {
            if (facing.y <= 0)
                direction = FacingDirection.Front;
            else direction = FacingDirection.Back;
        }
        else
        {
            if (facing.x <= 0)
                direction = FacingDirection.Left;
            else direction = FacingDirection.Right;
        }
    }
Esempio n. 49
0
    void FixedUpdate()
    {
        // if we haven't set up the enumerator, do so
        if (currentPOI.Current == null)
        {
            currentPOI = points.GetEnumerator();
            currentPOI.MoveNext(); //set the enumerator to the first element (Why microsoft?)
            currentRotation = currentPOI.Current.directionPattern.GetEnumerator();
            currentRotation.MoveNext(); //why
        }

        // get the player's direction relative to the enemy if they're within range
        if (alerted)
        {
            Vector3 playerVector = player.transform.position - transform.position;
            playerVector.z = 0f;
            if (Mathf.Abs(playerVector.y) >= Mathf.Abs(playerVector.x))
            {
                if (playerVector.y <= 0)
                    playerDirection = FacingDirection.Front;
                else playerDirection = FacingDirection.Back;
            }
            else
            {
                if (playerVector.x <= 0)
                    playerDirection = FacingDirection.Left;
                else playerDirection = FacingDirection.Right;
            }
        }

        attackTimer += Time.deltaTime;

        //attack update
        if (playerScript.currentHealth <= 0)
        {
            alerted = false;
            playerInRange = false;
        }

        if (attackTimer >= timeBetweenAttacks && playerInRange && alerted && playerDirection == direction && currentHealth > 0)
        {
            attackTimer = 0f;
            attackScript.Attack(player);
        }

        //movement update
        if (!alerted)
        {
            if (destinationReached)
            { //if you are waiting at a POI
                poiTimer += Time.deltaTime;
                turnTimer += Time.deltaTime;
                if (turnTimer >= currentPOI.Current.rotationSpeed)
                    Turn();
                if (poiTimer >= currentPOI.Current.restTime)
                {
                    if (!currentPOI.MoveNext())
                    { //if you reached the end of the list, restart.
                        currentPOI = points.GetEnumerator();
                        currentPOI.MoveNext(); // y
                        currentRotation = currentPOI.Current.directionPattern.GetEnumerator();
                        currentRotation.MoveNext(); // whyyy
                    }
                    Patrol();
                }
            }
            else // or travelling to a new POI
                Patrol();
        }
        else
        {
            if (!ranged && direction == playerDirection) // chase player
                Move(player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y);

            Vector3 facing = player.transform.position - transform.position;
            facing.z = 0f;
            if (Mathf.Abs(facing.y) >= Mathf.Abs(facing.x))
            {
                if (facing.y <= 0)
                    direction = FacingDirection.Front;
                else direction = FacingDirection.Back;
            }
            else
            {
                if (facing.x <= 0)
                    direction = FacingDirection.Left;
                else direction = FacingDirection.Right;
            }
        }
        Animating();
    }
Esempio n. 50
0
 public WaterSpell(FacingDirection fd, Vector2 pPosition)
 {
     SpellOrigin = pPosition;
     Direction = fd;
 }
Esempio n. 51
0
 // Faces the merchant in a given direction; This changes the merchant's sprite to match this
 //TODO: This is depreciated. All uses have been moved to animator controllers.
 public void Face(FacingDirection facingDirection)
 {
     merchant.Face(facingDirection);
 }
 private static Quaternion FaceObject(Vector3 direction, FacingDirection facing)
 {
     float angle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
     angle -= (float)facing;
     return Quaternion.AngleAxis(angle, Vector3.up);
 }
	private void UpdateAnimation ()
	{
		if (!_canMove)
		{
			return;	
		}
		// Only update the animator if we have a new direction
		FacingDirection l_newDirection = FacingDirection.None;
		
		// Moving right
		if (Input.GetAxis ("Horizontal") > 0)
		{
			l_newDirection = FacingDirection.Right;
		} else if (Input.GetAxis("Horizontal") < 0)
		{
			l_newDirection = FacingDirection.Left;
		}

		// Moving up
		if (Input.GetAxis ("Vertical") > 0)
		{
			l_newDirection = FacingDirection.Up;
		} else if (Input.GetAxis ("Vertical") < 0)
		{
			l_newDirection = FacingDirection.Down;
		}
		if ((l_newDirection != _currentDirection && l_newDirection != FacingDirection.None) || _wasIdle)
		{
			_currentDirection = l_newDirection;
			_wasIdle = false;
			switch (_currentDirection)
			{
				case FacingDirection.Up:
				{
					SetAnimatorTriggers ("walkUp");
					break;
				}
				case FacingDirection.Down:
				{
					SetAnimatorTriggers ("walkDown");	
					break;
				}
				case FacingDirection.Left:
				{
					SetAnimatorTriggers("walkLeft");
					break;				
				}
				case FacingDirection.Right:
				{
					SetAnimatorTriggers("walkRight");	
					break;
				}
			}
		}
	}
Esempio n. 54
0
    void Start()
    {
        currentHeldItem = "nothingHeld";
        spriteRenderer = GetComponent<SpriteRenderer> ();

        facingDir = FacingDirection.Right;
        controller = GetComponent<CharacterController>();
        pickupScript = GetComponent<PickupScript>();
        myTrans = transform;
    }
Esempio n. 55
0
 void Animating(float h, float v)
 {
     bool isMoving = h != 0f || v != 0f;
     if(isMoving && !wasMoving)
         anim.SetBool("IsMoving", true);
     else if (!isMoving && wasMoving)
         anim.SetBool("IsMoving", false);
     if(direction != prevDirection)
         anim.SetInteger("Direction", (int)direction);
     wasMoving = isMoving;
     prevDirection = direction;
 }
Esempio n. 56
0
    void Awake()
    {
        currentHealth = startingHealth;
        attackTimer = 0f;
        poiTimer = 0f;
        turnTimer = 0f;
        destinationReached = false;
        alerted = false;
        playerInRange = false;
        damageTaken = false;
        direction = FacingDirection.Front;

        player = GameObject.FindWithTag("Player");
        playerScript = player.GetComponent<Player>();
        detection = player.GetComponentInChildren<PlayerDetection>();
        enemyRigidbody = GetComponent<Rigidbody2D>();
        if (ranged)
            attackScript = GetComponentInChildren<EnemyShooting>();
        else
            attackScript = GetComponentInChildren<EnemyMelee>();
        attackRangeCollider = attackScript.gameObject.GetComponent<CircleCollider2D>();
        attackRangeCollider.radius = attackScript.GetRange();
        anim = GetComponent<Animator>();
        points = new List<PointOfInterest>();
    }
Esempio n. 57
0
    void HandleKeyPress()
    {
        if (Input.GetKeyUp(KeyCode.E))
        {
            if (!InteractingWith)
            {
                //interactie met iets
                NPC closest = null;
                float c = float.MaxValue;

                bool looping = true;
                while (looping)
                {
                    foreach (NPC npc in (NPC[])GameObject.FindObjectsOfType<NPC>())
                    {
                        bool nothit = true;
                        float dist = Vector3.Distance(this.transform.position, npc.gameObject.transform.position);
                        if (dist < c)
                        {
                            closest = npc;
                            c = dist;

                            nothit = true;
                        }

                        if (nothit)
                            looping = false;
                    }
                }
                if (c < 3.5f) //interact range!!!
                {
                    if (closest.Interact())
                    {                        
                        //zoom in camera
                        InteractingWith = true;
                        InteractingNPC = closest;
                    }
                }
            }
            else
            { 
                //volgende regel?
                if (ConvState == ConversationState.NPC)
                    ConvState = ConversationState.Player;
                else
                    ConvState = ConversationState.NPC;

                InteractingNPC.NextConversationLine();
            }
        }

        SetItemMoving(false);

        if (Input.GetKey(KeyCode.W))
        {
            SetItemMoving(true);
            TargetPosition += new Vector3(0, 0, 1.0f / MoveSpeed);
            SetItemFacing(ItemFacing.Up);

            if (Facing != FacingDirection.Front)
            {
                GetComponent<Renderer>().material.mainTexture = textures[0];
                Facing = FacingDirection.Front;                
            }
        }
        if (Input.GetKey(KeyCode.S))
        {
            SetItemMoving(true);            
            TargetPosition += new Vector3(0, 0, -1.0f / MoveSpeed);
            SetItemFacing(ItemFacing.Down);

            if (Facing != FacingDirection.Back)
            {
                //change sprite
                GetComponent<Renderer>().material.mainTexture = textures[1];
                Facing = FacingDirection.Back;
            }
        }
        if (Input.GetKey(KeyCode.A))
        {
            SetItemMoving(true);
            TargetPosition += new Vector3(-1.0f / MoveSpeed, 0, 0);
            SetItemFacing(ItemFacing.Left);

            if (Facing != FacingDirection.Left)
            {
                GetComponent<Renderer>().material.mainTexture = textures[2];
                Facing = FacingDirection.Left;
            }
        }
        if (Input.GetKey(KeyCode.D))
        {
            SetItemMoving(true);
            TargetPosition += new Vector3(1.0f / MoveSpeed, 0, 0);
            SetItemFacing(ItemFacing.Right);

            if (Facing != FacingDirection.Right)
            {
                GetComponent<Renderer>().material.mainTexture = textures[3];
                Facing = FacingDirection.Right;
            }
        }                      
    }
Esempio n. 58
0
 void Turn()
 {
     direction = currentRotation.Current;
     if (!currentRotation.MoveNext())
     {
         currentRotation = currentPOI.Current.directionPattern.GetEnumerator();
         currentRotation.MoveNext();
     }
     turnTimer = 0f;
 }
Esempio n. 59
0
    void Update()
    {
        if (facingDir == FacingDirection.Right)
            spriteRenderer.sprite = spriteRight;
        if (facingDir == FacingDirection.Left)
            spriteRenderer.sprite = spriteLeft;
        if (facingDir == FacingDirection.Up)
            spriteRenderer.sprite = spriteUp;
        if (facingDir == FacingDirection.Down)
            spriteRenderer.sprite = spriteDown;

        if (currentlyInChat == false) {
            moveDir = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"), 0);
            moveDir = transform.TransformDirection (moveDir);
            moveDir *= speed;
        } else {
            moveDir = Vector3.zero;
        }

        //		Debug.Log (facingDir);
        if (moveDir.x > 0) {
            facingDir = FacingDirection.Right;
            animWalkingRight = true;
        }
        if (moveDir.x < 0) {
            facingDir = FacingDirection.Left;
            animWalkingLeft = true;
        }
            if (moveDir.y > 0){
            facingDir = FacingDirection.Up;
            animWalkingRight = true;
        }
        if (moveDir.y < 0){
            facingDir = FacingDirection.Down;
            animWalkingLeft = true;
        }
        if (moveDir.y == 0 && moveDir.x == 0) {

            animWalkingLeft = false;
            animWalkingRight = false;

        }

        anim.SetBool("WalkingRight", animWalkingRight);
        anim.SetBool ("WalkingLeft", animWalkingLeft);
        //		moveDir.x -= gravity * Time.deltaTime;
        controller.Move(moveDir * Time.deltaTime);
        myTrans.position = new Vector3 (myTrans.position.x, myTrans.position.y, 0);

        if( Input.GetButtonDown("pickup") && pickupScript != null) //the E key, it's pre-set in the input manager so can be changed by players on launch
        {
            if(currentHeldItem != null)
            {
                pickupScript.Drop();
            }
            else
            {
                pickupScript.Pickup(transform);

            }
        }
        #region TestingArea
        // functions below are intended only for debugging and testing purposes, before utlizing these however, make sure testing mode is checked in the inspector, otherwise these won't work. /H
        if (testMode) {
        if (Input.GetKeyDown(KeyCode.G) )
                if (currentHeldItem != null)
                Debug.Log (currentHeldItem);
            else Debug.Log ("Nothing Is Currently Held By The Player");

        }
        #endregion
    }
	void OnEnable () 
	{
		SoftPauseScript.instance.SoftUpdate += SoftUpdate;
		_currentDirection = FacingDirection.Down;
		_canMove = true;
	}