Beispiel #1
0
    void Handle(InputDataReceivedEvent e)
    {
        constraint.ForEachGameObject((ego, ready) => {
            if (e.data == 5 && e.playerID == 1)
            {
                ready.playerOneReady = true;
                EgoEvents <PlayerReadyEvent> .AddEvent(new PlayerReadyEvent(1));
            }
            if (e.data == 6 && e.playerID == 1)
            {
                ready.playerOneReady = false;
                EgoEvents <PlayerNotReadyEvent> .AddEvent(new PlayerNotReadyEvent(1));
            }
            if (e.data == 5 && e.playerID == 2)
            {
                ready.playerTwoReady = true;
                EgoEvents <PlayerReadyEvent> .AddEvent(new PlayerReadyEvent(2));
            }

            if (e.data == 6 && e.playerID == 2)
            {
                ready.playerOneReady = false;
                EgoEvents <PlayerNotReadyEvent> .AddEvent(new PlayerNotReadyEvent(2));
            }
        });
    }
 private void Handle(CheckEndOfLineEvent e)
 {
     //
     // Check to see if Ego entity "car" or "opps_x" has crossed the finish line
     //
     constraint.ForEachGameObject(
         (egoComp, endofline) =>
     {
         //
         // If any car crosses the finish line, then game ends
         //
         if (e.car.transform.position.y > endofline.transform.position.y)
         {
             //
             // Following is a play line to see how to add a component to an entity
             // Issue the pause component to the car the just crossed the finish line
             //
             Ego.AddComponent <PauseComponent>(egoComp);
             //
             // Invoke the event that causes the EndOfGameSystem to turn on "Game Over" text
             //
             EgoEvents <EndOfGameEvent> .AddEvent(new EndOfGameEvent(true));
         }
     }
         );
 }
Beispiel #3
0
    public override void Update()
    {
        //HasSpeedUpComponent speedUp;
        constraint.ForEachGameObject((egoComponent, transform, powerUpComponent, movementComponent) => {
            if (powerUpComponent.powerUpActivated)
            {
                movementComponent.flySpeed  = 4;
                movementComponent.curvspeed = 2.9f;
                Ego.DestroyComponent <HasSpeedUpComponent>(egoComponent);
            }

            if (powerUpComponent.powerUpActivated)
            {
                powerUpComponent.playerPowerUpTimer += Time.deltaTime;
            }
            if (powerUpComponent.playerPowerUpTimer >= 2)
            {
                powerUpComponent.playerPowerUpTimer = -1f;
                movementComponent.flySpeed          = 2;
                movementComponent.curvspeed         = 2;
                powerUpComponent.powerUpActivated   = false;
            }

            HasSpeedUpComponent speed;
            if ((KutiInput.Instance.GetButtonDown(powerUpComponent.powerUpButton) || Input.GetKey(powerUpComponent.powerUpButtonPC) && egoComponent.TryGetComponents(out speed)))
            {
                var ev = new OnActivatePowerUp(powerUpComponent.playerID, egoComponent);
                EgoEvents <OnActivatePowerUp> .AddEvent(ev);
            }
        });
    }
        void OnTriggerExit2D(Collider2D collider2d)
        {
            var e = new TriggerExit2DEvent(egoComponent, collider2d.gameObject.GetComponent <EgoComponent>(),
                                           collider2d);

            EgoEvents <TriggerExit2DEvent> .AddEvent(e);
        }
Beispiel #5
0
    public static void Start()
    {
        // Attach an EgoComponent Component to each GameObject
        var gameObjects   = Object.FindObjectsOfType <GameObject>();
        var egoComponents = new List <EgoComponent>();

        foreach (var gameObject in gameObjects)
        {
            var egoComponent = gameObject.GetComponent <EgoComponent>();
            if (!egoComponent)
            {
                egoComponent = gameObject.AddComponent <EgoComponent>();
            }
            egoComponent.CreateMask();
            egoComponents.Add(egoComponent);
        }

        // Create System bundles
        foreach (var system in _systems)
        {
            system.CreateBundles(egoComponents.ToArray());
        }

        // Start all Systems
        foreach (var system in _systems)
        {
            system.Start();
        }

        // Invoke all queued Events
        EgoEvents.Invoke();

        // Clean up Destroyed Components & GameObjects
        EgoCleanUp.CleanUp();
    }
        public static EgoComponent GenerateGun()
        {
            EntityBuilder entity = EntityBuilder.Generate().WithPhysics(typeof(BoxCollider2D), .5f).WithGraphics("Images/gun");
            Interactive   c      = Ego.AddComponent <Interactive>(entity);

            c.InteractAction = e => EgoEvents <AttachEvent> .AddEvent(new AttachEvent(c.GetComponent <EgoComponent>(), e));

            Ego.AddComponent <Mountpoint>(entity);
            Useable u = Ego.AddComponent <Useable>(entity);

            u.UseAction = e => {
                Transform transform = u.transform;
                double    theta     = transform.rotation.eulerAngles.z * Mathf.Deg2Rad;
                Vector2   force     = new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
                force.Normalize();
                // generate new projectile, add motion in direction at speed

                EgoComponent bullet = Ego.AddGameObject(GenerateBullet().gameObject);
                bullet.transform.rotation = transform.rotation;
                bullet.transform.position = transform.position;
                bullet.gameObject.SetActive(true);
                EgoEvents <SetVelocityByEvent> .AddEvent(new SetVelocityByEvent(bullet, force));
            };
            return(entity);
        }
