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

            Ego.AddComponent <Hardpoint>(entity);
            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));
         }
     }
         );
 }
Esempio n. 6
0
 protected override void Undo()
 {
     if (createdNew)
     {
         Ego.DestroyGameObject(child.GetComponent <EgoComponent>());
         parent.childPart = null;
     }
 }
Esempio n. 7
0
 protected void CreateBundle(EgoComponent egoComponent)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component1 = egoComponent.GetComponent <C1>();
         CreateBundle(egoComponent, component1);
     }
 }
Esempio n. 8
0
 // Use this for initialization
 void Start()
 {
     // TODO: Replace with spawning logic
     Ego.AddGameObject(EntityFactory.GeneratePlayer().gameObject);
     Ego.AddGameObject(EntityFactory.GenerateGun().gameObject);
     //Ego.AddGameObject(EntityFactory.generate ("Laser Gun", TemplateEntities.laserGun));
     //EntityFactory.generate ("Zombie", TemplateEntities.zombie).SetActive (true);
 }
Esempio n. 9
0
 protected void CreateBundle(EgoComponent egoComponent, C2 component2)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component1 = egoComponent.GetComponent <C1>();
         var component3 = egoComponent.GetComponent <C3>();
         CreateBundle(egoComponent, component1, component2, component3);
     }
 }
Esempio n. 10
0
    public void Write(BinaryWriter writer)
    {
        Ego.Write(writer);
        Keys.Write(writer);
        Quests.Write(writer);
        Rumors.Write(writer);

        writer.WriteInt32(ActiveTab);
    }
Esempio n. 11
0
 protected void CreateBundle(EgoComponent egoComponent, C3 component3)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component1 = egoComponent.GetComponent <C1>();
         var component2 = egoComponent.GetComponent <C2>();
         var component4 = egoComponent.GetComponent <C4>();
         CreateBundle(egoComponent, component1, component2, component3, component4);
     }
 }
    void DealWithCollision(EgoComponent obstacle, EgoComponent vulnerable)
    {
        SnakePartComponent spc;

        if (vulnerable.TryGetComponents <SnakePartComponent> (out spc))
        {
            spc.childPart.GetComponent <MovementComponent> ().nextMovement    = Vector3.zero;
            spc.childPart.GetComponent <MovementComponent> ().currentMovement = Vector3.zero;
        }
        Ego.DestroyGameObject(vulnerable);
    }
Esempio n. 13
0
    protected override void Undo()
    {
        BoxCollider collider;

        if (edible.TryGetComponents(out collider))
        {
            collider.enabled = false;
            Ego.AddComponent <DelayColliderComponent>(edible);
        }
        edible.gameObject.SetActive(true);
    }
Esempio n. 14
0
 protected void CreateBundle(EgoComponent egoComponent, C1 component1)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component2 = egoComponent.GetComponent <C2>();
         var component3 = egoComponent.GetComponent <C3>();
         var component4 = egoComponent.GetComponent <C4>();
         var component5 = egoComponent.GetComponent <C5>();
         CreateBundle(egoComponent, component1, component2, component3, component4, component5);
     }
 }
Esempio n. 15
0
 protected void CreateBundle(EgoComponent egoComponent, C4 component4)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component1 = egoComponent.GetComponent <C1>();
         var component2 = egoComponent.GetComponent <C2>();
         var component3 = egoComponent.GetComponent <C3>();
         var component5 = egoComponent.GetComponent <C5>();
         var component6 = egoComponent.GetComponent <C6>();
         CreateBundle(egoComponent, component1, component2, component3, component4, component5, component6);
     }
 }
Esempio n. 16
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);
            }
        });
    }
Esempio n. 17
0
        /// <summary>
        /// Set the player object
        /// </summary>
        /// <param name="ego"></param>
        /// <param name="inRoom"></param>
        public void SetEgo(Ego ego, Room inRoom = null)
        {
            if (IsSetupFinalised)
            {
                throw new InvalidOperationException("Cannot set Ego after game state setup is finalised");
            }

            Ego = ego;
            if (inRoom != null)
            {
                Ego.MoveTo(inRoom);
            }
        }
