Example #1
0
        public void AddStage(int stg_indx, PlantStage ps)
        {
            stages.Add(stg_indx, ps);
            GameObject stage_obj = new GameObject("Stage" + stg_indx);

            stage_obj.transform.parent = this.transform;
            foreach (GameObject o in ps.objs)
            {
                o.transform.parent = stage_obj.transform;
            }
        }
Example #2
0
        public void Spawn(int i, int j, int x, int y, int stage_index)
        {
            // get PlantObj Clone from ObjPool
            GameObject obj = ObjPool.Get(gameObject.name);

            // if a Clone is found, activate correct Stage and Type and set the correct Transform
            if (obj)
            {
                obj.transform.position = new Vector3(x + 0.5f, y + 0.5f, TilemapManager.map[i, j].tile_height);
                obj.SetActive(true);
                PlantObj plant_obj = obj.GetComponent <PlantObj>();

                // set shake/bounce data
                PlantStage plant_stage = stages[stage_index];
                plant_obj.can_shake     = plant_stage.can_shake;
                plant_obj.rotate_around = plant_stage.rotate_around;
                plant_obj.shake_delta   = plant_stage.shake_delta;
                plant_obj.shake_freq    = plant_stage.shake_freq;
                plant_obj.can_bounce    = plant_stage.can_bounce;
                plant_obj.bounce_delta  = plant_stage.bounce_delta;

                // deactivate inactive stages for newly spawned plant_obj
                int k = 0;
                foreach (Transform t in plant_obj.transform)
                {
                    if (k != stage_index)
                    {
                        t.gameObject.SetActive(false);
                    }
                    k++;
                }

                // deactivate all variations in chosen plant stage
                if (!stages[stage_index].is_stack)
                {
                    foreach (Transform t in plant_obj.transform.GetChild(stage_index))
                    {
                        // do not deactivate the physics_obj
                        if (t.gameObject.name != "Physics_Obj")
                        {
                            t.gameObject.SetActive(false);
                        }
                    }

                    // choose the variation to activate
                    List <float> w_range = new List <float>();
                    for (int t = 0; t < stages[stage_index].types; ++t)
                    {
                        w_range.Add(t);
                        w_range.Add(t);
                        w_range.Add(stages[stage_index].sprite_probs[t] * 100);
                    }
                    int type_index = (int)Utils.weightedRange(w_range.ToArray());
                    // set stage_obj
                    plant_obj.stage_obj = plant_obj.transform.GetChild(stage_index).gameObject;
                    // type_obj =
                    plant_obj.stage_obj.transform.GetChild(type_index).gameObject.SetActive(true);
                }
                else
                {
                    plant_obj.stage_obj = plant_obj.transform.GetChild(stage_index).gameObject;
                }
            }
        }