Beispiel #7
0
    protected override void Execute()
    {
        Debug.Log("Execute pregnancy");
        if (setPregnant)
        {
            parent.isPregnant = true;
            if (parent.childPart == null)
            {
                var commandEvent = new CommandEvent(new BirthCommand(parent, position), 1);
                EgoEvents <CommandEvent> .AddEvent(commandEvent);

                var commandEvent2 = new CommandEvent(new PregnancyCommand(parent, position, false), 1);
                EgoEvents <CommandEvent> .AddEvent(commandEvent2);
            }
            else
            {
                if (!parent.childPart.isPregnant)
                {
                    var commandEvent = new CommandEvent(new PregnancyCommand(parent.childPart, position, true), 1);
                    EgoEvents <CommandEvent> .AddEvent(commandEvent);

                    var commandEvent2 = new CommandEvent(new PregnancyCommand(parent, position, false), 1);
                    EgoEvents <CommandEvent> .AddEvent(commandEvent2);
                }
            }
        }
        else
        {
            parent.isPregnant = false;
        }
    }
 public override void Start()
 {
     //
     // Register to listen to EndOfGame broadcast
     //
     EgoEvents <EndOfGameEvent> .AddHandler(Handle);
 }
Beispiel #9
0
    public EgoSystem()
    {
        _mask[ComponentIDs.Get(typeof(C1))]           = true;
        _mask[ComponentIDs.Get(typeof(C2))]           = true;
        _mask[ComponentIDs.Get(typeof(C3))]           = true;
        _mask[ComponentIDs.Get(typeof(C4))]           = true;
        _mask[ComponentIDs.Get(typeof(EgoComponent))] = true;

        // Attach built-in Event Handlers
        EgoEvents <AddedGameObject> .AddHandler(Handle);

        EgoEvents <DestroyedGameObject> .AddHandler(Handle);

        EgoEvents <AddedComponent <C1> > .AddHandler(Handle);

        EgoEvents <AddedComponent <C2> > .AddHandler(Handle);

        EgoEvents <AddedComponent <C3> > .AddHandler(Handle);

        EgoEvents <AddedComponent <C4> > .AddHandler(Handle);

        EgoEvents <DestroyedComponent <C1> > .AddHandler(Handle);

        EgoEvents <DestroyedComponent <C2> > .AddHandler(Handle);

        EgoEvents <DestroyedComponent <C3> > .AddHandler(Handle);

        EgoEvents <DestroyedComponent <C4> > .AddHandler(Handle);
    }
Beispiel #10
0
    public override void Start()
    {
        EgoEvents <InputDataReceivedEvent> .AddHandler(Handle);

        //EgoEvents<PlayerHitEvent>.AddHandler (Handle);
        EgoEvents <CollisionEnter2DEvent> .AddHandler(Handle);
    }
Beispiel #11
0
        public EgoConstraint()
        {
            _mask[ComponentIDs.Get(typeof(C1))]           = true;
            _mask[ComponentIDs.Get(typeof(C2))]           = true;
            _mask[ComponentIDs.Get(typeof(C3))]           = true;
            _mask[ComponentIDs.Get(typeof(C4))]           = true;
            _mask[ComponentIDs.Get(typeof(C5))]           = true;
            _mask[ComponentIDs.Get(typeof(EgoComponent))] = true;

            EgoEvents <AddedComponent <C1> > .AddHandler(e => CreateBundles(e.egoComponent));

            EgoEvents <DestroyedComponent <C1> > .AddHandler(e => RemoveBundles(e.egoComponent));

            EgoEvents <AddedComponent <C2> > .AddHandler(e => CreateBundles(e.egoComponent));

            EgoEvents <DestroyedComponent <C2> > .AddHandler(e => RemoveBundles(e.egoComponent));

            EgoEvents <AddedComponent <C3> > .AddHandler(e => CreateBundles(e.egoComponent));

            EgoEvents <DestroyedComponent <C3> > .AddHandler(e => RemoveBundles(e.egoComponent));

            EgoEvents <AddedComponent <C4> > .AddHandler(e => CreateBundles(e.egoComponent));

            EgoEvents <DestroyedComponent <C4> > .AddHandler(e => RemoveBundles(e.egoComponent));

            EgoEvents <AddedComponent <C5> > .AddHandler(e => CreateBundles(e.egoComponent));

            EgoEvents <DestroyedComponent <C5> > .AddHandler(e => RemoveBundles(e.egoComponent));
        }
