Example #1
0
    private bool IsBlockedTorwards(Direction?direction)
    {
        var nextCell  = this.Cell + CharMovement.GetDirectionVector2D(direction.Value);
        var isBlocked = direction.HasValue && this.grid.IsBlocked(nextCell);

        return(isBlocked);
    }
Example #2
0
    void Update()
    {
        UpdateAnimatorState();
        var closeToCellCenter = UpdateCell();

        if (!Snapping && closeToCellCenter && this.commitedToMovement)
        {
            this.commitedToMovement = false;

            if (this.scheduledStop)
            {
                this.scheduledStop = false;
                Stop();
                return;
            }
        }
        if (this.movingDirection.HasValue)
        {
            if (closeToCellCenter && IsBlockedTorwards(this.movingDirection))
            {
                Stop();
                this.MovementBlocked = true;
                return;
            }
            var vector = CharMovement.GetDirectionVector(this.movingDirection.Value);
            this.transform.position += vector * WalkSpeed * Time.deltaTime;
            var normalizedInt     = new Vector2Int(Mathf.RoundToInt(vector.x), Mathf.RoundToInt(vector.y));
            var nextCellPosition  = this.grid.GetCellPosition(this.cell + normalizedInt);
            var missingToNextCell = nextCellPosition - Position;
            if (missingToNextCell.magnitude / this.grid.cellSize < 1f - MOVEMENT_COMMITMENT_PERCENT)
            {
                this.commitedToMovement = true;
            }
        }
    }
Example #3
0
 void Awake()
 {
     this.srenderer     = GetComponentInChildren <SpriteRenderer>();
     this.grid          = GetComponentInParent <WalkingGrid>();
     this.movement      = GetComponent <CharMovement>();
     this.spriteActions = GetComponentInChildren <HunterSprite>();
 }
Example #4
0
 private void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.CompareTag("Clarice") || col.gameObject.CompareTag("Ariel"))
     {
         player = col.gameObject.GetComponent <CharMovement>();
     }
 }
Example #5
0
    private void MovePlayer()
    {
        m_Player = PlayerManager.Instance.GetPlayerInstance();
        if (m_Player == null)
        {
            Debuger.LogWarning("No Exist Player !");
            return;
        }
        List <CharMovement> movePath = new List <CharMovement>();

        foreach (var point in m_Config.LstSpeedMove)
        {
            //Vector3 point = target.Target.GetVector3();
            //movePath.Add(point);
            CharMovement move = new CharMovement();
            move.Target = point.Target.GetVector3();
            move.Speed  = (float)point.Speed;
            movePath.Add(move);
        }
        CharTransformData charData   = (CharTransformData)(m_Player.GetTransformData());
        GameObject        charObject = charData.GetGameObject();
        Rigidbody         body       = charObject.GetComponent <Rigidbody>();

        if (body)
        {
            m_bIsKinematic   = body.isKinematic;
            body.isKinematic = true;
        }
        m_Player.MovePath(movePath);
    }
Example #6
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("qualcosa e entrato");
        CharMovement player = collision.GetComponent <CharMovement>();

        player.healt--;
    }
Example #7
0
 private void MoveNpc()
 {
     if (m_lstTargetObjects == null || m_lstTargetObjects.Count <= 0)
     {
         Debuger.LogWarning("No Exist Npc !");
         return;
     }
     foreach (GameObject charObject in m_lstTargetObjects)
     {
         CharTransformContainer container = charObject.GetComponent <CharTransformContainer>();
         if (container == null)
         {
             Debuger.LogError("No Container in " + charObject.ToString());
             return;
         }
         m_Npc = (Npc)container.GetData();
         List <CharMovement> movePath = new List <CharMovement>();
         foreach (var point in m_Config.LstSpeedMove)
         {
             //Vector3 point = target.Target.GetVector3();
             //movePath.Add(point);
             CharMovement move = new CharMovement();
             move.Target = point.Target.GetVector3();
             move.Speed  = (float)point.Speed;
             movePath.Add(move);
         }
         Rigidbody body = charObject.GetComponent <Rigidbody>();
         if (body)
         {
             m_bIsKinematic   = body.isKinematic;
             body.isKinematic = true;
         }
         m_Npc.MovePath(movePath);
     }
 }
