コード例 #1
0
ファイル: PlantBase.cs プロジェクト: facybenbook/TrailPlant
 public void Init(PlantBase parent)
 {
     if (parent != null)
     {
         parent.m_children.Add(this);
     }
 }
コード例 #2
0
ファイル: Plant.cs プロジェクト: u-ndefined/Perma3000
 public Plant(PlantBase _plantBase)
 {
     plantBase = _plantBase;
     type      = plantBase.type;
     inputs    = plantBase.ArrayToDictionary(plantBase.editorInputs);
     outputs   = plantBase.ArrayToDictionary(plantBase.editorOutputs);
     HP        = plantBase.HP;
 }
コード例 #3
0
 private void PutPlantDown()
 {
     if (GameFlow.Instance.GridManager.InteractableTilemap.CanPlacePlant(m_CurrentTilePos))
     {
         m_HeldPlant.PlacePlant(m_CurrentTilePos);
         m_HeldPlant = null;
     }
 }
コード例 #4
0
    public void SetPlantInfo(sPlantData info, PlantBase plantBase)
    {
        m_PlantInfo = info;

        m_StartAttackTime = 5f / m_PlantInfo.attackSpeed;
        m_AttackTimer     = m_StartAttackTime;
        GetComponent <CircleCollider2D>().radius = m_PlantInfo.attackRange;

        m_PlantBase = plantBase;
    }
コード例 #5
0
    void SpawnGarlic(Vector2 pos)
    {
        WorldTile  cell  = world [(int)pos.x, (int)pos.y];
        GameObject obj   = Instantiate(garlicPrefab, new Vector3(cell.x, 0, cell.y), Quaternion.identity);
        PlantBase  plant = obj.GetComponent <PlantBase> ();

        plant.gridPos = new Vector2(cell.x, cell.y);
        // set potato in world
        world [cell.x, cell.y].plant = plant;
    }
コード例 #6
0
 public void PickUpPlant(PlantBase plant)
 {
     if (plant.CellXY.HasValue)
     {
         GameFlow.Instance.GridManager.InteractableTilemap.RemoveInteractableObject(plant);
     }
     m_HeldPlant                   = plant;
     plant.transform.parent        = m_HoldAnchor;
     plant.transform.localPosition = Vector3.zero;
 }
コード例 #7
0
    public void CraftPlant()
    {
        if (!AreSlotsEmpty())
        {
            PlantBase plant = ((GameObject)Instantiate(Resources.Load(GameConstants.BASE_PLANT_PREFAB_PATH))).GetComponent <PlantBase>();
            plant.Initialize(m_FlowerSlot.EnergyType.Value, m_StemSlot.EnergyType.Value, m_RootSlot.EnergyType.Value);

            ClearSlots();
            GameFlow.Instance.HideCraftingMenu();
        }
    }
コード例 #8
0
 protected virtual void PlantSeed(System.Type pb)
 {
     if (pb == typeof(PlantBase))
     {
         GameObject go    = gameObject.CreateChildren();
         PlantBase  plant = (PlantBase)go.AddComponent(pb);
         plant.Seed();
     }
     else
     {
         Debug.LogError("A non plant base type was sent.");
     }
 }
コード例 #9
0
 protected override void OnTriggerStay(Collider other)
 {
     if (!constructionHasBegun && buildingSpaceIsFree == false)
     {
         PlantBase plantBase = other.GetComponent <PlantBase>();
         if (plantBase && plantBase.spaceAvailable)
         {
             buildingSpaceIsFree = true;
             if (creator)
             {
                 SetBuildingMaterial(creator.player.allowedMaterial);
             }
         }
     }
 }
コード例 #10
0
    protected override void ReawakenWO()
    {
        base.ReawakenWO();
        int layerMask = 1 << 23;

        Collider[] cols = Physics.OverlapBox(transform.position, new Vector3(.5f, .5f, .5f), transform.rotation, layerMask);
        foreach (Collider col in cols)
        {
            PlantBase pb = col.GetComponent <PlantBase>();
            if (pb)
            {
                pb.spaceAvailable = false;
            }
        }
    }
コード例 #11
0
    // protected override void OnTriggerStay(Collider other){

    // }

    protected override void OnTriggerExit(Collider other)
    {
        if (!constructionHasBegun && buildingSpaceIsFree == true)
        {
            PlantBase plantBase = other.GetComponent <PlantBase>();
            if (plantBase)
            {
                buildingSpaceIsFree = false;
                if (creator)
                {
                    SetBuildingMaterial(creator.player.notAllowedMaterial);
                }
            }
        }
    }