Beispiel #12
0
    public override void Update()
    {
        constraint.ForEachGameObject(
            (ego, player) =>
        {
            float moveVertical = Input.GetAxis("Vertical");
            if (gameIsOver)
            {
                // do nothing is game is over
            }
            else
            {
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    Vector3 now = player.transform.position;
                    player.transform.position = new Vector3(now.x, now.y + player.speed, now.z);
                    //
                    // invoke an event to check if the player car has crossed the line
                    //
                    if (ego.gameObject.name == "Player")
                    {
                        var eve = new CheckEndOfLineEvent(ego);
                        EgoEvents <CheckEndOfLineEvent> .AddEvent(eve);
                    }
                }
            }
        }

            );
    }
        void OnCollisionStay2D(Collision2D collision)
        {
            var e = new CollisionStay2DEvent(egoComponent, collision.gameObject.GetComponent <EgoComponent>(),
                                             collision);

            EgoEvents <CollisionStay2DEvent> .AddEvent(e);
        }
Beispiel #14
0
    public EgoParentConstraint()
    {
        childConstraint = new CS1();
        childConstraint.parentConstraint = this;

        _mask[ComponentIDs.Get(typeof(C1))]           = true;
        _mask[ComponentIDs.Get(typeof(C2))]           = true;
        _mask[ComponentIDs.Get(typeof(C3))]           = true;
        _mask[ComponentIDs.Get(typeof(C4))]           = true;
        _mask[ComponentIDs.Get(typeof(C5))]           = true;
        _mask[ComponentIDs.Get(typeof(EgoComponent))] = true;

        EgoEvents <AddedComponent <C1> > .AddHandler(e => CreateBundles(e.egoComponent));

        EgoEvents <DestroyedComponent <C1> > .AddHandler(e => RemoveBundles(e.egoComponent));

        EgoEvents <AddedComponent <C2> > .AddHandler(e => CreateBundles(e.egoComponent));

        EgoEvents <DestroyedComponent <C2> > .AddHandler(e => RemoveBundles(e.egoComponent));

        EgoEvents <AddedComponent <C3> > .AddHandler(e => CreateBundles(e.egoComponent));

        EgoEvents <DestroyedComponent <C3> > .AddHandler(e => RemoveBundles(e.egoComponent));

        EgoEvents <AddedComponent <C4> > .AddHandler(e => CreateBundles(e.egoComponent));

        EgoEvents <DestroyedComponent <C4> > .AddHandler(e => RemoveBundles(e.egoComponent));

        EgoEvents <AddedComponent <C5> > .AddHandler(e => CreateBundles(e.egoComponent));

        EgoEvents <DestroyedComponent <C5> > .AddHandler(e => RemoveBundles(e.egoComponent));

        EgoEvents <SetParent> .AddHandler(e => SetParent(e.parent, e.child, e.worldPositionStays));
    }
Beispiel #15
0
 protected override void Execute()
 {
     parent.isPregnant = false;
     if (parent.childPart == null)
     {
         child                    = Ego.AddGameObject(Object.Instantiate <GameObject>(parent.snakePrefab)).GetComponent <SnakePartComponent>();
         child.snakePrefab        = parent.snakePrefab;
         child.transform.position = position;
         child.transform.rotation = parent.transform.rotation;
         child.transform.parent   = parent.container;
         child.container          = parent.container;
         parent.childPart         = child;
         //child.parentPart = parent;
         createdNew = true;
     }
     else
     {
         createdNew = false;
         if (!parent.childPart.isPregnant)
         {
             parent.childPart.isPregnant = true;
             var commandEvent = new CommandEvent(new PregnancyCommand(parent.childPart, position, true), 1);
             EgoEvents <CommandEvent> .AddEvent(commandEvent);
         }
     }
 }
 public override void Start()
 {
     //
     // if any cars cross the finish line then handle
     // Checking of end of line event
     //
     EgoEvents <CheckEndOfLineEvent> .AddHandler(Handle);
 }
