Ejemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PowerUpScript powerup = other.gameObject.GetComponent <PowerUpScript> ();

        if (powerup != null)
        {
            shotLevel       += powerup.shotXP;
            powerup.powerGet = true;
        }
        LifeUpScript lifeup = other.gameObject.GetComponent <LifeUpScript> ();

        if (lifeup != null)
        {
            GotLife         = true;
            lifeup.powerGet = true;
        }
        ElementPowerScript elePower = other.gameObject.GetComponent <ElementPowerScript> ();

        if (elePower != null)
        {
            GotNewPower       = elePower.shotElement;
            elePower.powerGet = true;
        }

        BackgroundLoop loop = other.gameObject.GetComponent <BackgroundLoop> ();

        if (loop != null)
        {
            loop.checkpoint = true;
        }
    }
Ejemplo n.º 2
0
        public async Task StartAndStop()
        {
            var firstTickTaskSource = new TaskCompletionSource <object?>();

            var startingCalled = false;
            var tickCalled     = false;
            var stoppingCalled = false;

            var backgroundLoop = new BackgroundLoop();

            backgroundLoop.Starting += (_, _) => { startingCalled = true; };
            backgroundLoop.Tick     += (_, _) =>
            {
                tickCalled = true;
                firstTickTaskSource.TrySetResult(null);
            };
            backgroundLoop.Stopping += (_, _) => { stoppingCalled = true; };

            await backgroundLoop.StartAsync();

            await firstTickTaskSource.Task;
            await backgroundLoop.StopAsync(5000);

            Assert.IsTrue(startingCalled, nameof(startingCalled));
            Assert.IsTrue(tickCalled, nameof(tickCalled));
            Assert.IsTrue(stoppingCalled, nameof(stoppingCalled));
        }
Ejemplo n.º 3
0
        public async Task InvokeMethod_AfterStart()
        {
            var firstTickTaskSource = new TaskCompletionSource <object?>();

            var firstTickPassed = false;

            var backgroundLoop = new BackgroundLoop(string.Empty, 500);

            backgroundLoop.Tick += (_, _) =>
            {
                if (!firstTickPassed)
                {
                    firstTickPassed = true;
                    firstTickTaskSource.TrySetResult(null);
                }
            };

            await backgroundLoop.StartAsync();

            await firstTickTaskSource.Task;

            var methodInvoked = false;
            await backgroundLoop.InvokeAsync(() => methodInvoked = true);

            await backgroundLoop.StopAsync(5000);

            Assert.IsTrue(methodInvoked, nameof(methodInvoked));
        }
Ejemplo n.º 4
0
 // Start is called before the first frame update
 void Start()
 {
     rb         = GetComponent <Rigidbody2D>();
     gameCount  = GetComponent <GameCounts>();
     backscript = mainCamera.GetComponent <BackgroundLoop>();
     nextLevel  = false;
     sceneManag = actScene.GetComponent <SceneManag>();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets all required properties based on the given target thread.
        /// The name of the messenger is directly taken from the given <see cref="BackgroundLoop"/>.
        /// </summary>
        /// <param name="hostThread">The thread on which this Messenger should work on.</param>
        public void ConnectToGlobalMessaging(BackgroundLoop hostThread)
        {
            hostThread.EnsureNotNull(nameof(hostThread));

            this.ConnectToGlobalMessaging(
                FirLibMessengerThreadingBehavior.EnsureMainSyncContextOnSyncCalls,
                hostThread.Name,
                hostThread.SyncContext);
        }
Ejemplo n.º 6
0
 // Start is called before the first frame update
 void Start()
 {
     rb         = GetComponent <Rigidbody2D>();
     gameCount  = GetComponent <GameCounts>();
     gameOver   = GetComponent <GameOver>();
     backLoop   = mainCamera.GetComponent <BackgroundLoop>();
     nextLevel  = GetComponent <NextLevel>();
     sceneManag = actScene.GetComponent <SceneManag>();
 }
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 8
0
    public static BackgroundLoop instance; //Static because we only want one instance

    private void Awake()
    {
        if (instance == null) //Instace == null because we dont set it then we assign it this instance.
        {
            instance = this;
        }
        else if (instance != this) //If instance != the new instance destroy it
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
    }
Ejemplo n.º 9
0
 private void Awake()
 {
     //destroy the instance that is created after the first game loss..
     if (_instanceBackgroundLoop == null)
     {
         _instanceBackgroundLoop = this;
     }
     else if (_instanceBackgroundLoop != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
 }
Ejemplo n.º 10
0
        public async Task InvokeMethod_BeforeStart()
        {
            var backgroundLoop = new BackgroundLoop(string.Empty, 500);

            var methodInvoked = false;
            var invokeTask    = backgroundLoop.InvokeAsync(() => methodInvoked = true);
            await backgroundLoop.StartAsync();

            await invokeTask;
            await backgroundLoop.StopAsync(5000);

            Assert.IsTrue(methodInvoked, nameof(methodInvoked));
        }
Ejemplo n.º 11
0
    // Start is called before the first frame update
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }


        DontDestroyOnLoad(gameObject);
    }
