コード例 #1
0
    protected void LookAt90(Vector3 lookingPos)
    {
        if (sprite == null)
        {
            return;
        }

        LookingDirection look = CalcLookingDirection2(lookingPos);

        switch (look)
        {
        case LookingDirection.Left:
            sprite.transform.localScale = new Vector3(1, 1, 1);
            break;

        case LookingDirection.Right:
            sprite.transform.localScale = new Vector3(-1, 1, 1);
            break;

        case LookingDirection.Up:
            break;

        case LookingDirection.Down:
            break;
        }
    }
コード例 #2
0
    IEnumerator FindAngleInEvery1Sec()
    {
        while (true)
        {
            myLookingDirection = FindAngleBetweenHeroAndMe(this.transform.position, playerObject.transform.position);

            //Debug.Log(myLookingDirection);

            switch (myLookingDirection)
            {
            case LookingDirection.Top:
                direction = Vector2.up;
                break;

            case LookingDirection.Down:
                direction = Vector2.down;
                break;

            case LookingDirection.Left:
                direction = Vector2.left;
                break;

            case LookingDirection.Right:
                direction = Vector2.right;
                break;

            default:
                direction = Vector2.zero;
                break;
            }

            yield return(new WaitForSeconds(delayForSettingDirection));
        }
    }
コード例 #3
0
    private void MovementScript_OnAxisChanged(float HorizontalAxis)
    {
        if (HorizontalAxis > 0)
        {
            //Play("Run");
            MovementSpeed    = 5f;
            LookingDirection = LookingDirection.Right;
            if (LookingDirection == LookingDirection.Right)
            {
                transform.localRotation = new Quaternion(0, 0, 0, 0);
            }
            //MovementAudio.Play();
        }
        if (HorizontalAxis < 0)
        {
            //Play("Run");
            MovementSpeed    = 5f;
            LookingDirection = LookingDirection.Left;
            if (LookingDirection == LookingDirection.Left)
            {
                transform.localRotation = new Quaternion(0, -180, 0, 0);
            }
            //MovementAudio.Play();
        }
        if (HorizontalAxis == 0)
        {
            MovementSpeed = 0f;
        }

        //Debug.Log("Player looking to the  " + LookingDirection);

        RigidBody.velocity = new Vector2(HorizontalAxis * MovementSpeed, RigidBody.velocity.y);
    }
コード例 #4
0
    public LookingDirection MirrorDirection(LookingDirection dir, int axis)
    {
        if (axis == 0)        //X-axis
        {
            if (dir == LookingDirection.North)
            {
                return(LookingDirection.South);
            }
            if (dir == LookingDirection.South)
            {
                return(LookingDirection.North);
            }
        }

        if (axis == 1)        //Y-Axis
        {
            if (dir == LookingDirection.East)
            {
                return(LookingDirection.West);
            }
            if (dir == LookingDirection.West)
            {
                return(LookingDirection.East);
            }
        }

        return(dir);
    }
コード例 #5
0
    public LookingDirection MirrorDirection(int dirInt, int axis)
    {
        LookingDirection dir = (LookingDirection)dirInt;

        if (axis == 0 || axis == 2)        //X-axis
        {
            if (dir == LookingDirection.North)
            {
                return(LookingDirection.South);
            }
            if (dir == LookingDirection.South)
            {
                return(LookingDirection.North);
            }
        }

        if (axis == 1 || axis == 2)        //Y-Axis
        {
            if (dir == LookingDirection.East)
            {
                return(LookingDirection.West);
            }
            if (dir == LookingDirection.West)
            {
                return(LookingDirection.East);
            }
        }

        return(dir);
    }
コード例 #6
0
 public void Hit(int damageTaken, Vector2 hitPoint, LookingDirection hitDirection)
 {
     if (destroyWhenHit)
     {
         Destroy(gameObject);
     }
 }
