Beispiel #1
0
    /********  OUR MESSAGES     ************************/

    /********  PUBLIC           ************************/

    public void Init(ONEGeneral.Direction p_Direction, int p_LeftLifetime, bool p_isFromPlayer)
    {
        m_destination = transform.localPosition;

        m_Direction    = p_Direction;
        m_isFromPlayer = p_isFromPlayer;

        m_LeftLifetime = p_LeftLifetime;
    }
Beispiel #2
0
    void Move(ONEGeneral.Direction p_direction)
    {
        Vector2 deplacement = ONEGeneral.DirectionToVec2(p_direction);
        Vector2 destination = new Vector2(Mathf.RoundToInt(m_destination.x + deplacement.x), Mathf.RoundToInt(m_destination.y + deplacement.y));

        List <GameObject> gos = ONEMap.Instance.getObjectAt((int)destination.y, (int)destination.x);

        if (gos != null)
        {
            bool blocked = false;

            foreach (GameObject go in gos)
            {
                if (go != null)
                {
                    Enemy     enemy  = go.GetComponent <Enemy>();
                    ONEPlayer player = go.GetComponent <ONEPlayer>();

                    // Obstacle
                    if (go.CompareTag("Obstacle"))
                    {
                        blocked = true;
                    }

                    // Player
                    else if (player != null)
                    {
                        player.Hit(1);
                        blocked = true;
                    }

                    // Enemy
                    else if (enemy != null)
                    {
                        blocked = true;
                    }
                }
            }

            // move if not blocked
            if (!blocked)
            {
                m_destination = destination;
            }
        }
    }
Beispiel #3
0
    void Shoot(ONEGeneral.Direction p_direction, GameObject p_projectileSpawn)
    {
        if (p_projectileSpawn == null)
        {
            return;
        }

        GameObject created = Instantiate(p_projectileSpawn, transform.parent);

        created.transform.localPosition = m_destination;
        ProjectileSpawn script = created.GetComponent <ProjectileSpawn>();

        Debug.Assert(script != null);
        script.Direction = p_direction;
        script.PlayMyTurn();

        ONESoundDesign.EnemyShoot();
    }
Beispiel #4
0
    /********  OUR MESSAGES     ************************/

    /********  PUBLIC           ************************/

    public void PlayMyTurn()
    {
        //Creat projectile
        foreach (GeneretedProjectile newProjectileGenereted in m_ProjectilesSpawnList)
        {
            GameObject projectileGO = Instantiate(newProjectileGenereted.m_Projectile, transform.parent);

            projectileGO.transform.localPosition = transform.localPosition;
            ONEMap.Instance.addToMap(projectileGO);

            Projectile projectileScript = projectileGO.GetComponent <Projectile>();

            ONEGeneral.Direction direction = ComputeDirection(newProjectileGenereted, m_direction);
            projectileScript.Init(direction, m_isFromPlayer);
            //Play one turn to place projectile
            projectileScript.PlayMyTurn();
        }
        Destroy(gameObject);
    }
Beispiel #5
0
        public void Shoot(Transform p_parent, Vector3 p_position, ONEGeneral.Direction p_direction)
        {
            if (m_projectileSpawn == null || m_currentCooldown != 0)
            {
                Debug.Log("Can't shoot"); return;
            }

            GameObject created = Instantiate(m_projectileSpawn, p_parent);

            created.transform.localPosition = p_position;
            ProjectileSpawn script = created.GetComponent <ProjectileSpawn>();

            script.IsFromPlayer = true;
            script.Direction    = p_direction;
            Debug.Assert(script != null);

            m_currentCooldown = m_cooldown + 1;

            ONESoundDesign.PlayerShoot();
        }
Beispiel #6
0
    protected int DirectionToOrientation(ONEGeneral.Direction p_Direction)
    {
        switch (p_Direction)
        {
        case ONEGeneral.Direction.eEE: return(0);

        case ONEGeneral.Direction.eSE: return(1);

        case ONEGeneral.Direction.eSS: return(2);

        case ONEGeneral.Direction.eSW: return(3);

        case ONEGeneral.Direction.eWW: return(4);

        case ONEGeneral.Direction.eNW: return(5);

        case ONEGeneral.Direction.eNN: return(6);

        case ONEGeneral.Direction.eNE: return(7);
        }
        return(0);
    }
Beispiel #7
0
    public void Move(ONEGeneral.Direction p_movement)
    {
        m_direction = p_movement;

        Vector2 deplacement = ONEGeneral.DirectionToVec2(p_movement);
        Vector2 destination = new Vector2(Mathf.RoundToInt(m_destination.x + deplacement.x), Mathf.RoundToInt(m_destination.y + deplacement.y));

        List <GameObject> gos = ONEMap.Instance.getObjectAt((int)destination.y, (int)destination.x);

        if (gos != null && destination.x >= m_columnLimit)
        {
            bool blocked = false;

            foreach (GameObject go in gos)
            {
                if (go != null)
                {
                    Enemy      enemy      = go.GetComponent <Enemy>();
                    Weapon     weapon     = go.GetComponent <Weapon>();
                    Projectile projectile = go.GetComponent <Projectile>();

                    // Obstacle
                    if (go.CompareTag("Obstacle"))
                    {
                        blocked = true;
                    }

                    // Enemy
                    else if (enemy != null)
                    {
                        enemy.Hit(1);
                        blocked = true;
                    }

                    // Weapon
                    else if (weapon != null)
                    {
                        TakeWeapon(weapon.WeaponInSlot);
                        Destroy(go);
                    }

                    // Projectile
                    else if (projectile != null && ONEGeneral.OppositeDirection(projectile.Direction, m_direction))
                    {
                        projectile.CollisionWithPlayer();
                    }
                }
            }

            // move if not blocked
            if (!blocked)
            {
                m_destination = destination;
            }
        }

        m_progression = System.Math.Max(m_progression, Mathf.RoundToInt(m_destination.x));
        m_columnLimit = System.Math.Min(m_progression - m_offset, ONEMap.Instance.NbColumn + 1 - m_visibility);

        WeaponsCooldown();
    }
Beispiel #8
0
 public void Init(ONEGeneral.Direction p_Direction, bool p_isFromPlayer)
 {
     Init(p_Direction, m_TotalLifetime, p_isFromPlayer);
 }
Beispiel #9
0
    /********  PROTECTED        ************************/
    protected ONEGeneral.Direction ComputeDirection(GeneretedProjectile newProjectileGenereted, ONEGeneral.Direction p_Direction)
    {
        int orientation = (DirectionToOrientation(newProjectileGenereted.m_Direction) + DirectionToOrientation(p_Direction)) % 8;

        return(DirectionFromOrientation(orientation));
    }