Example #3
0
        public static void initPlantTypes()
        {
            // "grasslands":
            // "pebble_tile", "tall_grass", "grass", "grass_tile", "flower",
            // "flower_tile", "mushroom", "mushroom_tile"

            // "pebble_tile"
            GameObject obj   = new GameObject();
            PlantObj   debri = initPlant("pebble_tile", obj);

            debri.spawn_order = 0;
            // Stage 0
            PlantStage ps = new PlantStage(1, 1, 6, new int[] { 4, 5, 23, 24, 25, 43 }, new float[] { 0.167f, 0.167f, 0.167f, 0.167f, 0.167f, 0.167f }, true);

            // first three are random, fourth follows tall_grass placement
            ps.initNoise(new int[] { 0, 100, 200, 0 }, new float[] { 1.0f, 1.0f, 1.0f, 1.0f }, new float[] { 0.0f, 0.8f, 0.6f, 0.6f }, new float[] { 0.001f, 0.5f, 0.2f, 0.5f });
            debri.AddStage(0, ps);
            // Obj Pool
            ObjPool.Add(obj, 100);

            // "tall_grass"
            obj = new GameObject();
            PlantObj tallgrass = initPlant("tall_grass", obj);

            tallgrass.spawn_order = 1;
            // Stage 0
            ps = new PlantStage(1, 1, 2, new int[] { 46, 47 }, new float[] { 0.5f, 0.5f });
            ps.initNoise(new int[] { 0 }, new float[] { 1.0f }, new float[] { 0.65f }, new float[] { 0.8f });
            ps.initBoxCollider(true, Vector3.zero, Vector3.one);
            ps.initShake();
            tallgrass.AddStage(0, ps);
            // Stage 2
            ps = new PlantStage(1, 2, 2, new int[] { 68, 69 }, new float[] { 0.5f, 0.5f }, false, false, true);
            ps.initNoise(new int[] { 25 }, new float[] { 0.3f }, new float[] { 0.78f }, new float[] { 0.9f });
            ps.initBoxCollider(true, Vector3.zero, Vector3.one);
            ps.initShake(0.5f);
            tallgrass.AddStage(1, ps);
            // ObjPool
            ObjPool.Add(obj, 500);

            // "grass"

            // "grass_tile"

            // "flower"
            obj = new GameObject();
            PlantObj flower = initPlant("flower", obj);

            flower.XY_neighbors = false;
            flower.spawn_order  = 1;
            // Stage 0
            ps = new PlantStage(1, 1, 1, new int[] { 6 }, new float[] { 1.0f }, true);
            ps.initNoise(new int[] { 560 }, new float[] { 3.0f }, new float[] { 0.85f }, new float[] { 0.05f });
            ps.initBoxCollider(true, new Vector3(-0.02f, -0.02f, 0f), new Vector3(0.4f, 0.45f, 0.1f));
            ps.initShake();
            flower.AddStage(0, ps);
            // Stage 1
            ps = new PlantStage(1, 1, 1, new int[] { 10 }, new float[] { 1.0f });
            ps.initNoise(new int[] { 60 }, new float[] { 1.0f }, new float[] { 0.8f }, new float[] { 0.1f });
            ps.initBoxCollider(true, Vector3.zero, Vector3.one * 0.3f);
            ps.initShake();
            flower.AddStage(1, ps);
            // ObjPool
            ObjPool.Add(obj, 20);

            // "flower_tile"
            obj = new GameObject();
            PlantObj flower_tile = initPlant("flower_tile", obj);

            flower_tile.spawn_order  = 0;
            flower_tile.XY_neighbors = false;
            // Stage 0
            ps = new PlantStage(1, 1, 4, new int[] { 61, 62, 81, 82 }, new float[] { 0.25f, 0.25f, 0.25f, 0.25f }, true);
            ps.initNoise(new int[] { 560, 60 }, new float[] { 3.0f, 1.0f }, new float[] { 0.9f, 0.8f }, new float[] { 1.0f, 0.7f });
            flower_tile.AddStage(0, ps);
            // Obj Pool
            ObjPool.Add(obj, 50);

            // "mushroom"
            obj = new GameObject();
            PlantObj mushroom = initPlant("mushroom", obj);

            mushroom.XY_neighbors = false;
            mushroom.spawn_order  = 1;
            // Stage 0
            ps = new PlantStage(1, 1, 1, new int[] { 26 }, new float[] { 1.0f }, true);
            ps.initNoise(new int[] { 20 }, new float[] { 2.0f }, new float[] { 0.9f }, new float[] { 0.05f });
            ps.initCapsuleCollider(false, Vector3.zero, 2, 0.5f, 0.1f);
            ps.initCapsuleCollider(true, Vector3.zero, 2, 0.6f, 0.15f);
            ps.initShake();
            mushroom.AddStage(0, ps);
            // Stage 1
            ps = new PlantStage(1, 1, 2, new int[] { 27, 28 }, new float[] { 0.5f, 0.5f });
            ps.initNoise(new int[] { 10, 95 }, new float[] { 2.0f, 1.0f }, new float[] { 0.9f, 0.8f }, new float[] { 0.05f, 0.05f });
            ps.initCapsuleCollider(false, Vector3.zero, 2, 2f, 0.4f);
            ps.initCapsuleCollider(true, Vector3.zero, 2, 2f, 0.45f);
            ps.initShake(0.5f);
            ps.initBounce();
            mushroom.AddStage(1, ps);
            // Stage 2
            ps = new PlantStage(1, 2, 2, new int[] { 126, 127 }, new float[] { 0.5f, 0.5f }, false, false, true);
            ps.initNoise(new int[] { 32 }, new float[] { 2.0f }, new float[] { 0.9f }, new float[] { 0.05f });
            ps.initCapsuleCollider(false, Vector3.zero, 2, 2.5f, 0.4f);
            ps.initCapsuleCollider(true, Vector3.zero, 2, 2.5f, 0.45f);
            ps.initShake(0.5f);
            ps.initBounce();
            mushroom.AddStage(2, ps);
            // Stage 3
            ps = new PlantStage(2, 2, 1, new int[] { 128 }, new float[] { 0.5f }, false, false, true);
            // ps = new PlantStage(2, 2, 1, new int[] { 128, 129, 108, 109 }, new float[] { 0.5f });
            ps.initNoise(new int[] { 45 }, new float[] { 2.0f }, new float[] { 0.9f }, new float[] { 0.05f });
            ps.initCapsuleCollider(false, Vector3.zero, 2, 3f, 0.8f);
            ps.initCapsuleCollider(true, Vector3.zero, 2, 3f, 0.85f);
            ps.initShake(0.35f);
            ps.initBounce();
            mushroom.AddStage(3, ps);
            // Obj Pool
            ObjPool.Add(obj, 20);

            // "mushroom_tile"
            obj = new GameObject();
            PlantObj mushroom_tile = initPlant("mushroom_tile", obj);

            mushroom_tile.spawn_order  = 0;
            mushroom_tile.XY_neighbors = false;
            // Stage 0
            ps = new PlantStage(1, 1, 2, new int[] { 60, 80 }, new float[] { 0.5f, 0.5f }, true);
            ps.initNoise(new int[] { 20, 10, 95, 32, 45 }, new float[] { 2.0f, 2.0f, 1.0f, 2.0f, 2.0f },
                         new float[] { 0.87f, 0.87f, 0.77f, 0.87f, 0.87f }, new float[] { 0.2f, 0.2f, 0.2f, 0.2f, 0.2f });
            mushroom_tile.AddStage(0, ps);
            // Obj Pool
            ObjPool.Add(obj, 50);
        }