コード例 #7
0
 /// <summary>
 /// The general checks for pressing any move key.
 /// </summary>
 private void CheckMoving()
 {
     // Check for every moving key.
     changeSide = false;
     changeSide = Input.GetKey(KeyCode.LeftShift);
     if (!changeSide)
     {
         //LEFT
         if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
         {
             lookDir = LookingDirection.Left;
             MoveKeyPressed();
         }
         //RIGHT
         if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
         {
             lookDir = LookingDirection.Right;
             MoveKeyPressed();
         }
         //UP
         if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
         {
             lookDir = LookingDirection.Up;
             MoveKeyPressed();
         }
         //DOWN
         if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
         {
             lookDir = LookingDirection.Down;
             MoveKeyPressed();
         }
     }
 }
コード例 #8
0
 public Character(Point location)
 {
     this.location         = location;
     this.creationTime     = Extensions.GetMicroSeconds();
     this.state            = State.Standing;
     this.lookingDirection = LookingDirection.Right;
 }
コード例 #9
0
 /// <summary>
 /// The awake function is used to apply values to variables.
 /// </summary>
 protected void Awake()
 {
     render               = GetComponent <SpriteRenderer> ();
     lookDir              = LookingDirection.Down;
     curAnimState         = AnimationStates.Idle;
     LastPressedDirection = new List <LookingDirection> ();
 }
コード例 #10
0
    public void SetWallStatus(LookingDirection direc, bool status, bool pass)
    {
        //Debug.Log("happened " + direc + "/" + status);

        switch (direc)
        {
        case LookingDirection.North:
            mWallNorth.SetActivation(status);
            mWallNorth.SetPassabble(pass);
            break;

        case LookingDirection.South:
            mWallSouth.SetActivation(status);
            mWallSouth.SetPassabble(pass);
            break;

        case LookingDirection.East:
            mWallEast.SetActivation(status);
            mWallEast.SetPassabble(pass);
            break;

        case LookingDirection.West:
            mWallWest.SetActivation(status);
            mWallWest.SetPassabble(pass);
            break;
        }
        //Debug.Log("reached it " + status + "/" + mWallNorthActive + "|" + mWallSouthActive + "|" + mWallWestActive + "|" + mWallEastActive);
    }
コード例 #11
0
 public override void DealDamage(MovableActor targetActor, LookingDirection direction)
 {
     Player.Instance.InteractionBlocked = true;
     mAttacking       = true;
     mAttackDirection = direction;
     AttackVisualistion();
 }
コード例 #12
0
    // Rotates object facing and wall attached to
    public LevelWall Rotate(LevelTile tile)
    {
        if (mFacing == LookingDirection.North)
        {
            // object is placed at wallSouth
            mFacing         = LookingDirection.East;
            mWallAttachedTo = tile.WallWest;
        }
        else if (mFacing == LookingDirection.East)
        {
            // object is placed at wallWest
            mFacing         = LookingDirection.South;
            mWallAttachedTo = tile.WallNorth;
        }
        else if (mFacing == LookingDirection.South)
        {
            // object is placed at wallSouth
            mFacing         = LookingDirection.West;
            mWallAttachedTo = tile.WallEast;
        }
        else if (mFacing == LookingDirection.West)
        {
            // object is placed at wallSouth
            mFacing         = LookingDirection.North;
            mWallAttachedTo = tile.WallSouth;
        }

        return(mWallAttachedTo);
    }
コード例 #13
0
    protected override void Shoot(float speed, LookingDirection direction)
    {
        //setup direction
        spriteDirection.FaceDirection(direction);

        // setup velocity
        rigidbody2d.velocity = spriteDirection.WorldLookingDirection * speed;
    }
コード例 #14
0
    public WeaponBehavior ShootWeapon(Vector3 SpawnPosition, LookingDirection direction, PlayerController owner)
    {
        WeaponBehavior instantiated = Instantiate(weaponPrefab, SpawnPosition, Quaternion.identity);

        instantiated.damage = weaponDamage;
        instantiated.Init(initialVelocity, direction, owner);
        return(instantiated);
    }
