Esempio n. 1
0
 public Collision(PhysicsEntity entity, GameObject gameObject, CollisionSide side)
 {
     this.entity             = entity;
     this.gameObject         = gameObject;
     collideArray            = new bool[4];
     collideArray[(int)side] = true;
 }
Esempio n. 2
0
        public override void OnCollide(PhysicsEntity other)
        {
            if (other is Player)
            { //not instadeath
              //if (gameTime.TotalGameTime.TotalSeconds - lastAttackTime > 3)
              //{

                //    AttackPlayer();
                //    lastAttackTime = gameTime.TotalGameTime.TotalSeconds;
                //}
                //instadeath
                if (!onGround)
                {
                    if (player.Y + player.Rect.Height - 8 <= rectangle.Y)
                    {
                    }
                    else
                    {
                        player.PState = PlayerState.Dead;
                    }
                }
                else
                if (player.Y + 4 >= rectangle.Y + rectangle.Height)
                {
                }
                else
                {
                    player.PState = PlayerState.Dead;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// On Collision with player, change rooms.
 /// </summary>
 public override void OnCollide(PhysicsEntity other)
 {
     if (other is Player)
     {
         (other as Player).DoorInRange = this;
     }
 }
Esempio n. 4
0
 private void AdjustSize(PhysicsEntity other)
 {
     if (parent == null)
     {
         return;
     }
 }
Esempio n. 5
0
 public override void OnCollide(PhysicsEntity other)
 {
     if (other is Player)//if other is player(will only be on top or bottom) bounces player
     {
         if (player.Y + player.Rect.Height + 3 < Y + 5)
         {
             player.AddForce(new Vector2(0, -700));
         }
         //collide with player
         //if (player.Y + player.Rect.Height == Y + rectangle.Height)
         //{
         //    X = (player.X + player.Rect.Width <= X + 3) ? player.X + player.Rect.Width : player.X - rectangle.Width;
         //    velocity = Vector2.Zero;
         //    drag = true;
         //}
     }
     //{
     //enemyState = (enemyState == EnemyState.FaceLeft) ? EnemyState.FaceRight : EnemyState.FaceLeft;
     //}
     //else
     //{
     //    //if (player.Y + player.Rect.Height == Y + rectangle.Height)
     //    //    X = (player.X + player.Rect.Width <= X + 3) ? player.X + player.Rect.Width : player.X - rectangle.Width;
     //    //velocity = Vector2.Zero;
     //    //drag = true;
     //}
 }
Esempio n. 6
0
 public EffectBox(int x, int y, int width, int height, Vector2 accelerationChange, Texture2D texture = null)
     : base(x, y, width, height, texture, null, false)
 {
     this.accelerationChange = accelerationChange;
     parent         = null;
     originalRect   = new Rectangle(x, y, width, height);
     PositionLocked = true;
 }
Esempio n. 7
0
 public EffectBox(int x, int y, int width, int height, Vector2 accelerationChange, PhysicsEntity parent, Texture2D texture = null)
     : base(x, y, width, height, texture, null, false)
 {
     this.accelerationChange = accelerationChange;
     this.parent             = parent;
     PositionLocked          = true;
     parentCentrer           = parent.Rect.Center;
     originalRect            = new Rectangle(x, y, width, height);
 }
Esempio n. 8
0
        public override void OnCollide(PhysicsEntity other)
        {
            other.AddForce(accelerationChange);
            if (HasParent)
            {
                parent.OnCollide(other);

                /* having problems
                 * if (other.Rect.Contains(parent.Rect))
                 * {
                 *  X = parentCentrer.X;
                 *  Y = parentCentrer.Y;
                 *  rectangle.Width = 0;
                 *  rectangle.Height = 0;
                 *  return;
                 * }
                 * if (other.X >= parentCentrer.X && other.X < rectangle.Width + X && other.X > X)
                 * {
                 *  rectangle.Width = X + (other.X - X);
                 * }
                 * else if (other.X >= parentCentrer.X && other.X + other.Rect.Width > X && other.X < X)
                 * {
                 *  rectangle.Width = 0;
                 * }
                 * else if (other.X + other.Rect.Width <= parentCentrer.X && other.X + other.Rect.Width < rectangle.Width + X && other.X + other.Rect.Width > X)
                 * {
                 *  rectangle.Width = other.X + other.Rect.Width + ((X+rectangle.Width) - (other.X + other.Rect.Width));
                 *  rectangle.X = other.X + other.Rect.Width;
                 * }
                 * else if (other.X + other.Rect.Width <= parentCentrer.X && other.X + other.Rect.Width > X + rectangle.Width && other.X > X)
                 * {
                 *  rectangle.Width = 0;
                 * }
                 *
                 * if (other.Y >= parentCentrer.Y && other.Y < rectangle.Height + Y && other.Y > Y)
                 * {
                 *  rectangle.Height = Y + (other.Y - Y);
                 * }
                 * else if (other.Y >= parentCentrer.Y && other.Y + other.Rect.Height > Y && other.Y < Y)
                 * {
                 *  rectangle.Height = 0;
                 * }
                 *
                 * else if (other.Y + other.Rect.Height <= parentCentrer.Y && other.Y + other.Rect.Height < rectangle.Height + Y && other.Y + other.Rect.Height > Y)
                 * {
                 *  rectangle.Height = other.Y + other.Rect.Height + ((Y + rectangle.Height) - (other.Y + other.Rect.Height));
                 *  rectangle.Y = other.Y + other.Rect.Height;
                 * }
                 * else if (other.Y + other.Rect.Height <= parentCentrer.Y && other.Y + other.Rect.Height > Y + rectangle.Height && other.Y > Y)
                 * {
                 *  rectangle.Height = 0;
                 * }
                 */
            }
        }
Esempio n. 9
0
 public void RemoveChild(PhysicsEntity child)
 {
     if (children.Contains(child))
     {
         children.Remove(child);
     }
     if (children.Count < maxSpawns && (type != EntityType.bottle || infinitePickups))
     {
         canSpawn = true;
     }
 }
Esempio n. 10
0
        public bool OnGround(PhysicsEntity p)
        {
            float pBottom = (p.Y + p.Rect.Height) + 5;

            for (int i = 0; i < objects.Count; i++)
            {
                if ((pBottom) >= objects[i].Y && (pBottom) < (objects[i].Rect.Height + objects[i].Y))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 11
0
 public override void OnCollide(PhysicsEntity other)
 {
     if (Game1.RumbleMode && other is Player)
     {
         falling = true;
     }
     if (rumble)
     {
         if (other is Bottle)
         {
             RoomManager.GetRoomManager.Current.Colliders.Remove(this);
             RoomManager.GetRoomManager.Current.Enemies.Remove(this);
             RoomManager.GetRoomManager.Current.Drawable.Remove(this);
         }
     }
 }
Esempio n. 12
0
 public override void OnCollide(PhysicsEntity other)
 {
     if (other is Player)
     {
         if (player.Y + player.Rect.Height == Y + rectangle.Height)
         {
             X = (player.X <= X) ? player.X + player.Rect.Width : player.X - rectangle.Width;
         }
         if (gameTime.TotalGameTime.TotalSeconds - lastAttackTime > 1.5)//if it has been 1.5 seconds since the last attack, attack
         {
             AttackPlayer();
             lastAttackTime = gameTime.TotalGameTime.TotalSeconds;
         }
     }
     if (other is Enemy)
     {
     }
 }
Esempio n. 13
0
 public override void OnCollide(PhysicsEntity other)
 {
     base.OnCollide(other);
     if (!isThrowButton)
     {
         if (other is Player)
         {
             playerInRange = true;
             (other as Player).ButtonInRange = this;
         }
     }
     else
     {
         if (other is Bottle)
         {
             PressButton();
         }
     }
 }
Esempio n. 14
0
        /// <summary>
        /// when this bottle collides with some other physics entity
        /// </summary>
        /// <param name="other">the physics entity it has collided with</param>
        public override void OnCollide(PhysicsEntity other)
        {
            if (other is Player)//if the other object is the player, give the bottle to the player and no longer draw it
            {
                drawing      = false;
                isCollidable = false;
                player.bottlesOnHand++;
                player.Color = Color.DarkGreen;
                rm.Current.Colliders.Remove(this);
                rm.Current.Enemies.Remove(this);
                EntityIsRemoved();
            }
            if (thrown)//if it has been thrown determine what it has collided with and deal with it accordingly
            {
                if (!(other is EffectBox) && !(other is Button) && !(other is Player) && !(other is Fan) && !(other is Bottle) && !(other is Spikes) && (other.IsCollidable))
                {
                    drawing      = false;
                    isCollidable = false;
                    thrown       = false;
                    rm.Current.Colliders.Remove(this);
                    rm.Current.Enemies.Remove(this);
                }
                if (!(other is ForegroundTile) && !(other is Spikes) && !(other is PhaseBlock))
                {
                    if (other is PhysicsEntity && !(other is Player))
                    {
                        if (other is Enemy && !(other is Door))
                        {
                            (other as Enemy).GetHit();
                        }
                        other.acceleration = Vector2.Zero;
                        other.velocity     = new Vector2(this.velocity.X, 0);

                        other.AddForce(new Vector2((this.X < other.X) ? 5000 : -5000, 0));
                    }
                }
            }
        }
Esempio n. 15
0
 public virtual void OnCollide(PhysicsEntity other)
 {
     // Manage collision with other entities
 }
Esempio n. 16
0
        public void DetectCollisions()
        {
            bool newCollision;

            if (objects != null)
            {
                for (int i = 0; i < entities.Count; i++)
                {
                    newCollision = true;

                    physEntity = entities[i];//if it hasn't move, it won't have new collisions, if somehting hits it, that entity will take care of collision
                    if (physEntity.X == physEntity.PrevX && physEntity.Y == physEntity.PrevY)
                    {
                        newCollision = false;
                    }
                    // Reset collision array
                    physEntity.colliderArray[0] = false;
                    physEntity.colliderArray[1] = false;
                    physEntity.colliderArray[2] = false;
                    physEntity.colliderArray[3] = false;

                    // Calculate the bottom and right side locations for the physEntity
                    float entBottom = physEntity.Y + physEntity.Rect.Height;
                    float entRight  = physEntity.X + physEntity.Rect.Width;
                    float entTop    = physEntity.Y;
                    float entLeft   = physEntity.X;

                    for (int j = 0; j < objects.Count; j++)
                    {
                        gameObject = objects[j];

                        if (gameObject == physEntity)
                        {
                            continue;
                        }
                        if (gameObject is Bottle && physEntity is Bottle)
                        {
                            continue;
                        }
                        if (((gameObject is Door || gameObject is Button || gameObject is EffectBox) && physEntity is Player) || (gameObject is Player && (physEntity is Door || physEntity is Button || gameObject is EffectBox)))
                        {
                        }
                        else if (Game1.developerMode && (gameObject is Player || physEntity is Player))
                        {
                            continue;
                        }

                        // Calculate the bottom and right side locations for the gameObject
                        float objBottom = gameObject.Y + gameObject.Rect.Height;
                        float objRight  = gameObject.X + gameObject.Rect.Width;

                        // Check distances between the sides of the objects.
                        float tDistance = objBottom - entTop;
                        float bDistance = entBottom - gameObject.Y;
                        float rDistance = entRight - gameObject.X;
                        float lDistance = objRight - entLeft;

                        // Whichever side is closest is the side they are colliding on.
                        if (physEntity.Rect.Intersects(gameObject.Rect))
                        {
                            if ((gameObject is HoppingEnemy || gameObject is Ooze) && (physEntity is HoppingEnemy || physEntity is Ooze))
                            {
                                continue;
                            }

                            gameObject.OnCollide(physEntity);
                            physEntity.OnCollide(gameObject);
                            if (gameObject is Door)//stops nast problems from happening during room spawn, should  be changed in case of like locked doors or something
                            {
                                continue;
                            }
                            if (!gameObject.IsCollidable)
                            {
                                continue;
                            }
                            if (gameObject == physEntity)
                            {
                                continue;
                            }
                            if ((gameObject is Player && physEntity is Button) || (gameObject is Button && physEntity is Player))
                            {
                                continue;
                            }
                            //below, sets collide array and creates new collision object
                            //TOP
                            if (tDistance < bDistance && tDistance < lDistance && tDistance < rDistance)
                            {
                                physEntity.colliderArray[0] = true;
                                if (physEntity.Y != physEntity.PrevY && newCollision)
                                {
                                    collisions.Add(new Collision(physEntity, gameObject, CollisionSide.top));
                                }
                            }

                            //RIGHT
                            else if (rDistance < bDistance && rDistance < lDistance && rDistance < tDistance)
                            {
                                if ((gameObject is Player && physEntity is Ooze) || (gameObject is Ooze && physEntity is Player))
                                {
                                }
                                else
                                {
                                    physEntity.colliderArray[1] = true;
                                    if (physEntity.X != physEntity.PrevX && newCollision)
                                    {
                                        collisions.Add(new Collision(physEntity, gameObject, CollisionSide.right));
                                    }
                                }
                            }

                            //BOTTOM
                            else if (bDistance < tDistance && bDistance < lDistance && bDistance < rDistance)
                            {
                                physEntity.colliderArray[2] = true;
                                if (physEntity.Y != physEntity.PrevY && newCollision)
                                {
                                    collisions.Add(new Collision(physEntity, gameObject, CollisionSide.bottom));
                                }
                            }

                            //LEFT
                            else if (lDistance < bDistance && lDistance < tDistance && lDistance < rDistance)
                            {
                                if ((gameObject is Player && physEntity is Ooze) || (gameObject is Ooze && physEntity is Player))
                                {
                                }
                                else
                                {
                                    physEntity.colliderArray[3] = true;
                                    if (physEntity.X != physEntity.PrevX && newCollision)
                                    {
                                        collisions.Add(new Collision(physEntity, gameObject, CollisionSide.left));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }