Exemple #1
0
 public override void OnCollision(RigidBody body)
 {
     if (body.GameObject.GetComponent<Player>() != null)
     {
         GameManager.Instance.EndMessage = "YOU WON!";
         // stop the game!
         Scene.CurrentState = GameState.End;
     }
     base.OnCollision(body);
 }
Exemple #2
0
        public override void OnCollision(RigidBody body)
        {
            var p = body.GameObject.GetComponent<Player>();
            var e = body.GameObject.GetComponent<Enemy>();

            if (p != null)
            {
                // if we collided with the player, give him health
                p.Health += HealthGain;
                Scene.DestroyObject(GameObject);
            }

            // enemies can pick them up as well
            if (e != null)
            {
                e.Health += HealthGain;
                Scene.DestroyObject(GameObject);
            }
        }
Exemple #3
0
        public override void OnCollision(RigidBody body)
        {
            // they be zombies!
            var player = body.GameObject.GetComponent<Player>();
            var bullet = body.GameObject.GetComponent<Bullet>();

            if (bullet != null)
            {
                // damage self
                // TODO: This should probably be handled by the bullet, not the enemy
                Health -= bullet.Damage;
                if (Health <= 0)
                {
                    if (bullet.ShotBy != null)
                    {
                        GameManager.Instance.AddScore(bullet.ShotBy.Index, 10);
                    }
                    Scene.DestroyObject(GameObject);
                    SpawnBlood();
                }
            }
            else if (player != null)
            {
                // damage player
                if ((DateTime.Now - _lastDamageTime).TotalSeconds > TimeBetweenDamage)
                {
                    // nom nom
                    player.Health -= Damage;
                    if (player.Health <= 0)
                    {
                        GameManager.Instance.EndMessage = "YOU LOST";
                        Scene.Instance.CurrentState = GameState.End;
                    }
                    _lastDamageTime = DateTime.Now;
                }
            }
        }
Exemple #4
0
 public virtual void OnCollision(RigidBody body) 
 {
     
 }
Exemple #5
0
 public override void OnCollision(RigidBody body)
 {
     Scene.DestroyObject(GameObject);
 }
Exemple #6
0
 public RectangleF CheckForCollisions(RigidBody col, RectangleF rect, out RigidBody x)
 {
     foreach (GameObject o in _sceneObjects)
     {
         RigidBody collider = o.GetComponent<RigidBody>();
         if (collider != null)
         {
             if (collider != col)
             {
                 RectangleF result = RectangleF.Overlap(rect, collider.Box);
                 if(!result.IsEmpty)
                 {
                     x = collider;
                     return result;
                 }
             }
         }
     }
     x = null;
     return RectangleF.Empty;
 }
Exemple #7
0
        public RectangleF CheckForCollisions(RigidBody col, out RigidBody x)
        {
            foreach(GameObject o in _sceneObjects)
            {
                RigidBody collider = o.GetComponent<RigidBody>();
                if (collider != null)
                {
                    if(collider != col)
                    {
                        RectangleF result = RectangleF.Overlap(collider.Box, col.Box);
                        if (!result.IsEmpty)
                        {
                            x = collider;
                            return result;
                        }
                    }
                }
            }

            x = null;
            return RectangleF.Empty;

            //for(int i = 0; i < boxes.Count; i++)
            //{
            //    BoxCollider current = boxes[i];

            //    for(int j = 0; j < boxes.Count; j++)
            //    {
            //        if (j == i)
            //            continue;

            //        if(current.Box.Intersects(boxes[j].Box))
            //        {
            //            //alert both of those components
            //            current.GameObject.OnCollision(boxes[j]);
            //            boxes[j].GameObject.OnCollision(current);
            //        }
            //    }
            //}
        }
Exemple #8
0
 public override void OnCollision(RigidBody body)
 {
     if (GameObject.RigidBody.Colliding)
     {
         _jumping = false;
     }
 }