コード例 #15
0
    protected override void Shoot(float shootSpeed, LookingDirection direction)
    {
        // set drirection
        spriteDirection.FaceDirection(direction);

        // setup velocity
        rigidbody2d.velocity = new Vector2(SpriteDirection.LookingDirectionToVector2(direction).x *Mathf.Sin(throwingAngle), Mathf.Cos(throwingAngle)) * shootSpeed;
    }
コード例 #16
0
 public void FaceDirection(LookingDirection newDirection)
 {
     lookingDirection = newDirection;
     if (scalingValues.ContainsKey(lookingDirection))
     {
         transform.localScale = scalingValues[lookingDirection];
     }
 }
コード例 #17
0
    public void PlaceOnTile(LevelTile tile, LookingDirection goalDirec)
    {
        if (mTilePlacedOn)
        {
            mTilePlacedOn.ActorOnTile = null;                   // tile before we moved
        }
        mTilePlacedOn             = tile;                       // tile we moved to
        mTilePlacedOn.ActorOnTile = this;

        switch (goalDirec)
        {
        case LookingDirection.East:
            mWorldPos.position = mTilePlacedOn.transform.localPosition + new Vector3(mPosOffsetX, mPosOffsetY, 0);
            mFacing            = LookingDirection.East;
            break;

        case LookingDirection.North:
            mWorldPos.position = mTilePlacedOn.transform.localPosition + new Vector3(0, mPosOffsetY, mPosOffsetZ);
            mFacing            = LookingDirection.North;
            break;

        case LookingDirection.West:
            mWorldPos.position = mTilePlacedOn.transform.localPosition + new Vector3(-mPosOffsetX, mPosOffsetY, 0);
            mFacing            = LookingDirection.West;
            break;

        case LookingDirection.South:
            mWorldPos.position = mTilePlacedOn.transform.localPosition + new Vector3(0, mPosOffsetY, -mPosOffsetZ);
            mFacing            = LookingDirection.South;
            break;
        }

        AdjustRotation(goalDirec);

        //Map Update
        UpdateMap();

        // we moved so ask every with player collidable object, if player
        // collides with it
        if (mTriggersObjects)
        {
            if (!mInTransRotate)
            {
                foreach (GameObject obj in GameObject.FindGameObjectsWithTag("ReceivePlayerMovedEvent"))
                {
                    obj.SendMessage("OnPlayerMoved", SendMessageOptions.DontRequireReceiver);
                }
            }


            foreach (GameObject obj in GameObject.FindGameObjectsWithTag("ReceivePlayerActedEvent"))
            {
                obj.SendMessage("OnPlayerActed", SendMessageOptions.DontRequireReceiver);
            }
        }

        mGoalTile = null;
    }
コード例 #18
0
 public virtual void ReceiveDamage(int elementalDmg, int magicalDmg, LookingDirection direction)
 {
     // Damage taken Animation
     mHealth -= elementalDmg + magicalDmg;
     if (mHealth <= 0)
     {
         Die();
     }
 }
コード例 #19
0
    /// <summary>
    /// The function that gets called after a "spellcast" event.
    /// Rotates the instantiated spell towards the right direction.
    /// </summary>
    private void SpellCast()
    {
        dir = charAnim.lookDir;
        GameObject    spell         = Instantiate(fireBall, transform.position, Quaternion.identity) as GameObject;
        SpellMovement spellMovement = spell.GetComponent <SpellMovement>();

        spellMovement.lookDir = dir;
        spell.transform.SetParent(transform);
    }
コード例 #20
0
 public ShootingSprite(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOffset,
                       Point currentFrame, Point sheetSize, Vector2 speed, int millisecondsPerFrame, bool hasGravity, Game game,
                       List <Sprite> bullets, LookingDirection lookimgdirection)
     : base(textureImage, position, frameSize, collisionOffset, currentFrame, sheetSize, speed, millisecondsPerFrame, hasGravity, game)
 {
     collisionOffset     = 20;
     Bullets             = bullets;
     lookingDirection    = lookimgdirection;
     bulletRepeatWaitMax = ((float)((Game1)game).rnd.Next(bulletSpawnMinMilliSeconds, bulletSpawnMaxMilliSeconds)) / 1000;
 }