Esempio n. 18
0
 protected void CreateBundle(EgoComponent egoComponent, C6 component6)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component1 = egoComponent.GetComponent <C1>();
         var component2 = egoComponent.GetComponent <C2>();
         var component3 = egoComponent.GetComponent <C3>();
         var component4 = egoComponent.GetComponent <C4>();
         var component5 = egoComponent.GetComponent <C5>();
         var component7 = egoComponent.GetComponent <C7>();
         var component8 = egoComponent.GetComponent <C8>();
         CreateBundle(egoComponent, component1, component2, component3, component4, component5, component6, component7, component8);
     }
 }
Esempio n. 19
0
 void Handle(TickEvent e)
 {
     constraint.ForEachGameObject((egoComponent, delayer, collider) =>
     {
         if (delayer.ready)
         {
             collider.enabled = true;
             Ego.DestroyComponent <DelayColliderComponent>(egoComponent);
         }
         else
         {
             delayer.ready = true;
         }
     });
 }
Esempio n. 20
0
 protected void CreateBundle(EgoComponent egoComponent, C8 component8)
 {
     if (Ego.CanUpdate(_mask, egoComponent.mask))
     {
         var component1  = egoComponent.GetComponent <C1>();
         var component2  = egoComponent.GetComponent <C2>();
         var component3  = egoComponent.GetComponent <C3>();
         var component4  = egoComponent.GetComponent <C4>();
         var component5  = egoComponent.GetComponent <C5>();
         var component6  = egoComponent.GetComponent <C6>();
         var component7  = egoComponent.GetComponent <C7>();
         var component9  = egoComponent.GetComponent <C9>();
         var component10 = egoComponent.GetComponent <C10>();
         CreateBundle(egoComponent, component1, component2, component3, component4, component5, component6, component7, component8, component9, component10);
     }
 }
Esempio n. 21
0
        /// <summary>
        /// Constructor
        /// </summary>
        public GameState()
        {
            IsSetupFinalised = false;

            Items       = new Entities <Item>();
            Rooms       = new Entities <Room>();
            Npcs        = new Entities <Npc>();
            Occurrences = new Entities <Occurrence>();
            Variables   = new Variables();

            WelcomeMessage = "Welcome!";
            Ego            = new Ego("You", "It's just you.");

            Variables.Set("testvar1", "value");
            Variables.Set("test2", 123.456);
        }
        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);
        }
Esempio n. 23
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);
 }
Esempio n. 24
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;
            }
        });
    }
        // Handles Detaching Hardpoint-Mountpoint pairs
        void Handle(DetachEvent e)
        {
            Hardpoint hardpoint;

            if (e.Child.parent.TryGetComponents(out hardpoint))
            {
                e.Child.transform.SetParent(null);
                Ego.SetParent(null, e.Child);
                Rigidbody2D rigidbody2D;

                // Should actually return a rigidbody to their defaults for their dropped state, which is usually this
                if (e.Child.TryGetComponents(out rigidbody2D))
                {
                    rigidbody2D.isKinematic = false;
                    rigidbody2D.simulated   = true;
                }
                hardpoint.Attached = null;
            }
        }
Esempio n. 26
0
 void Handle(CollisionEnter2DEvent e)
 {
     constraint.ForEachGameObject((egoComponent, transform, rigbody, jump, player, onCollissionEnter, Animator, AnimationComponent, spriteRend, serialPort) => {
         //When Player lands on ground
         if (e.egoComponent2.HasComponents <Ground>() && jump.jumpstatus == JumpComponent.Jumpstatus.falling)
         {
             jump.jumpstatus = JumpComponent.Jumpstatus.grounded;
             Ego.DestroyComponent <JumpStatus>(egoComponent);
         }
         //When Player jumps against a plattform
         if (e.egoComponent2.HasComponents <Ground>() && jump.jumpstatus == JumpComponent.Jumpstatus.jumping)
         {
             jump.jumpPosition.y = egoComponent.transform.position.y - jump.jumpHeight;
         }
         //When Player lands on Player
         if (e.egoComponent2.HasComponents <PlayerComponent> () && e.egoComponent1.HasComponents <JumpComponent>())
         {
             if (e.egoComponent1.GetComponent <JumpComponent>().jumpstatus == JumpComponent.Jumpstatus.falling)
             {
                 e.egoComponent1.GetComponent <PlayerComponent>().score++;
                 if (e.egoComponent1.GetComponent <PlayerComponent>().score == 12)
                 {
                     EgoEvents <GameEndEvent> .AddEvent(new GameEndEvent(e.egoComponent1.GetComponent <PlayerComponent>().playerID));
                 }
                 EgoEvents <ScoreEvent> .AddEvent(new ScoreEvent(e.egoComponent1.GetComponent <PlayerComponent>().playerID, e.egoComponent1.GetComponent <PlayerComponent>().score));
                 EgoEvents <PlayerHitEvent> .AddEvent(new PlayerHitEvent());
             }
         }
         if (e.egoComponent1.HasComponents <PlayerComponent> () && e.egoComponent2.HasComponents <JumpComponent>())
         {
             if (e.egoComponent2.GetComponent <JumpComponent>().jumpstatus == JumpComponent.Jumpstatus.falling)
             {
                 e.egoComponent2.GetComponent <PlayerComponent>().score++;
                 if (e.egoComponent2.GetComponent <PlayerComponent>().score == 12)
                 {
                     EgoEvents <GameEndEvent> .AddEvent(new GameEndEvent(e.egoComponent2.GetComponent <PlayerComponent>().playerID));
                 }
                 EgoEvents <ScoreEvent> .AddEvent(new ScoreEvent(e.egoComponent2.GetComponent <PlayerComponent>().playerID, e.egoComponent2.GetComponent <PlayerComponent>().score));
                 EgoEvents <PlayerHitEvent> .AddEvent(new PlayerHitEvent());
             }
         }
     });
 }
        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);
        }
