示例#1
0
    // Update is called once per frame
    void Update()
    {
        // SUPERHACK: Really I should hook into an OnDeath event from the player...but I want this now
        if (GameObject.Find("TDFighterRoot(Clone)") == null)
        {
            spawnTimer -= Time.deltaTime;
            if (spawnTimer <= 0.0f)
            {
                activePlayer = Instantiate(PlayerShip, SpawnPoint.position, SpawnPoint.rotation);
                spawnTimer   = RespawnTime;
                //player.OnDeath += OnPlayerDeath;
            }
        }

        // HACK: Need an input handler somewhere
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!gamePaused)
            {
                PauseGame();
            }
            else
            {
                UnpauseGame();
            }
        }
    }
示例#2
0
    protected override void onTargetReached(GameObject obj)
    {
        TDWorld    world  = TDWorld.getWorld();
        GameObject player = world.getPlayer();

        if (obj == player)
        {
            TDPlayer tdP = world.getTDPlayer();
            tdP.receiveDamage(1);
        }
        DestroyObject(gameObject);
    }
示例#3
0
    void OnDestroy()
    {
        Destroy(m_healthBar);
        if (OnEventDestroy != null)
        {
            OnEventDestroy(this);
        }
        TDWorld world = TDWorld.getWorld();

        if (world == null)
        {
            return;
        }
        TDPlayer player = world.getTDPlayer();

        if (player == null)
        {
            return;
        }
        player.reward(killReward());
    }
示例#4
0
    // Update is called once per frame
    void Update()
    {
        TDWorld  world    = TDWorld.getWorld();
        TDPlayer tdPlayer = world.getTDPlayer();

        if (tdPlayer.health() <= 0)
        {
            Application.LoadLevel("GameOver");
        }

        if (Mode.eNone == m_mode)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(mouseRay, out hit))
            {
                if (hit.transform.gameObject.Equals(GameObject.Find("Terrain")))
                {
                    Vector3 pos = hit.point;
                    pos = TDWorld.getWorld().truncate3d(pos);
                    GameObject newTower = null;
                    if (TDGrid.CellState.eFree == world.positionState(pos))
                    {
                        switch (m_mode)
                        {
                        case Mode.eArcher:
                            if (!world.canTowerBeBuiltAt(pos))
                            {
                                break;
                            }
                            newTower = world.addTower(TDTower.Type.eArrowTower, pos);
                            break;

                        case Mode.eCanon:
                            if (!world.canTowerBeBuiltAt(pos))
                            {
                                break;
                            }
                            newTower = world.addTower(TDTower.Type.eCanonTower, pos);
                            break;

                        case Mode.eHeroPatrol:
                            TDHero tdHero = world.getTDHero();
                            tdHero.patrol(pos);
                            break;

                        default:
                            return;
                        }
                        if (newTower != null)
                        {
                            TDTower tdTower = world.getTDTower(newTower);
                            if (!tdPlayer.affords(tdTower.price()))
                            {
                                DestroyObject(newTower);
                                return;
                            }
                            tdPlayer.expense(tdTower.price());
                            TDWorld.getWorld().occupyPosition(pos, TDGrid.CellState.eBusy);
                        }
                    }
                }
            }
        }
    }