コード例 #21
0
 /// <summary>
 /// Gets looking direction to the side of given direction.
 /// </summary>
 /// <returns>
 /// The direction at side.
 /// </returns>
 /// <param name='direc'>
 /// direction to calculate side from.
 /// </param>
 /// <param name='side'>
 /// true - calculate late right side of direc, false - calculate left side of direc
 /// </param>
 public static LookingDirection GetDirectionAtSide(LookingDirection direc, bool side)
 {
     if (side)        //rotate right
     {
         return((LookingDirection)(((int)direc + 1) % 4));
     }
     else         // rotate left
     {
         return((LookingDirection)((4 + (int)direc - 1) % 4));
     }
 }
コード例 #22
0
ファイル: Player.cs プロジェクト: sirK2005/DungeonCrawler
    public override void ReceiveDamage(int elementalDmg, int magicalDmg, LookingDirection direction)
    {
        base.ReceiveDamage(elementalDmg, magicalDmg, direction);

        // get direction opposite of attacked direction and show on screen where dmg came from
        int facingDmgComesFrom = (4 + (int)World.GetOppositeDirection(direction) - (int)Facing) % 4;

        GameMainHUDScreen.Instance.SetDamageMarkerAlpha(facingDmgComesFrom, 1.0f);
        // calc new health bar fill
        GameMainHUDScreen.Instance.UpdateHealthBar(MaxHealth, Health);
    }
コード例 #23
0
    public static LookingDirection OtherDirectionY(LookingDirection direction)
    {
        switch (direction)
        {
        case LookingDirection.Left:
            return(LookingDirection.Right);

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

        default:
            return(direction);
        }
    }
コード例 #24
0
ファイル: LevelPart.cs プロジェクト: sirK2005/DungeonCrawler
    public LevelTile CreateTileInDirection(LookingDirection dir, LevelTile tile)
    {
        Vector2   pos;
        LevelTile selecTile = null;

        switch (dir)
        {
        case LookingDirection.North:
            pos       = new Vector2(tile.Pos.x, tile.Pos.y + 1);
            selecTile = CreateTile(pos, tile);
            if (selecTile != null)
            {
                tile.SetWallStatus(LookingDirection.North, false);
            }
            break;

        case LookingDirection.East:
            pos       = new Vector2(tile.Pos.x + 1, tile.Pos.y);
            selecTile = CreateTile(pos, tile);
            if (selecTile != null)
            {
                tile.SetWallStatus(LookingDirection.East, false);
            }
            break;

        case LookingDirection.South:
            pos       = new Vector2(tile.Pos.x, tile.Pos.y - 1);
            selecTile = CreateTile(pos, tile);
            if (selecTile != null)
            {
                tile.SetWallStatus(LookingDirection.South, false);
            }
            break;

        case LookingDirection.West:
            pos       = new Vector2(tile.Pos.x - 1, tile.Pos.y);
            selecTile = CreateTile(pos, tile);
            if (selecTile != null)
            {
                tile.SetWallStatus(LookingDirection.West, false);
            }
            break;

        default:
            Debug.LogWarning("createTileInDirection: something went wrong with the direction!");
            break;
        }

        return(selecTile);
    }
コード例 #25
0
 void TurnOver()
 {
     if (playerObj != null)
     {
         if (player.transform.position.x < transform.position.x + 0.5f)
         {
             LDirection = LookingDirection.Left;
         }
         else if (player.transform.position.x > transform.position.x - 0.5f)
         {
             LDirection = LookingDirection.Right;
         }
     }
 }
コード例 #26
0
 /// <summary>
 /// Rotates the actor camera either left or right
 /// </summary>
 /// <param name='turnRight'>
 /// True - rotate Camera to the right, false - rotate camera to the left
 /// </param>
 public void turn(bool turnRight)
 {
     mRotateTransDirec = turnRight;
     mInTransition     = mInTransRotate = true;
     mGoalTile         = mTilePlacedOn;
     //rotate looking direction
     if (turnRight)
     {
         mGoalFacing = World.GetDirectionAtSide(mFacing, true);
     }
     else
     {
         mGoalFacing = World.GetDirectionAtSide(mFacing, false);
     }
 }