Example #8
0
    public void DeadUnit(CharMovement unit)
    {
        PlayerSide playerSide = unit.playerSide;

        string caption = captionsLibrary.GetCaption(CaptionsLibrary.CaptionsType.Death, playerSide);

        uiManager.CreateCaption(caption, unit.unitSpriteHandler.baseColor.transform);

        audioManager.PlaySoundEffect(audioLibrary.death[(int)playerSide]);

        switch (playerSide)
        {
        case PlayerSide.Cats:
            catObjects.Remove(unit);
            break;

        case PlayerSide.Dogs:
            dogObjects.Remove(unit);
            break;
        }

        Destroy(unit.hPBar.gameObject);
        unit.unitSpriteHandler.DeathAnimation(unit.gameObject);
        Destroy(unit);

        if (catObjects.Count <= 0 || dogObjects.Count <= 0)
        {
            EndGame();
        }
    }
    private int countUnitType(UnitTypes unitType, bool injured)
    {
        int totUnit = 0;

        GameObject[] teamMembersArray = GameObject.FindGameObjectsWithTag(gameObject.tag);
        foreach (GameObject teamMember in teamMembersArray)
        {
            CharMovement unit = teamMember.GetComponent <CharMovement>();
            if (unit.currentJob == unitType)
            {
                if (injured)
                {
                    if (unit.hp < 100)
                    {
                        totUnit++;
                    }
                }
                else
                {
                    totUnit++;
                }
            }
        }
        return(totUnit);
    }
Example #10
0
    public IEnumerator StartAI()
    {
        var jumpCell     = this.grid.ToClosestEdgeVector(this.child.Cell) * 2;
        var jumpOrigin2d = this.grid.GetCellPosition(jumpCell);
        var jumpOrigin3d = new Vector3(jumpOrigin2d.x, jumpOrigin2d.y, this.transform.position.z);

        this.child.TurnTo(jumpOrigin2d.x >= 0f ? CharMovement.Direction.LEFT : CharMovement.Direction.RIGHT);
        var jump = new JumpAnimation(this.child, from: jumpOrigin3d, to: Vector2.zero).Start();

        yield return(new WaitUntil(() => jump.HasFinished));

        while (true)
        {
            for (var i = 0; i < 3; i++)
            {
                var blocked   = this.grid.BlockedDirections(this.child.Cell);
                var direction = CharMovement.RandomDirection(except: blocked);
                var steps     = this.child.Steps;
                this.child.Move(direction);
                yield return(new WaitWhile(() => steps == this.child.Steps && !this.child.MovementBlocked));
            }
            this.child.Stop();

            for (var i = 0; i < 3; i++)
            {
                yield return(new WaitForSeconds(1f));

                this.child.TurnTo(CharMovement.RandomDirection(except: child.HeadedDirection));
            }
        }
    }
Example #11
0
 private void OnTriggerExit2D(Collider2D col)
 {
     if (col.gameObject.CompareTag("Clarice") || col.gameObject.CompareTag("Ariel"))
     {
         player = null;
     }
 }
Example #12
0
    public void SaveStatus()
    {
        if (door1.GetIsLocked())
        {
            door1Status = 1;
        }
        else
        {
            door1Status = 0;
        }

        if (door2.GetIsLocked())
        {
            door2Status = 1;
        }
        else
        {
            door2Status = 0;
        }

        PlayerPrefs.SetInt("door1", door1Status);
        PlayerPrefs.SetInt("door2", door2Status);

        player = gc.GetActiveCharGO();
        PlayerPrefs.SetFloat("PlayerX", player.transform.position.x);
        PlayerPrefs.SetFloat("PlayerY", player.transform.position.y);
    }
Example #13
0
    public ISet <CharMovement.Direction> BlockedDirections(Vector2Int cell)
    {
        var blocked = CharMovement.DIRECTIONS.Where(
            direction => IsBlocked(cell + CharMovement.GetDirectionVector2D(direction)));

        return(new HashSet <CharMovement.Direction>(blocked));
    }
Example #14
0
    // Start is called before the first frame update
    void Start()
    {
        charMovement = GetComponent <CharMovement>();

        camSwitchTime   = 0.35f;
        LockOnWasActive = false;
    }
Example #15
0
    public void HealerUnit(CharMovement unit)
    {
        PlayerSide playerSide = unit.playerSide;
        string     caption    = captionsLibrary.GetCaption(CaptionsLibrary.CaptionsType.Healer, playerSide);
        AudioClip  clip       = audioLibrary.RandomCaption(playerSide);

        audioManager.PlayVoiceLine(clip);
        uiManager.CreateCaption(caption, unit.unitSpriteHandler.baseColor.transform);
    }
