コード例 #1
0
    protected virtual void Plant(int plantNumber)
    {
        // Plant animation in that direction
        // Check if there is space in front to plant
        // If there is plant
        // Instatiate new plant object
        //  position it in the world

        // Else make failure animation

        // Start cooldown timer/reduce seed count
        // TODO: use more general form of detecting direction
        // Vector3 dirr = Globals.DirectionToVector(direction);
        // PlantGridObject newPlant = (PlantGridObject)Instantiate(plants[plantNumber], transform.position + dirr, Quaternion.identity);
        if (Globals.inventory[plantNumber] > 0 && plantCooldown <= 0)
        {
            canPlant = true;
            foreach (KeyValuePair <Globals.PlantData, int> plant in Globals.plants)
            {
                if (plant.Key.PlantScene == Application.loadedLevelName)
                {
                    if (Mathf.Abs(plant.Key.PlantLocation.x - this.gameObject.transform.position.x) < 0.5 &&
                        Mathf.Abs(plant.Key.PlantLocation.y - this.gameObject.transform.position.y) < 0.5)
                    {
                        canPlant = false;
                    }
                }
            }
            if (canPlant == true)
            {
                //planting code
                PlantGridObject newPlant = (PlantGridObject)Instantiate(plants[plantNumber], new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                if (plantNumber == 1)
                {
                    TurbinePlantObject turbinePlant = (TurbinePlantObject)newPlant;
                    turbinePlant.playSound();
                }
                newPlant.Rotate(direction);
                Globals.inventory[plantNumber]--;



                Globals.PlantData thisPlant = new Globals.PlantData(newPlant.transform.position, Application.loadedLevelName, newPlant.direction);
                Globals.plants.Add(thisPlant, plantNumber);

                canvas.UpdateUI();          //recheck if player can plant
                plantCooldown = plantDelay;
                canvas.UpdatePlantCooldown(plantCooldown <= 0);
            }
            else
            {
                audioSource.clip = invalidPlacement;
                audioSource.Play();
            }
        }
    }
コード例 #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.CompareTag("Player"))
        {
            moveList.Add(col.gameObject);
            PlayerGridObject player = col.GetComponent <PlayerGridObject>();
            player.platforms++;
            hasPlayer = true;
        }
        if (col.gameObject.CompareTag("Enemy") || col.gameObject.CompareTag("EnemySpawner"))
        {
            //there's a bug where the platform is stuck in the middle of lava if it hits a firemonster

            /*if (col.gameObject.GetComponent<GenericMonsterBehaviour>())
             * {
             *  return;
             * }*/
            KillableGridObject enemy = col.GetComponentInParent <KillableGridObject>();
            enemy.TakeDamage(damage);
        }
        if (!pingPong && col.gameObject.CompareTag("Turbine") && !col.gameObject.GetComponent <TurbinePlantObject>().onPlatform)
        {
            col.gameObject.GetComponent <TurbinePlantObject>().onPlatform = true; //makes sure turbine can only be on one platform
            if (!turbineMove)
            {
                if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.West)
                {
                    direction = Globals.Direction.East;
                }
                else if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.East)
                {
                    direction = Globals.Direction.West;
                }
                else if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.North)
                {
                    direction = Globals.Direction.South;
                }
                else if (col.gameObject.GetComponentInParent <TurbinePlantObject>().direction == Globals.Direction.South)
                {
                    direction = Globals.Direction.North;
                }
            }
            plant = col.gameObject.GetComponent <PlantGridObject>();

            moveList.Add(col.gameObject);
            hasTurbine  = true;
            turbineMove = true;
        }
    }
コード例 #3
0
    // Destroys this boat as well as the plant on it
    public void Destructor()
    {
        for (int i = 0; i < moveList.Count; i++)
        {
            if (moveList[i].CompareTag("Turbine") || moveList[i].CompareTag("Plant"))
            {
                PlantGridObject plant = moveList[i].GetComponent <PlantGridObject>();
                plant.TakeDamage(500);
            }
            if (moveList[i].CompareTag("Player"))
            {
                PlayerGridObject player = moveList[i].GetComponent <PlayerGridObject>();
                player.invincible = false;
            }
        }

        Destroy(this.gameObject);
    }