Beispiel #17
0
    void TryDash(Movement movement, ActorComponent actor)
    {
        movement.velocity.x  = (-movement.velocity.x) + Mathf.Sign(movement.velocity.x) * 30f;
        movement.velocity.y -= movement.velocity.y;
        var e = new DashEvent(actor.guid, movement.velocity);

        EgoEvents <DashEvent> .AddEvent(e);
    }
Beispiel #18
0
    public override void Start()
    {
        EgoEvents <DamageEvent> .AddHandler(Handle);

        EgoEvents <CountDownEvent> .AddHandler(Handle);

        EgoEvents <GameStartEvent> .AddHandler(Handle);
    }
Beispiel #19
0
 public static void SetParent(EgoComponent parent, EgoComponent child)
 {
     if (child == null)
     {
         Debug.LogWarning("Cannot set the Parent of a null Child");
     }
     EgoEvents <SetParent> .AddEvent(new SetParent( parent, child ));
 }
Beispiel #20
0
    public static void Destroy(GameObject gameObject)
    {
        var egoComponent = gameObject.GetComponent <EgoComponent>();

        EgoEvents <DestroyedGameObject> .AddEvent(new DestroyedGameObject( gameObject, egoComponent ));

        EgoCleanUp.Destroy(gameObject);
    }
Beispiel #21
0
    public static void DestroyGameObject(EgoComponent egoComponent)
    {
        var gameObject = egoComponent.gameObject;

        EgoEvents <DestroyedGameObject> .AddEvent(new DestroyedGameObject( gameObject, egoComponent ));

        EgoCleanUp.Destroy(egoComponent.gameObject);
    }
Beispiel #22
0
    public static EgoComponent AddGameObject(GameObject gameObject)
    {
        var egoComponent = AddGameObjectToChildren(gameObject.transform);

        EgoEvents <AddedGameObject> .AddEvent(new AddedGameObject( gameObject, egoComponent ));

        return(egoComponent);
    }
Beispiel #23
0
    public override void Start()
    {
        constraint.ForEachGameObject((egoComponent, transform, lineRenderer, lineRendererComponent) => {
        });

        EgoEvents <LineRendererDrawEvent> .AddHandler(Handle);

        EgoEvents <CountDownEvent> .AddHandler(Handle);
    }
 void SetOnGround(BottomComponent bottom)
 {
     if (!bottom.touchingGround)
     {
         var e = new TouchGroundEvent(bottom.actor.guid, true);
         EgoEvents <TouchGroundEvent> .AddEvent(e);
     }
     bottom.touchingGround = true;
 }
Beispiel #25
0
 void Handle(JumpEvent e)
 {
     constraint.ForEachGameObject((egoComponent, transform, movement) =>
     {
         MovementComponent.ViewDirection moveDirectionVar;
         moveDirectionVar = movement.viewDirection;
         EgoEvents <JumpEvent> .AddEvent(new JumpEvent(moveDirectionVar.ToString()));
     });
 }
 void SetOffGround(BottomComponent bottom)
 {
     if (bottom.touchingGround)
     {
         var e = new TouchGroundEvent(bottom.actor.guid, false);
         EgoEvents <TouchGroundEvent> .AddEvent(e);
     }
     bottom.touchingGround = false;
 }
Beispiel #27
0
 public override void Start()
 {
     constraint.ForEachGameObject((egoComponent, countDownComponent) => {
         Debug.Log("Countdown Start");
         countDownComponent.myCountDownStatus = CountDownComponent.CountDownStatus.inactive;
         egoComponent.gameObject.SetActive(false);
     });
     EgoEvents <CountDownEvent> .AddHandler(Handle);
 }
Beispiel #28
0
    // Use this for initialization
    public override void Start()
    {
        constraint.ForEachGameObject((egoComponent, transform, movement) => {
            movement.viewDirection = MovementComponent.ViewDirection.none;
        });

        EgoEvents <JumpEvent> .AddHandler(Handle);

        EgoEvents <InputDataReceivedEvent> .AddHandler(Handle);
    }
Beispiel #29
0
    // Use this for initialization
    public override void Start()
    {
        //Register Event Handlers
        EgoEvents <PlayerHitEvent> .AddHandler(Handle);

        constraint.ForEachGameObject((egoComponent, transform, player) =>
        {
            player.initialPosition = transform.position;
        });
    }
Beispiel #30
0
    public override void Start()
    {
        constraint.ForEachGameObject((egoComponent, transform, powerUpUIComponent) => {
            egoComponent.gameObject.GetComponent <SpriteRenderer>().enabled = false;
        });

        EgoEvents <OnSpeedUpPickUp> .AddHandler(Handle);

        EgoEvents <OnActivatePowerUp> .AddHandler(Handle);
    }