Example #16
0
 public void SetupHero(int pNumber, Color color)
 {
     this.pNumber = pNumber;
     charAnimator = GetComponent <Animator>();
     charMovement = GetComponent <CharacterMovement>();
     CharMovement.SetupCharacterMovement(pNumber, charAnimator);
     transform.Find("playerRing").GetComponent <MeshRenderer>().material.color = color;
     uiManager.SetupCanvas(pNumber - 1, characterImage, abilityImages);
 }
Example #17
0
 private void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.CompareTag("Clarice") || col.gameObject.CompareTag("Ariel"))
     {
         playerTouching = true;
         playerT        = col.gameObject.transform;
         player         = col.gameObject.GetComponent <CharMovement>();
     }
 }
Example #18
0
 void Awake()
 {
     this.movement           = GetComponent <CharMovement>();
     this.movement.WalkSpeed = 4f;
     this.Scent              = GetComponent <ObjectScent>();
     this.witchSprite        = GetComponentInChildren <WitchSprite>();
     this.animator           = GetComponentInChildren <Animator>();
     this.originalController = animator.runtimeAnimatorController;
 }
Example #19
0
    public PremadeAnimation RunKnockback(CharMovement.Direction charDirection)
    {
        var forward   = CharMovement.GetDirectionVector(charDirection);
        var backwards = new Vector3(-forward.x, -forward.y, -forward.z);

        return(new AnimationChain(this, new List <PremadeAnimation> {
            new TranslateAnimation(this, backwards * DISTANCE, duration: DURATION / 2f),
            new TranslateAnimation(this, forward * DISTANCE, duration: DURATION / 2f)
        }).Start());
    }
Example #20
0
    void Start()
    {
        movementScript = CharMover.GetComponent <CharMovement>();
        anim           = pc.GetComponent <Animator> ();
        textComp       = display.GetComponent <Text>();
        textComp.text  = "";
        anim_speech    = speech.GetComponent <Animator> ();

        GenerateNewQuest();
    }
Example #21
0
 void Awake()
 {
     this.bang           = GetComponentInChildren <HunterBang>();
     this.grid           = GetComponentInParent <WalkingGrid>();
     this.witchScent     = this.grid.Witches[0].Scent;
     this.cauldronScent  = this.grid.Cauldron.Scent;
     this.hunter         = GetComponent <HunterActions>();
     this.hunterMovement = GetComponent <CharMovement>();
     this.hunterSprite   = GetComponentInChildren <HunterSprite>();
 }
Example #22
0
        private void SocialTask(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (!CharMovement.CanMove() || IsAttacking())
            {
                return;
            }

            CharMovement.MoveTo(RandomThreadSafe.Instance.Next(SpawnX - 90, SpawnX + 90), RandomThreadSafe.Instance.Next(SpawnY - 90, SpawnY + 90), Z);

            // broadcastPacket(new SocialAction(ObjID, rnd.Next(8)));
        }
Example #23
0
    public float BetterTPTime = 5f;         // How long BT will last

    public override void PickUpMe(GameObject byObject)
    {
        CharMovement OtherCM = byObject.GetComponent <CharMovement>();

        if (OtherCM != null)
        {
            OtherCM.MakeBetterTP(BetterTPTime);
            GameManager.Instance.IncreaseGamePoints(PointsOnTake);
            Destroy(gameObject);
        }
    }
Example #24
0
 private void Awake()
 {
     charMovement      = GetComponent <CharMovement>();
     meleeCombat       = GetComponent <MeleeCombat>();
     rangedCombat      = GetComponent <RangedCombat>();
     rangedCombatGhost = GetComponent <RangedCombatGhost>();
     aimWeapon         = GetComponent <AimWeapon>();
     throwWeapon       = GetComponent <ThrowWeapon>();
     playerCollider    = GetComponent <CapsuleCollider>();
     anim = GetComponent <Animator>();
 }
Example #25
0
    void Update()
    {
        if (this.grid == null)
        {
            return;
        }
        this.transform.position += CharMovement.GetDirectionVector(direction) * SPEED * Time.deltaTime;
        var p    = this.transform.position;
        var cell = this.grid.GetCellToSnap(this.transform.position);

        this.transform.position = new Vector3(p.x, p.y, 100 + cell.y);
    }