コード例 #4
0
    //start happens 1st frame
    void Start()
    {
        Globals.tileMap = this;
        rooms           = new GameObject[transform.GetChild(0).childCount];
        for (int i = 0; i < transform.GetChild(0).childCount; i++)
        {
            rooms[i] = transform.GetChild(0).GetChild(i).gameObject;
        }

        int     plantType;
        Vector3 plantVector;

        foreach (KeyValuePair <Globals.PlantData, int> kvp in Globals.plants)
        {
            if (kvp.Key.PlantScene == Application.loadedLevelName)
            {
                plantVector = kvp.Key.PlantLocation;
                plantType   = kvp.Value;
                PlantGridObject newPlant = (PlantGridObject)Instantiate(player.GetComponent <PlayerGridObject>().plants[plantType], plantVector, Quaternion.identity);
                newPlant.Rotate(kvp.Key.PlantDirection);
            }
        }

        // Get all Tiles that are children of this TileMap object
        Tile[] myTiles = GetComponentsInChildren <Tile>();

        // For each tile: get the tile's position with respect
        // to the tilemap's position.
        foreach (Tile tile in myTiles)
        {
            Vector3 tilePosition = tile.transform.position;

            // Tile's position with respect to the tilemap's position
            tilePosition -= this.transform.position;

            //Debug.Log(tilePosition);

            grid[(int)tilePosition.x, (int)tilePosition.y] = tile;

            //nodeGrid[(int)tilePosition.x, (int)tilePosition.y] = new Node(tile, this);
        }
    }
コード例 #5
0
    // Update is called once per frame
    protected override void Update()
    {
        base.Update();

        // TODO: pull up animator code for player up to here so monster can have their own
        // Get Left or Right
        horizontalAxis = Input.GetAxisRaw("Horizontal");
        // Get Up or Down
        verticalAxis = Input.GetAxisRaw("Vertical");

        // Up
        if (canMove)
        {
            if (!isAttacking && verticalAxis > 0)
            {
                Move(Globals.Direction.North);
                Move(Globals.Direction.North);

                // Double movespeed
                if (horizontalAxis == 0.0f)
                {
                    Move(Globals.Direction.North);
                }
            }
            // Down
            else if (!isAttacking && verticalAxis < 0)
            {
                Move(Globals.Direction.South);
                Move(Globals.Direction.South);

                if (horizontalAxis == 0.0f)
                {
                    Move(Globals.Direction.South);
                }
            }

            // Left
            if (!isAttacking && horizontalAxis < 0)
            {
                Move(Globals.Direction.West);
                Move(Globals.Direction.West);

                if (verticalAxis == 0.0f)
                {
                    Move(Globals.Direction.West);
                }
            }
            // Right
            else if (!isAttacking && horizontalAxis > 0)
            {
                Move(Globals.Direction.East);
                Move(Globals.Direction.East);

                if (verticalAxis == 0.0f)
                {
                    Move(Globals.Direction.East);
                }
            }

            if (!isAttacking && (horizontalAxis != 0.0f || verticalAxis != 0.0f))
            {
                animator.SetBool("IsWalking", true);
                animator.SetInteger("Direction", (int)direction);
            }
            else
            {
                animator.SetBool("IsWalking", false);
            }
        }

        if (!canvas.dialogue && Input.GetKeyDown(KeyCode.Space))
        {
            if (!isAttacking)
            {
                animator.SetTrigger("Attack");
                Attack();

                //knockBack logic
                foreach (KillableGridObject target in killList)
                {
                    MoveableGridObject moveable = target.GetComponent <MoveableGridObject>();
                    if (moveable && target.faction == Globals.Faction.Enemy)
                    {
                        if (!(moveable.gameObject.GetComponent <BombObject>()) && !(moveable.gameObject.GetComponent <RollingBoulder>()))
                        {
                            for (int i = 0; i < this.gameObject.GetComponent <PlayerGridObject>().knockBackPower; i++)
                            {
                                moveable.Move(this.gameObject.GetComponent <PlayerGridObject>().direction);
                            }
                        }
                    }
                }
            }
        }
        else if (!canvas.dialogue && Input.GetButtonDown("Deplant"))
        {
            switch (direction)
            {
            case Globals.Direction.South:
                killList = southHitCollider.GetKillList();
                break;

            case Globals.Direction.East:
                killList = eastHitCollider.GetKillList();
                break;

            case Globals.Direction.North:
                killList = northHitCollider.GetKillList();
                break;

            case Globals.Direction.West:
                killList = westHitCollider.GetKillList();
                break;
            }
            killList.RemoveAll((KillableGridObject target) => target == null);

            // Deal damage to all targets of the enemy faction
            foreach (KillableGridObject target in killList)
            {
                //deplant code MOVED so deplanting is a different button
                PlantGridObject plant = target.GetComponent <PlantGridObject>();
                if (plant)
                {
                    if (!plant.unharvestable)
                    {
                        plant.TakeDamage(100);
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < 10; ++i)
            {
                if (!canvas.dialogue && Input.GetKeyDown("" + i))
                {
                    Plant(i - 1);
                }
            }
        }

        if (plantCooldown > 0)
        {
            plantCooldown--;
            if (plantCooldown <= 0)
            {
                canvas.UpdatePlantCooldown(true);
            }
        }
    }