Ejemplo n.º 1
0
        internal void Begin()
        {
            //
            // mmGame calls Begin() before a new scene window is created
            //
            SceneColliderDatabase.Initialize();

            //
            // Allow Entitas to init systems, auto collect matched systems, no manual Systems.Add(ISystem) required
            //
            EntitySystems = new Entitas.Feature(null);                           //game entities
            EntitySystems.Initialize();

            //SceneSystems = new Entitas.Feature(null);               //scene UI entities
            //SceneSystems.Initialize();
            OnStart();
        }
 public override void Update(float deltaTime)
 {
     base.Update(deltaTime);
     //
     // Has Entity been assigned yet?
     //
     if (CompEntity == null)
     {
         return;
     }
     if (!Enabled)
     {
         return;
     }
     //
     // update location of box containing the collider
     //
     if (!fixedCollider)
     {
         boxContainer.x = Transform.Position.X - OriginLocal.X;
         boxContainer.y = Transform.Position.Y - OriginLocal.Y;
         BoxPoints      = new List <Vector2>();
         Vector2 topL = new Vector2(boxContainer.x, boxContainer.y);
         Vector2 topR = new Vector2(topL.X + boxContainer.width, topL.Y);
         Vector2 botL = new Vector2(topL.X, topL.Y + boxContainer.height);
         Vector2 botR = new Vector2(topR.X, topR.Y + boxContainer.height);
         BoxPoints.Add(topL);
         BoxPoints.Add(botL);
         BoxPoints.Add(botR);
         BoxPoints.Add(topR);
         //
         // Find the min & max vectors for collision
         //
         CollisionBox.Fit(BoxPoints);                                //updates the position of this collider
     }
     if (!setSceneColliders)
     {
         //
         // update the database of colliders in this scene (happens only once)
         //
         SceneColliderDatabase.SetCollider(CompEntity, CollidreShape.Box);
         setSceneColliders = true;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add an entity/children to be destroyed after Scene Update/Render is done
 /// </summary>
 /// <param name="entity"></param>
 public static void DestroyGameEntity(Entity entity)
 {
     //
     // All children added first (to be removed)
     //
     if (entity.Get <Transform>().ChildCount > 0)
     {
         foreach (Component child in entity.Get <Transform>().Children)
         {
             GameEntityToDestroy.TryAdd(child.CompEntity, true);
             SceneColliderDatabase.RemoveCollider(child.CompEntity);
         }
     }
     //
     // Add entity to be removed
     //
     GameEntityToDestroy.TryAdd(entity, true);
     SceneColliderDatabase.RemoveCollider(entity);
 }
Ejemplo n.º 4
0
        public override void Update(float deltaTime)
        {
            base.Update(deltaTime);
            //
            // Has Entity been assigned yet?
            //
            if (CompEntity == null)
            {
                return;
            }
            //
            // update location of box containing the collider
            //
            boxContainer.x = Transform.Position.X;
            boxContainer.y = Transform.Position.Y;
            BoxPoints      = new List <Vector2>();
            Vector2 topL = new Vector2(boxContainer.x, boxContainer.y - Radius);                        //north
            Vector2 topR = new Vector2(boxContainer.x - Radius, boxContainer.y);                        //west
            Vector2 botL = new Vector2(boxContainer.x + Radius, boxContainer.y);                        //east
            Vector2 botR = new Vector2(boxContainer.x, boxContainer.y + Radius);                        //south

            BoxPoints.Add(topL);
            BoxPoints.Add(botL);
            BoxPoints.Add(botR);
            BoxPoints.Add(topR);
            //
            // Find the min & max vectors for collision
            //
            CollisionBox.Fit(BoxPoints);                                //updates the position of this collider

            if (!setScenColliders)
            {
                //
                // update the database of colliders in this scene (happens only once)
                //
                SceneColliderDatabase.SetCollider(CompEntity, CollidreShape.Circle);
                setScenColliders = true;
            }
        }
        private void Move(Vector2 motion)
        {
            MoveCollisionResult = new CollisionResult();
            Transform.Position += motion * this.Speed * Global.DeltaTime;

            if (SceneColliderDatabase.CollidedWithBox(CompEntity, out MoveCollisionResult))
            {
                //
                // continue moving if both entities that hit eachother
                // are either enemies or friends
                //
                if (CompEntity.IsEnemy && MoveCollisionResult.CompEntity.IsEnemy)
                {
                    return;                                             //both enemy
                }
                if (!CompEntity.IsEnemy && !MoveCollisionResult.CompEntity.IsEnemy)
                {
                    return;                                 //both friends
                }
                this.IsMoving = false;                      // stop moving(enemy hit a friendly OR friendly hit an enemy
            }
            return;
        }