Example #26
0
 private void OnTriggerEnter2D(Collider2D col)
 {
     if ((col.gameObject.CompareTag("Clarice") || col.gameObject.CompareTag("Ariel")) && interruptor.GetAcesa() == false)
     {
         followPlayer = true;
         playerGO     = col.gameObject;
         player       = col.gameObject.GetComponent <CharMovement>();
         if (firstFollow)
         {
             iniciaVoaSom.Invoke();
             firstFollow = false;
         }
     }
 }
Example #27
0
 // Start is called before the first frame update
 void Start()
 {
     isAi = gameObject.transform.GetChild(7).gameObject.activeSelf;
     if (isAi)
     {
         Debug.Log("I am AI");
         enemyAttack = gameObject.GetComponent <CAttack>();
         player      = GameObject.FindGameObjectWithTag("Player");
         rb          = gameObject.GetComponent <Rigidbody2D>();
         cmove       = gameObject.GetComponent <CharMovement>();
         chooseWalk();
         jump();
         crouch();
     }
 }
Example #28
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }

        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
        charMovement = FindObjectOfType <CharMovement>();
        sentences    = new Queue <string>();
    }
Example #29
0
 private void Start()
 {
     pc = GameObject.FindGameObjectWithTag(gameObject.tag).GetComponent <CharMovement>();
     if (!pc.facingRight)
     {
         speed *= -1;
     }
     Invoke("DestroyProjectile", lifeTime);
     //Create a calaculate target class to be used here and in AttackCollision.
     if (gameObject.tag == "Player")
     {
         targetTag = "Enemy";
     }
     else if (gameObject.tag == "Enemy")
     {
         targetTag = "Player";
     }
     //Get the damage value of the attack
     damage = GameObject.FindGameObjectWithTag(gameObject.tag).GetComponent <CAttack>().damageArray[damagePosition];
 }
Example #30
0
    public void SpawnUnit(PlayerSide playerSide, int spawnSeq, bool sound = true)
    {
        GameObject[] target = GameObject.FindGameObjectsWithTag("CatPatrol");
        //int xOffset = 1;
        if (((int)playerSide) > 0)
        {
            //xOffset = -1;
            target = GameObject.FindGameObjectsWithTag("DogPatrol");
        }
        //Vector3 charPosition = new Vector3(headquarters[(int)playerSide].transform.position.x + xOffset * 1.3f, headquarters[(int)playerSide].transform.position.y, headquarters[(int)playerSide].transform.position.z + 2.2f -  spawnSeq*1.2f);
        Vector3    charPosition = new Vector3(target[spawnSeq].transform.position.x, target[spawnSeq].transform.position.y, target[spawnSeq].transform.position.z);
        Quaternion charRotation = new Quaternion(0, 0, 0, 0);
        //Instantiate(unitPrefabs[(int)playerSide], unitList);
        Transform unit = Instantiate(unitPrefabs[(int)playerSide], charPosition, charRotation, unitList).transform;

        CharMovement charMovement = unit.GetComponent <CharMovement>();

        charMovement.gameManager = this;

        charMovement.uiManager = uiManager;
        switch (playerSide)
        {
        case PlayerSide.Cats:
            catObjects.Add(charMovement);
            break;

        case PlayerSide.Dogs:
            dogObjects.Add(charMovement);
            break;
        }

        HPBarHandler handler = Instantiate(HPBar, HPBarCanvases.transform).GetComponent <HPBarHandler>();

        handler.Init(unit, cam);
        charMovement.hPBar = handler;

        if (sound)
        {
            audioManager.PlaySoundEffect(audioLibrary.spawned[(int)playerSide]);
        }
    }
Example #31
0
 // Use this for initialization
 void Awake()
 {
     Application.targetFrameRate = 60;
     col = new Collision2D();
     Instance = this;
 }
Example #32
0
    void Start()
    {
        movementScript = CharMover.GetComponent<CharMovement>();
        anim = pc.GetComponent<Animator> ();
        textComp = display.GetComponent<Text>();
        textComp.text = "";
        anim_speech = speech.GetComponent<Animator> ();

        GenerateNewQuest();
    }
 /// <summary>
 /// Start this instance.
 /// </summary>
 void Start()
 {
     instance = this;
     charController = character.GetComponent<CharMovement>();
 }