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);
        }
 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));
         }
     }
         );
 }
        public static EgoComponent GenerateCreature()
        {
            EntityBuilder entity = EntityBuilder.Generate().WithPhysics(typeof(CircleCollider2D)).WithMotion();

            Ego.AddComponent <Hardpoint>(entity);
            return(entity);
        }
Exemplo n.º 4
0
    protected override void Undo()
    {
        BoxCollider collider;

        if (edible.TryGetComponents(out collider))
        {
            collider.enabled = false;
            Ego.AddComponent <DelayColliderComponent>(edible);
        }
        edible.gameObject.SetActive(true);
    }
Exemplo n.º 5
0
    void Handle(CollisionEnter2DEvent e)
    {
        Debug.Log("Enter Collision Event");
        constraint.ForEachGameObject((egoComponent, spriteRenderer, collisionComponent, lineRenderer, movement, player) => {
            SpriteRenderer shipSprite;
            PlayerComponent playerC;
            //Return if colliding Object has no SpriteRenderer
            if (!e.egoComponent1.TryGetComponents(out shipSprite))
            {
                return;
            }
            //Else change Sprite to Explosion, if you collided with a spaceship
            else if (e.egoComponent2.TryGetComponents(out playerC) && e.egoComponent1.TryGetComponents(out playerC))
            {
                //e.egoComponent1.GetComponent<SpriteRenderer>().sprite = collisionComponent.explodingSprite;
                if (e.egoComponent1.GetComponent <MovementComponent>().myFlyStatus == MovementComponent.FlyStatus.flying &&
                    e.egoComponent2.GetComponent <MovementComponent>().myFlyStatus == MovementComponent.FlyStatus.flying)
                {
                    var ev = new DamageEvent(player.playerID, false);
                    Debug.Log("Damage Event called cause players collided");
                    EgoEvents <DamageEvent> .AddEvent(ev);
                }

                //Unschön, vielleicht geht das ja auch aus dem DamageEvent heraus?

                /*MovementComponent movementComponent;
                 * if (!e.egoComponent1.TryGetComponents(out movementComponent)) {
                 *      return;
                 * }
                 * else {
                 *      movementComponent.myFlyStatus = MovementComponent.FlyStatus.notFlying;
                 * }*/
            }

            PowerUpComponent powerup;
            if (!e.egoComponent2.TryGetComponents(out powerup))
            {
                return;
            }
            else if (e.egoComponent2.TryGetComponents(out powerup))
            {
                Debug.Log("powerup collected");
                Ego.AddComponent <HasSpeedUpComponent>(e.egoComponent1);
                e.egoComponent1.GetComponent <PlayerPowerUpComponent>().playerPowerUpTimer = 0;
                //e.egoComponent2.gameObject.SetActive(false);
                e.egoComponent2.gameObject.GetComponent <SpriteRenderer>().enabled   = false;
                e.egoComponent2.gameObject.GetComponent <CircleCollider2D>().enabled = false;
                var ev = new OnSpeedUpPickUp(e.egoComponent1.GetComponent <PlayerComponent>().playerID);
                EgoEvents <OnSpeedUpPickUp> .AddEvent(ev);
            }
        });
    }
        public static EgoComponent GenerateLaserGun()
        {
            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 => {
                //RaycastHit2D clicked = Physics2D.Raycast (transform.position, transform.right);
                Transform transform = u.transform;
                Debug.DrawRay(transform.position, transform.right, Color.red, 100, false);
            };
            return(entity);
        }
Exemplo n.º 7
0
 public EntityBuilder WithPhysics(Type colliderType, float diameter = 1)
 {
     Ego.AddComponent <Rigidbody2D>(Entity);
     if (colliderType == typeof(CircleCollider2D))
     {
         Ego.AddComponent <CircleCollider2D>(Entity).radius = diameter / 2;
     }
     else if (colliderType == typeof(BoxCollider2D))
     {
         Ego.AddComponent <BoxCollider2D>(Entity).size = new Vector2(diameter, diameter);
     }
     else
     {
         Debug.LogError("Collider type specified not supported.");
     }
     return(this);
 }
        public static EgoComponent GeneratePlayer()
        {
            EntityBuilder entity =
                EntityBuilder.Generate().WithPhysics(typeof(CircleCollider2D)).WithMotion().WithGraphics("Images/player");

            Ego.AddComponent <MovementInput>(entity);
            Ego.AddComponent <Hardpoint>(entity);
            Ego.AddComponent <BehaviorTree>(entity).TrunkNode =
                new SelectorAll(
                    new ButtonPressed(
                        new Drop(), "Drop"),
                    new ButtonPressed(
                        new Interact(), "Interact"),
                    new ButtonPressed(
                        new Use(), "Fire1")
                    );

            return(entity);
        }
Exemplo n.º 9
0
    // Update is called once per frame
    public override void FixedUpdate()
    {
        /*constraint.ForEachGameObject ((egoComponent, transform, rigbody, jump) => {
         *      if (Input.GetKeyDown(jump.keyCodeJump) && jump.jumpstatus == JumpComponent.Jumpstatus.grounded)
         *      {
         *              jump.jumpstatus = JumpComponent.Jumpstatus.jumping;
         *              Ego.AddComponent<JumpStatus>(egoComponent);
         *              rigbody.gravityScale = 0;
         *              jump.jumpPosition = transform.position;
         *      }
         *
         *      if (Input.GetKey(jump.keyCodeJump) && jump.jumpstatus == JumpComponent.Jumpstatus.jumping) {
         *              rigbody.MovePosition(Vector3.Lerp(transform.position, new Vector3(transform.position.x, jump.jumpPosition.y + jump.jumpHeight, transform.position.z), jump.jumpTime));
         *      }
         *
         *      if (Input.GetKeyUp(jump.keyCodeJump) && jump.jumpstatus == JumpComponent.Jumpstatus.jumping)
         *      {
         *              rigbody.gravityScale = jump.gravityScale;
         *              jump.jumpstatus = JumpComponent.Jumpstatus.falling;
         *      }
         * });*/

        constraint.ForEachGameObject((egoComponent, transform, rigbody, jump, player, onCollissionEnter, Animator, AnimationComponent, spriteRend, serialPort) => {
            if (jump.canJump && jump.jumpstatus == JumpComponent.Jumpstatus.grounded)
            {
                jump.jumpstatus = JumpComponent.Jumpstatus.jumping;
                Ego.AddComponent <JumpStatus>(egoComponent);
                rigbody.gravityScale = 0;
                jump.jumpPosition    = transform.position;
            }

            if (jump.canJump && jump.jumpstatus == JumpComponent.Jumpstatus.jumping)
            {
                rigbody.MovePosition(Vector3.Lerp(transform.position, new Vector3(transform.position.x, jump.jumpPosition.y + jump.jumpHeight, transform.position.z), jump.jumpTime));
            }

            if (!jump.canJump && jump.jumpstatus == JumpComponent.Jumpstatus.jumping)
            {
                rigbody.gravityScale = jump.gravityScale;
                jump.jumpstatus      = JumpComponent.Jumpstatus.falling;
            }
        });
    }
Exemplo n.º 10
0
 public EntityBuilder WithGraphics(String sprite)
 {
     Ego.AddComponent <SpriteRenderer>(Entity).sprite = Resources.Load(sprite, typeof(Sprite)) as Sprite;
     return(this);
 }
Exemplo n.º 11
0
 public EntityBuilder WithMotion()
 {
     Ego.AddComponent <MovementLimiter>(Entity);
     return(this);
 }