Ejemplo n.º 12
0
 public void Awake()
 {
     if (backgroundLoop == null)
     {
         backgroundLoop = this;
     }
     else
     {
         if (gameObject != this)
         {
             Destroy(gameObject);
         }
     }
     DontDestroyOnLoad(gameObject);
 }
Ejemplo n.º 13
0
 void Update()
 {
     liveBoss = GameObject.FindGameObjectWithTag("Boss");
     if ((endStage) && (liveBoss == null))
     {
         LifeSystemScript lifeSystem = GameObject.FindGameObjectWithTag("LifeControl").GetComponent <LifeSystemScript> ();
         lifeSystem.stageClear = true;
     }
     if (checkpoint)
     {
         var            newBackground  = Instantiate(loopPrefab, transform.position + new Vector3(42.35f, 0), Quaternion.identity, transform.parent) as Transform;
         var            newBackground2 = Instantiate(loopPrefab, transform.position + new Vector3(84.7f, 0), Quaternion.identity, transform.parent) as Transform;
         var            newSensor      = Instantiate(nextSensor, transform.position + new Vector3(84.7f, 0), transform.rotation, transform.parent) as Transform;
         BackgroundLoop loop           = newSensor.transform.GetComponent <BackgroundLoop> ();
         loop.checkpoint = false;
         loop.loopPoints = loopPoints + 1;
         if (SceneManager.GetActiveScene().name != "MainMenu")
         {
             if (stagePoints > 0)
             {
                 while (loopPoints > 0)
                 {
                     int enemyId = Random.Range(0, 3);
                     if ((EnemyLimit [enemyId] > 0) && (Random.Range(0, 100) <= EnemyProb[enemyId]))
                     {
                         var genEnemy = Instantiate(Enemy [enemyId], transform.position + new Vector3(Random.Range(42.35f, 84.35f), Random.Range(-4, 4.5f)), Quaternion.identity, transform.parent.parent) as Transform;
                         loopPoints  -= EnemyCost [enemyId];
                         stagePoints -= EnemyCost [enemyId];
                         EnemyLimit [enemyId]--;
                     }
                 }
             }
             else if (endStage == false)
             {
                 var genEnemy = Instantiate(Boss, transform.position + new Vector3(42.35f, Random.Range(-2, 2.5f)), Quaternion.identity, transform.parent.parent) as Transform;
                 endStage = true;
             }
         }
         loop.stagePoints = stagePoints;
         loop.endStage    = endStage;
         Destroy(gameObject);
     }
 }
Ejemplo n.º 14
0
    void Start()
    {
        BoxCollider2D streetCollider = streetObject.GetComponent <BoxCollider2D>();
        float         verticalLength = streetCollider.size.y * streetObject.transform.localScale.y;
        float         lastPos        = 0;

        for (int i = 0; i < visibleObjects; i++)
        {
            GameObject sClone = Instantiate(streetObject, transform);
            sClone.GetComponent <SpriteRenderer>().sprite = streetSprites[i];

            BackgroundLoop bl = sClone.GetComponent <BackgroundLoop>();
            bl.VerticalLength = verticalLength * visibleObjects / 2;
            bl.sprites        = streetSprites;

            sClone.transform.position = new Vector3(0, lastPos, 1);

            lastPos -= verticalLength;
        }
    }
Ejemplo n.º 15
0
        public async Task IsThreadNameSet()
        {
            var firstTickTaskSource = new TaskCompletionSource <object?>();

            var isThreadNameSet = false;

            var backgroundLoop = new BackgroundLoop("TestThreadName", 10);

            backgroundLoop.Tick += (_, _) =>
            {
                isThreadNameSet = Thread.CurrentThread.Name == "TestThreadName";
                firstTickTaskSource.TrySetResult(null);
            };

            await backgroundLoop.StartAsync();

            await firstTickTaskSource.Task;
            await backgroundLoop.StopAsync(5000);

            Assert.IsTrue(isThreadNameSet, nameof(isThreadNameSet));
        }
Ejemplo n.º 16
0
        public async Task IsSynchronizationContextSet()
        {
            var firstTickTaskSource = new TaskCompletionSource <object?>();

            var isSyncContextSet = false;

            var backgroundLoop = new BackgroundLoop(string.Empty, 500);

            backgroundLoop.Tick += (_, _) =>
            {
                isSyncContextSet =
                    SynchronizationContext.Current is BackgroundLoop.BackgroundLoopSynchronizationContext;
                firstTickTaskSource.TrySetResult(null);
            };

            await backgroundLoop.StartAsync();

            await firstTickTaskSource.Task;
            await backgroundLoop.StopAsync(5000);

            Assert.IsTrue(isSyncContextSet, nameof(isSyncContextSet));
        }
Ejemplo n.º 17
0
        public async Task TicksMoreTimes()
        {
            var firstTickTaskSource = new TaskCompletionSource <object?>();

            var tickCount = 0;

            var backgroundLoop = new BackgroundLoop(string.Empty, 10);

            backgroundLoop.Tick += (_, _) =>
            {
                tickCount++;
                if (tickCount == 5)
                {
                    firstTickTaskSource.TrySetResult(null);
                }
            };

            await backgroundLoop.StartAsync();

            await firstTickTaskSource.Task;
            await backgroundLoop.StopAsync(5000);

            Assert.IsTrue(tickCount >= 5, nameof(tickCount));
        }