コード例 #1
0
    /// <summary>
    /// Fire Tower Action creates a go and sends it toward the highest priority target.
    /// Updates timer for next action. If no targets exist transitions tower to Idle
    /// </summary>
    protected override void Act()
    {
        base.Act();

        if (_targets.Count == 0)
        {
            return;
        }

        GameObject target = this.getTarget().gameObject;

        if (target == null)
        {
            return;
        }

        GameObject go = GameObject.Instantiate(ProjectilePrefab, gameObject.transform.position, Quaternion.identity) as GameObject;

        SlowProjectile slowPro = go.GetComponent <SlowProjectile>();

        slowPro.setTarget(target.transform);

        //slowPro.Duration = BaseDuration * _durationMultiplier;

        //Debug.Log("Act");

        if (OnSlowFired != null)
        {
            OnSlowFired();
        }
    }
コード例 #2
0
    protected override void ProjectileInit(GameObject proj, Alien target)
    {
        SlowProjectile data = proj.GetComponent <SlowProjectile>();

        data.Init(SlowTime, SlowRate, AreaOfEffect, target, Constants.bulletVelocity, Damage);
    }
コード例 #3
0
ファイル: Player.cs プロジェクト: ajayyy/TurnBasedAttacker
    void Update () {
        //uncomment below if you want to skip straight to the scoreboard. Make the number the number of players you have minus one

		//if (playerNum != 15)
		//	GetComponent<AnimationScript> ().OnDeadAnimationEnded();
		
        //shothand for GameController.instance
        GameController gameController = GameController.instance;

		if (gameController.gameOver) {
			//the game is done, the player should not be able to move
			return;
		}

        if(stunned && gameController.turnNum - 5 >= turnStunned) {
            stunned = false;
            gameController.usablePlayers[playerNum] = true;

            //setup fade animation
            Color stunColor = stunnedColor.GetComponent<SpriteRenderer>().color;
            stunnedColor.GetComponent<AnimationScript>().type = 5;
            stunnedColor.GetComponent<AnimationScript>().targetColor = new Color(stunColor.r, stunColor.g, stunColor.b, 0);
            stunnedColor.GetComponent<AnimationScript>().kill = true;

            stunnedColor.GetComponent<Animator>().SetTrigger("move");
        }

        //if it's this player's turn but it is animating
        if (gameController.turnPlayerNum == playerNum && Time.time - gameController.lastMove >= 0.01f && selected && !EverythingIdle() && !stunned) {
            //make the button disabled
            gameController.saveGameUsable = false;
        }

        //set this player as selected if it was clicked by the controlling player (LAN game)
        if (GameSettings.serverSocket != null && playerNum != 0 && !selected) {
            string message = GameSettings.connectedPlayers[playerNum - 1].GetMessage();
            bool correctMessage = message != null && message.Contains("selected: ");

            if (correctMessage) {
                int selectedPlayer = int.Parse(message.Split('{')[1].Split('}')[0]);

                if(selectedPlayer == gameController.players.IndexOf(gameObject)) {
                    GameSettings.connectedPlayers[playerNum - 1].RemoveMessage();

                    SelectPlayer();

                    GameSettings.SendToAllExcept(message, GameSettings.connectedPlayers[playerNum - 1]);
                }
            }
        }
        if (GameSettings.connectedServer != null && playerNum != GameSettings.currentPlayerNum && !selected) {
            string message = GameSettings.connectedServer.GetMessage();
            bool correctMessage = message != null && message.Contains("selected: ");

            if (correctMessage) {
                int selectedPlayer = int.Parse(message.Split('{')[1].Split('}')[0]);

                if (selectedPlayer == gameController.players.IndexOf(gameObject)) {
                    GameSettings.connectedServer.RemoveMessage();

                    SelectPlayer();
                }
            }
        }

        //if it is this player's turn
        if (gameController.turnPlayerNum == playerNum && Time.time - gameController.lastMove >= 0.01f && selected && EverythingIdle() && !stunned) {

            //make button enabled if we can play
            if(Time.time - gameController.lastMove <= 0.5f && !doneTurn) {
                gameController.saveGameUsable = true;
            }

            if (doneTurn) {
                gameController.NextTurn();

                ChangeColor(idleColor);

                doneTurn = false;
            } else if (shootMode) {
                ChangeColor(shootColor);

                bool chosen = false; //was a direction chosen
                float direction = 0; //the direction chosen in angles

                if (Right()) {
                    chosen = true;
                    direction = 0;
                } else if (Left()) {
                    chosen = true;
                    direction = 180;
                } else if (Up()) {
                    chosen = true;
                    direction = 90;
                } else if (Down()) {
                    chosen = true;
                    direction = 270;
                }

                if (Action()) {
                    //disable it, they activated it by mistake
                    shootMode = false;
                }

                if (chosen) {
                    //find other player
                    RaycastHit2D otherPlayer = Physics2D.Raycast(transform.position + MathHelper.DegreeToVector3(direction), MathHelper.DegreeToVector2(direction));

                    if (otherPlayer.collider != null && (otherPlayer.collider.tag == "Player" || otherPlayer.collider.tag == "Block")) {
                        projectile.GetComponent<AnimationScript>().direction = direction;
                        projectile.GetComponent<AnimationScript>().target = otherPlayer.collider.transform.position;
                        projectile.GetComponent<AnimationScript>().targetObject = otherPlayer.collider.gameObject;
                        projectile.transform.position = transform.position;
                        projectile.SetActive(true);

                        projectile.GetComponent<Animator>().SetTrigger("move");
                        doneTurn = true;
                        shootMode = false;
                        holding = false;
                    }

                }

            //not check if a pickup has been activated
            } else if (blockMode) {
                ChangeColor(shootColor);

                bool chosen = false; //was a direction chosen
                float direction = 0; //the direction chosen in angles

                if (Right()) {
                    chosen = true;
                    direction = 0;
                } else if (Left()) {
                    chosen = true;
                    direction = 180;
                } else if (Up()) {
                    chosen = true;
                    direction = 90;
                } else if (Down()) {
                    chosen = true;
                    direction = 270;
                }

                if (Action()) {
                    //disable it, they activated it by mistake
                    blockMode = false;
                }

                if (chosen) {
                    //find other player
                    RaycastHit2D otherPlayer = Physics2D.Raycast(transform.position + MathHelper.DegreeToVector3(direction), MathHelper.DegreeToVector2(direction));

                    GameObject newBlock = Instantiate(gameController.block);
                    newBlock.GetComponent<AnimationScript>().direction = direction;
                    newBlock.transform.position = transform.position;

                    gameController.blocks.Add(newBlock);

                    doneTurn = true;
                    blockMode = false;
                    holding = false;
                }

            } else if (spawnMode) {
                ChangeColor(shootColor);

                bool chosen = false; //was a direction chosen
                float direction = 0; //the direction chosen in angles

                if (Right()) {
                    chosen = true;
                    direction = 0;
                } else if (Left()) {
                    chosen = true;
                    direction = 180;
                } else if (Up()) {
                    chosen = true;
                    direction = 90;
                } else if (Down()) {
                    chosen = true;
                    direction = 270;
                }

                if (Action()) {
                    //disable it, they activated it by mistake
                    spawnMode = false;
                }

                if (chosen) {
                    //find other player
                    RaycastHit2D otherPlayer = Physics2D.Raycast(transform.position + MathHelper.DegreeToVector3(direction), MathHelper.DegreeToVector2(direction));
                    
                    GameObject newPlayer = Instantiate(gameController.player);
                    newPlayer.GetComponent<AnimationScript>().direction = direction;
                    newPlayer.transform.position = transform.position;

                    Player playerScript = newPlayer.GetComponent<Player>();
                    playerScript.playerNum = playerNum;
                    playerScript.idleColor = idleColor;
                    playerScript.highlightColor = highlightColor;
                    playerScript.shootColor = shootColor;
                    playerScript.selected = false;

                    playerScript.GetComponent<Animator>().SetTrigger("move");

                    gameController.players.Add(newPlayer);
                    GameController.instance.playerStatusList[playerScript.playerNum].GetComponentInChildren<Text>().text = int.Parse(GameController.instance.playerStatusList[playerScript.playerNum].GetComponentInChildren<Text>().text) + 1 + "";

                    doneTurn = true;
                    spawnMode = false;
                    holding = false;
                }

            } else if (slowShootMode) {
                ChangeColor(shootColor);

                bool chosen = false; //was a direction chosen
                float direction = 0; //the direction chosen in angles

                if (Right()) {
                    chosen = true;
                    direction = 0;
                } else if (Left()) {
                    chosen = true;
                    direction = 180;
                } else if (Up()) {
                    chosen = true;
                    direction = 90;
                } else if (Down()) {
                    chosen = true;
                    direction = 270;
                }

                if (Action()) {
                    //disable it, they activated it by mistake
                    slowShootMode = false;
                }

                if (chosen) {
                    //find other player

                    GameObject newProjectile = Instantiate(slowProjectile);

                    SlowProjectile slowProjectileScript = newProjectile.GetComponent<SlowProjectile>();

                    slowProjectileScript.direction = direction;
                    slowProjectileScript.lastTurnMoved = playerNum;
                    newProjectile.transform.position = transform.position;

                    gameController.slowProjectiles.Add(newProjectile);


                    doneTurn = true;
                    slowShootMode = false;
                    holding = false;

                }

            } else if (blockShootMode) {
                ChangeColor(shootColor);

                bool chosen = false; //was a direction chosen
                float direction = 0; //the direction chosen in angles

                if (Right()) {
                    chosen = true;
                    direction = 0;
                } else if (Left()) {
                    chosen = true;
                    direction = 180;
                } else if (Up()) {
                    chosen = true;
                    direction = 90;
                } else if (Down()) {
                    chosen = true;
                    direction = 270;
                }

                if (Action()) {
                    //disable it, they activated it by mistake
                    blockShootMode = false;
                }

                if (chosen) {
                    //find other player
                    RaycastHit2D otherPlayer = Physics2D.Raycast(transform.position + MathHelper.DegreeToVector3(direction), MathHelper.DegreeToVector2(direction));

                    if (otherPlayer.collider != null) {
                        gameController.blockProjectile.GetComponent<AnimationScript>().direction = direction;
                        gameController.blockProjectile.GetComponent<AnimationScript>().target = otherPlayer.collider.transform.position;
                        if(otherPlayer.collider.gameObject.tag == "Border") {
                            gameController.blockProjectile.GetComponent<AnimationScript>().target = otherPlayer.point;
                        }
                        gameController.blockProjectile.GetComponent<AnimationScript>().targetObject = otherPlayer.collider.gameObject;
                        gameController.blockProjectile.transform.position = transform.position;
                        gameController.blockProjectile.SetActive(true);

                        gameController.blockProjectile.GetComponent<Animator>().SetTrigger("move");
                        doneTurn = true;
                        blockShootMode = false;
                        holding = false;
                    }

                }

            } else if (stunShootMode) {
                ChangeColor(shootColor);

                bool chosen = false; //was a direction chosen
                float direction = 0; //the direction chosen in angles

                if (Right()) {
                    chosen = true;
                    direction = 0;
                } else if (Left()) {
                    chosen = true;
                    direction = 180;
                } else if (Up()) {
                    chosen = true;
                    direction = 90;
                } else if (Down()) {
                    chosen = true;
                    direction = 270;
                }

                if (Action()) {
                    //disable it, they activated it by mistake
                    stunShootMode = false;
                }

                if (chosen) {
                    //find other player
                    RaycastHit2D otherPlayer = Physics2D.Raycast(transform.position + MathHelper.DegreeToVector3(direction), MathHelper.DegreeToVector2(direction));

                    if (otherPlayer.collider != null && otherPlayer.collider.gameObject.tag == "Player") {
                        gameController.stunProjectile.GetComponent<AnimationScript>().direction = direction;
                        gameController.stunProjectile.GetComponent<AnimationScript>().target = otherPlayer.collider.transform.position;
                        if (otherPlayer.collider.gameObject.tag == "Border") {
                            gameController.stunProjectile.GetComponent<AnimationScript>().target = otherPlayer.point;
                        }
                        gameController.stunProjectile.GetComponent<AnimationScript>().targetObject = otherPlayer.collider.gameObject;
                        gameController.stunProjectile.transform.position = transform.position;
                        gameController.stunProjectile.SetActive(true);

                        Player playerScript = otherPlayer.collider.gameObject.GetComponent<Player>();

                        if (int.Parse(GameController.instance.playerStatusList[playerScript.playerNum].GetComponentInChildren<Text>().text) == 1) {
                            GameController.instance.usablePlayers[playerScript.playerNum] = false;
                        }

                        gameController.stunProjectile.GetComponent<Animator>().SetTrigger("move");
                        doneTurn = true;
                        stunShootMode = false;
                        holding = false;
                    }

                }

            } else {

                ChangeColor(highlightColor);

                bool moved = false;

                //movement
                if (Right()) {
                    playerAnimation.direction = 0;
                    playerAnimation.type = 0;
                    moved = true;
                } else if (Left()) {
                    playerAnimation.direction = 180;
                    playerAnimation.type = 0;
                    moved = true;
                } else if (Up()) {
                    playerAnimation.direction = 90;
                    playerAnimation.type = 0;
                    moved = true;
                } else if (Down()) {
                    playerAnimation.direction = 270;
                    playerAnimation.type = 0;
                    moved = true;
                }

                //projectiles
                if (Action() && holding && pickup == 0) {
                    shootMode = true;
                }

                //place block
                if (Action() && holding && pickup == 1) {
                    blockMode = true;
                }

                //spawn player
                if (Action() && holding && pickup == 2) {
                    spawnMode = true;
                }

                //slow projectile
                if (Action() && holding && pickup == 3) {
                    slowShootMode = true;
                }

                //block projectile
                if (Action() && holding && pickup == 4) {
                    blockShootMode = true;
                }

                //stun projectile
                if (Action() && holding && pickup == 5) {
                    stunShootMode = true;
                }

                if (moved) {
                    //check if there is something in the way
                    RaycastHit2D otherObject = Physics2D.Raycast(transform.position + MathHelper.DegreeToVector3(playerAnimation.direction), MathHelper.DegreeToVector2(playerAnimation.direction));

                    if(otherObject.collider == null || (Vector3.Distance(otherObject.point, transform.position + MathHelper.DegreeToVector3(playerAnimation.direction)) > 0.6f || (otherObject.collider.tag != "Border" && Vector3.Distance(otherObject.point, transform.position + MathHelper.DegreeToVector3(playerAnimation.direction)) >= 0.45f)) || otherObject.collider.tag == "Pickup") {
                        animator.SetTrigger("move");
                        doneTurn = true; //once the animation becomes idle again, the doneTurn if statement will be triggered, and the next turn will start
                    }

                }
            }

        }

    }
コード例 #4
0
ファイル: SlowHelper.cs プロジェクト: brandann/BeachTD
 void Awake()
 {
     _parentSlow = gameObject.GetComponentInParent <SlowProjectile>();
 }