コード例 #27
0
ファイル: FourSided.cs プロジェクト: sirK2005/DungeonCrawler
    // Use this for initialization
    void Start()
    {
        AttachedToWall obj = GetComponent <AttachedToWall>();

        if (obj)
        {
            mFacingDirection = obj.mFacing;
        }

        // adjust Facing Order in accordance to own facing
        for (int count = 0; count < (int)mFacingDirection; count++)
        {
            mFacingOrder.Insert(0, mFacingOrder[3]);
            mFacingOrder.RemoveAt(4);
        }
    }
コード例 #28
0
 void TurnOver()
 {
     if (player != null)
     {
         var scale = transform.localScale;
         if (player.transform.position.x < transform.position.x)
         {
             LDirection = LookingDirection.Left;
         }
         else if (player.transform.position.x > transform.position.x)
         {
             LDirection = LookingDirection.Right;
         }
         transform.localScale = scale;
     }
 }
コード例 #29
0
    public virtual void InitializeActor()
    {
        mWorldPos = transform;
        mFacing   = LookingDirection.North;

        mPosOffsetX = mPosOffsetZ = 0;
        mPosOffsetY = 7.5f;

        mInTransition     = false;
        mInTransRotate    = false;
        mRotateTransDirec = false;
        mTransitionSpeed  = 2.5f;

        mHealth = mMaxHealth;
        mDead   = false;
    }
コード例 #30
0
 public Vector2 DirectionToVector(LookingDirection dir)
 {
     if (dir == LookingDirection.North)
     {
         return(new Vector2(0, 1));
     }
     if (dir == LookingDirection.East)
     {
         return(new Vector2(1, 0));
     }
     if (dir == LookingDirection.South)
     {
         return(new Vector2(0, -1));
     }
     return(new Vector2(-1, 0));        // West
 }
コード例 #31
0
ファイル: NPC.cs プロジェクト: realjuancho/GGJ.2016.Ritual
	void Update ()
	{
			NPCTarget posicionObjetivo = posicionesObjetivo.GetCurrentNPCTarget();

			//Si encuentra una posición de objetivo
			if(posicionObjetivo)
			{

				//Voltea a ver la posicion de objetivo
			if (posicionObjetivo.transform.position.x > transform.position.x) {
				currentlyLooking = LookingDirection.Right;
			} else { 
				currentlyLooking = LookingDirection.Left;
			}
				SwitchFaces();

				if(!distracted)
				{
					transform.position = Vector2.Lerp(transform.position, posicionObjetivo.transform.position, Time.deltaTime * NPCspeed);
					Vector3 distancia = posicionObjetivo.transform.position - transform.position;

					if(distancia.magnitude < 0.01f)
					{
						transform.position = posicionObjetivo.transform.position;
						arrivedToTarget = true;
						anim.SetBool ("moving", false);
						distracted = posicionObjetivo.IsDistractor;
						timeToDistract = posicionObjetivo.DistractorTime;
					}
					visionFieldBoxCollider2D.enabled = true;
				}
				else 
				{
					if(timeSinceDistracted < timeToDistract)
					{
						timeSinceDistracted += Time.deltaTime;
						visionFieldBoxCollider2D.enabled = false;
					}
					else
					{
						distracted = false;
						timeSinceDistracted = 0.0f;
						timeToDistract = 0.0f;
						anim.SetBool("moving", true);
					}
				}

			}

			else{

				//Si el tiempo que ha estado mirando una direccion supera el maximo permitido, el NPC cambiará de dirección
				timeSinceCurrentlyLooking += Time.deltaTime;
				if(timeSinceCurrentlyLooking > turningTime)
				{
				if (currentlyLooking == LookingDirection.Left) {
					currentlyLooking = LookingDirection.Right;
				}

					timeSinceCurrentlyLooking = 0.0f;
					Debug.Log("Now Turn " + currentlyLooking);

					SwitchFaces();
				}
			}
	}