コード例 #1
0
    public void PlayMyTurn()
    {
        //Time up, bye bye :( But let a gift ;)
        if (m_LeftLifetime <= 0)
        {
            Explode();
            Destroy(gameObject);
            return;
        }

        //Still here ? So analyse next cell
        Vector2 deplacement = ONEGeneral.DirectionToVec2(m_Direction);
        Vector2 destination = new Vector2(Mathf.RoundToInt(m_destination.x + deplacement.x), Mathf.RoundToInt(m_destination.y + deplacement.y));

        int column = (int)destination.x;
        int row    = (int)destination.y;

        if (ONEMap.Instance.isOnMapCoordinates(row, column))
        {
            List <GameObject> nextCellObjectList = ONEMap.Instance.getObjectAt(row, column);
            foreach (GameObject nextCellObject in nextCellObjectList)
            {
                if (nextCellObject.GetComponent <ONEPlayer>()) // Player
                {
                    CollisionWithPlayer();
                    return;
                }
                else if (nextCellObject.CompareTag("Obstacle")) // Obstacle
                {
                    Explode();
                    Destroy(gameObject);
                    return;
                }
                if (nextCellObject.GetComponent <Enemy>() && m_isFromPlayer) // Enemy
                {
                    nextCellObject.GetComponent <Enemy>().Hit(1);
                    Destroy(gameObject);
                    return;
                }
            }
            m_destination = destination;
            m_LeftLifetime--;
        }
        else
        {
            Explode();
            Destroy(gameObject);
            return;
        }

        float delta           = (float)m_LeftLifetime / m_TotalLifetime;
        var   calculatedColor = Color.Lerp(m_initialColor, m_almostDeadColor, 1 - delta);

        calculatedColor.a = 1;
        GetComponent <SpriteRenderer>().color = calculatedColor;
    }
コード例 #2
0
ファイル: Enemy.cs プロジェクト: ChristopheClaustre/LD41
    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;
            }
        }
    }
コード例 #3
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();
    }
コード例 #4
0
ファイル: ONEGeneral.cs プロジェクト: ChristopheClaustre/LD41
    /***************************************************/
    /***  METHODS               ************************/
    /***************************************************/

    /********  UNITY MESSAGES   ************************/

    // Use this for initialization
    private void Start()
    {
        m_instance = this;
    }