コード例 #12
0
    public void Init(PlantCreator.FlowerType type, Vector3 initDir, float size, PlantBase parent, float invRadius = 0, PlantCreator.FlowerType subType = PlantCreator.FlowerType.None)
    {
        base.Init(parent);

        m_FlowerType    = type;
        m_FlowerSubType = subType;

        m_size     = size;
        m_lifeTime = lifeTime.Rand;
        lifeTimer  = 0;
        m_speed    = speed.Rand;
        velocity   = initDir.normalized * m_speed;
        if (invRadius != 0)
        {
            m_InvRadius = invRadius;
        }
        else
        {
            m_InvRadius = 1f / ((Random.RandomRange(0, 1f) > 0.5f ? 1f : -1f) * initRadius.Rand);
        }

        m_height     = height * size;
        oriInvRadius = temInvRadius = m_InvRadius;

        //radiusSpeed = -temInvRadius * RadiusSpeed.Rand;
        maxRadOffset = Random.RandomRange(4f, 7f) * m_size;
        m_state      = State.Grow;

        trail.height      = m_height;
        trail.width       = intervel;
        trail.vertexColor = PlantCreator.Instance.greenColor;

        int splitTime = (int)stemNumber.Rand;

        for (int i = 0; i < splitTime; ++i)
        {
            splitList.Add(Random.RandomRange(0.4f, 1.2f));
            splitList.Sort();
        }

        int dotTime = (int)seedNumber.Rand;

        for (int i = 0; i < dotTime; ++i)
        {
            dotList.Add(Random.RandomRange(0.2f, 1.2f));
            dotList.Sort();
        }
    }
コード例 #13
0
    void FloodFillOnion(Vector2 pos, int amount, float radius)
    {
        LinkedList <WorldTile> cells = GetEmptyCropCellsFloodFill((int)pos.x, (int)pos.y, radius, amount);

        while (cells.Count > 0)
        {
            // get each cell
            WorldTile cell = cells.First.Value;
            cells.RemoveFirst();
            // make onion
            GameObject obj   = Instantiate(onionPrefab, new Vector3(cell.x, 0, cell.y), Quaternion.identity);
            PlantBase  plant = obj.GetComponent <PlantBase> ();
            plant.gridPos = new Vector2(cell.x, cell.y);
            // set plant
            world [cell.x, cell.y].plant = plant;
        }
    }
コード例 #14
0
    public void KillPlant(PlantBase plant, bool predation = false)
    {
        if (plant == null || plant.gameObject == null)
        {
            return;
        }

        if (m_PlantMap.ContainsKey(plant.Type))
        {
            m_PlantMap[plant.Type].Remove(plant);
        }

        if (predation && OnPredationEvent != null)
        {
            OnPredationEvent(plant);
        }

        NetworkServer.Destroy(plant.gameObject);
    }
コード例 #15
0
    void SpawnPlantAtTile(WorldTile t, PlantType typ)
    {
        GameObject prefab = cornPrefab;

        switch (typ)
        {
        case PlantType.corn:
            prefab = cornPrefab;
            break;

        case PlantType.potato:
            prefab = potatoPrefab;
            break;
        }
        GameObject newPlant    = Instantiate(prefab, new Vector3(t.x, 0, t.y), Quaternion.identity);
        PlantBase  plantScript = newPlant.GetComponent <PlantBase> ();

        plantScript.gridPos = new Vector2(t.x, t.y);
        t.plant             = plantScript;
    }
コード例 #16
0
        public override void DoIt(double deltaTime)
        {
            // déplacement
            posX += speedX;

            // gestion de l'animation
            num_aff++;

            PlantBase foundPlant = Global.LE.FindAll(x => x is PlantBase).Find(plant => posX <= plant.posX + plant.HitBox.Width &&
                                                                               posX + HitBox.Width >= plant.posX && CorrectedY <= plant.CorrectedY + plant.HitBox.Height &&
                                                                               CorrectedY + HitBox.Height >= plant.CorrectedY) as PlantBase;

            if (foundPlant != null)
            {
                previousSpeed  = speedX;
                speedX         = 0;
                foundPlant.HP -= 2;
            }
            else
            {
                speedX = previousSpeed;
            }
        }
コード例 #17
0
    /// <summary>
    /// Gets the neighbours for a position.
    /// </summary>
    /// <returns>A length 4 array of neighbours, they can be null</returns>
    /// <param name="pos">Position.</param>
    public static PlantBase[] Get8NeighboursForPosition(Vector2 pos)
    {
        PlantBase[] neighbours = new PlantBase[directions8.Length];

        int     x, y;
        Vector2 newPos;

        for (int i = 0; i < directions8.Length; i++)
        {
            newPos = pos + directions8 [i];
            x      = (int)newPos.x;
            y      = (int)newPos.y;
            if (IsValidWorldPos(x, y) && singleton.world [x, y].hasPlant)
            {
                neighbours [i] = singleton.world [x, y].plant;
            }
            else
            {
                neighbours [i] = null;
            }
        }
        return(neighbours);
    }