Esempio n. 28
0
        protected override void OnWorldInitialized(bool restore)
        {
            if (restore)
            {
                Tree.Reset(World);
                return;
            }

            ShadowRectangle
            .Create(World);

            Engine.Renderer.GUIManager.ShowSoftwareCursor = false;
            Tree.Reset(World);
            World.Interactive = false;
            Ego.EnterScene(Tree.Basement.SceneID);

            Tree.Actors.Ryan.EnterScene(Tree.Basement.SceneID);
            Tree.Actors.RyanVoice.EnterScene(Tree.Basement.SceneID);
            Tree.Actors.Mouse.EnterScene(Tree.Basement.SceneID);

            Tree.Cutscenes.Director.StartSession(Cutscenes.Sessions.One);
        }
        // Handles Attaching Hardpoint-Mountpoint pairs
        void Handle(AttachEvent e)
        {
            Hardpoint  hardpoint;
            Mountpoint mountpoint;

            if (e.Parent != e.Child && e.Parent.TryGetComponents(out hardpoint) && e.Child.TryGetComponents(out mountpoint))
            {
                e.Child.transform.SetParent(e.Parent.transform);
                Ego.SetParent(e.Parent, e.Child);
                e.Child.transform.localRotation = Quaternion.AngleAxis(mountpoint.LocalRotation, Vector3.forward);
                e.Child.transform.localPosition = hardpoint.LocalVector2D + mountpoint.LocalVector2D;

                // Makes sure attached body doesn't change parent's center of gravity or mass, and doesn't collide with the parent
                Rigidbody2D rigidbody2D;
                if (e.Child.TryGetComponents(out rigidbody2D))
                {
                    rigidbody2D.isKinematic = true;
                    rigidbody2D.simulated   = false;
                }

                hardpoint.Attached = mountpoint.GetComponent <EgoComponent>();
            }
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            // Employee example
            //Employee employee1 = new TeamMember("Paul", 8000);
            //Employee employee2 = new TeamMember("Jack", 30000);
            //Employee teamLeader = new TeamLeader("Marg", 750000);

            //teamLeader.Add(employee1);
            //teamLeader.Add(employee2);

            //Console.WriteLine(teamLeader.GetData());


            // Motorbike example
            //IMotorbike baseClass = new Motorbike();
            //IMotorbike customObject = baseClass;

            //customObject.StartEngine();
            //customObject = new Triumph(baseClass);
            //customObject.StartEngine();
            //customObject.PowerOnLights();
            //customObject = new HarleyDavidson(baseClass);
            //customObject.PowerOnLights();

            // ECigarette example
            IECigarette eCigarette = new ECigarette();

            Console.WriteLine("Price for regular cig: " + eCigarette.GetPrice().ToString());
            eCigarette = new Ego(eCigarette);
            Console.WriteLine("Price for Ego cig: " + eCigarette.GetPrice().ToString());
            eCigarette = new VapingShelter(eCigarette);
            Console.WriteLine("Price for VapingShelter cig: " + eCigarette.GetPrice().ToString());
            eCigarette = new TheatricalFake(eCigarette);
            Console.WriteLine("Price for TheatricalFake cig: " + eCigarette.GetPrice().ToString());

            Console.Read();
        }