private void UpdateDebug()
 {
     if(Input.GetKeyDown(KeyCode.K))
     {
         CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GrowEvent(10));
     }
 }
 private void OnGridCollision(GridTransform other)
 {
     if (other.GetComponent <Player>() != null)
     {
         CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GameOverEvent());
     }
 }
Exemple #3
0
 private void OnGridCollision(GridTransform other)
 {
     if (other.GetComponent <Player>() != null)
     {
         Destroy(gameObject);
         CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GameState.WinLevelEvent());
     }
 }
Exemple #4
0
    private void Start()
    {
        childRight = MakeChild("childRight", Vector2.right);
        childUp    = MakeChild("childUp", Vector2.up);
        childOne   = MakeChild("childOne", Vector2.one);

        gridTransform = gameObject.GetComponent <GridTransform>();
        gridRight     = childRight.AddComponent <GridTransform>();
        gridUp        = childUp.AddComponent <GridTransform>();
        gridOne       = childOne.AddComponent <GridTransform>();

        gridTransforms = new GridTransform[] { gridTransform, gridRight, gridUp, gridOne };

        foreach (var gTransform in gridTransforms)
        {
            gTransform.Events = new GridEventHandlers(OnCollision: (x) => OnGridCollision(x));
        }

        tweener            = gameObject.AddComponent <LinearTweener>();
        tweener.speed      = 10f;
        tweener.autoTarget = () => gridTransform.Target;

        //gridTransform.Warp(GridSystem.GetNode((int)transform.position.x, (int)transform.position.y));

        CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GameState.EnemySpawnEvent());

        animationParent = new GameObject("animationParent");
        animationParent.transform.SetParent(transform, false);
        animationParent.transform.localPosition = new Vector3(0.5f, -0.5f, 0f);

        animationChild      = GameObject.CreatePrimitive(PrimitiveType.Quad);
        animationChild.name = "AnimationChild";
        animationChild.transform.SetParent(animationParent.transform, false);
        animationChild.transform.localPosition = Vector2.up;
        animationChild.transform.localScale    = new Vector3(2f, 2f, 1f);

        Sprite[] sheet = Resources.LoadAll <Sprite>("Sprites/slime-sprite-sheet-FINAL-PNG");

        front = textureFromSprite(sheet[8]);
        right = textureFromSprite(sheet[5]);
        left  = textureFromSprite(sheet[2]);
        back  = textureFromSprite(sheet[11]);

        mat = new Material(Shader.Find("Unlit/Transparent"));
        mat.SetTexture("_MainTex", front);
        animationChild.GetComponent <MeshRenderer>().material = mat;
    }
Exemple #5
0
    private void OnGridCollision(GridTransform other)
    {
        GreenSlime slime = other.GetComponentInParent <GreenSlime>();

        if (slime == this)
        {
            return;
        }

        Player player = other.GetComponent <Player>();

        if (player != null)
        {
            Destroy(gameObject);
            CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GrowEvent(GameState.SnakeGrowCount));
            CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GameState.EnemyDestroyedEvent());
        }
    }
    public void EventSystemBaseTestSimplePasses()
    {
        //Check that the event system is empty
        Assert.True(CEventSystem.Count == 0);

        //create an event, add it to the system, and check the count
        TestEventObject testEvent = new TestEventObject();

        CEventSystem.AddEventHandler(category.category, category.subcategory, testEvent);
        Assert.True(CEventSystem.Count == 1);

        //Check the state of the test class after broadcasting a set true, set false, and foo event
        Assert.True(!testEvent.State);
        CEventSystem.BroadcastEvent(category.category, category.subcategory, new SetTrueEvent());
        Assert.True(testEvent.State);
        CEventSystem.BroadcastEvent(category.category, category.subcategory, new SetFalseEvent());
        Assert.True(!testEvent.State);
        CEventSystem.BroadcastEvent(category.category, category.subcategory, new FooEvent());
        Assert.True(!testEvent.State);

        //remove the event, check the count of the system.
        CEventSystem.RemoveEventHandler(category.category, category.subcategory, testEvent);
        Assert.True(CEventSystem.Count == 0);
    }
Exemple #7
0
 private void OnGridCollision(GridTransform other)
 {
     CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GameOverEvent());
     Destroy(gameObject);
     //CEventSystem.BroadcastEvent(EventChannel.gameState, EventSubChannel.none, new GrowEvent(1));
 }
Exemple #8
0
 private void BroadcastDirectionEvent(Direction direction)
 {
     CEventSystem.BroadcastEvent(EventChannel.input, EventSubChannel.player1, new DirectionEvent(direction));
 }
 public static void PlaySound(Vector3 position, string soundName, bool loop = false)
 {
     EnsureInstance();
     CEventSystem.BroadcastEvent(EventChannel.sound, EventSubChannel.none, new SoundEvent(position, soundName, loop));
 }