Esempio n. 1
0
    //this is where the objects are created and returned into the main program
    public Enemyship initShip(string ship)
    {
        Enemyship enemyShip = null;

        if (ship.Equals("UFO"))
        {
            return(new Ufo());
        }
        else if (ship.Equals("MOTHERSHIP"))
        {
            return(new Mothership());
        }
        else
        {
            return(null);
        }
    }
    void playerInput()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            shipType = "UFO";

            enemyShip = flyweightFactory.initShip(shipType);
            enemyActions(enemyShip, "UFO");
        }
        else if (Input.GetButtonDown("Jump"))
        {
            shipType = "MOTHERSHIP";

            enemyShip = flyweightFactory.initShip(shipType);
            enemyActions(enemyShip, "MOTHERSHIP");
        }
        else
        {
        }
    }
    void spawnEnemy()
    {
        float TempR = rN;

        //int TempR = 2;
        if (TempR <= 1 && Time.time > nextSpawnTime)
        {
            nextSpawnTime = Time.time + spawnPeriod;
            shipType      = "UFO";
            enemyShip     = flyweightFactory.initShip(shipType);
            enemyActions(enemyShip, "UFO");
            //nextSpawnTime = spawnPeriod;
        }
        else if (TempR >= 1 && Time.time > nextSpawnTime)
        {
            nextSpawnTime = Time.time + spawnPeriod;
            shipType      = "MOTHERSHIP";
            enemyShip     = flyweightFactory.initShip(shipType);
            enemyActions(enemyShip, "MOTHERSHIP");
        }
        else
        {
        }
    }
 //provides a set of actions for the object to perform, in this case, instantiate
 void enemyActions(Enemyship anEnemyShip, string t)
 {
     anEnemyShip.getShip(rSx, rSz, wallPos, t);
     anEnemyShip.shipAction();
 }