Ejemplo n.º 1
0
 /// <summary>
 /// Handles the collision of the coin
 /// </summary>
 /// <param name="other"></param>
 public override void OnCollision(GameObject other)
 {
     if (other is Player && canPickup)
     {
         GameWorld.iIncorrectness += 1;
         GameWorld.removeList.Add(this);
     }
     base.OnCollision(other);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the collision for the bullet
        /// </summary>
        /// <param name="other"></param>
        public override void OnCollision(GameObject other)
        {
            if (other is Crate || other is Bridge)
            {
                GameWorld.removeList.Add(this);
            }

            if (Enemy.currentEnemyWeapon is EnemyRPG)
            {
                if (hasAttacked)
                {
                    if (!(other is Enemy || other is Weapon || other is Sky))
                    {
                        GameWorld.removeList.Add(this);
                        GameWorld.objects.Add(new Explosion(new Vector2D(this.position.X - (sprite.Width / 2), this.position.Y - (sprite.Height / 2)), 1));
                        hasAttacked = false;
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Resolves collisions of two game objects.
 /// </summary>
 /// <param name="rigidbody">Player</param>
 /// <param name="b"></param>
 private void ResolveAABBCollision(GameObject rigidbody, GameObject b)
 {
     RectangleF result = RectangleF.Intersect(rigidbody.CollisionBox, b.CollisionBox);
     if (result.Width > 0 || result.Height > 0)
     {
         Vector2D rigidbodyCenter = new Vector2D(
             rigidbody.CollisionBox.Left + rigidbody.CollisionBox.Width * 0.5f,
             rigidbody.CollisionBox.Top + rigidbody.CollisionBox.Height * 0.5f
         );
         if (result.Height > result.Width)
         //resolve horisontally
         {
             float distanceFromRight = Math.Abs(rigidbodyCenter.X - b.CollisionBox.Right);
             float distanceFromLeft = Math.Abs(rigidbodyCenter.X - b.CollisionBox.Left);
             if (distanceFromRight > distanceFromLeft)
             {
                 // Go left
                 rigidbody.Position.X -= result.Width;
             }
             else
             {
                 // Go right
                 rigidbody.Position.X += result.Width;
             }
         }
         else
         {
             float distanceFromTop = Math.Abs(rigidbodyCenter.Y - b.CollisionBox.Top);
             float distanceFromBottom = Math.Abs(rigidbodyCenter.Y - b.CollisionBox.Bottom);
             if (distanceFromTop < distanceFromBottom)
             {
                 // Go up
                 rigidbody.Position.Y -= result.Height;
                 Player.isGrounded = true;
                 if (Player.velocity.Y > 0) // Don't pull player down
                 {
                     Player.velocity.Y = 0;
                 }
             }
             else
             {
                 // Go down
                 //Player.isGrounded = false;
                 //Don't make the position go down as we go below the map
                 rigidbody.Position.Y += result.Height;
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks the player's collision each tick, only called on actual collision.
        /// </summary>
        /// <param name="other"></param>
        public override void OnCollision(GameObject other)
        {
            if (other is Bullet)
            {
                health -= Enemy.currentEnemyWeapon.damage;
                GameWorld.removeList.Add(other);
            }

            if (other is Explosion)
            {
                if (!Explosion.damageTaken)
                {
                    health -= Enemy.currentEnemyWeapon.damage;
                    Explosion.damageTaken = true;
                }
            }

            if (health <= 0)
            {
                Form1.timer1.Stop();
                GameWorld.eng.StopAllSounds();
                DialogResult dialogResult = MessageBox.Show("You got yourself killed, you idiot! What the hell kinda retarded move is that? Do you even know how to play video games? Just click yes to return to the main menu, scrub. Or you can just quit now. That wouldn't suprise me at all, since you're such a f*****g c**t!", "Game f*****g over!", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    GameWorld.objects.Clear();
                    GameWorld.GameWeapons.Clear();
                    GameWorld.removeList.Clear();
                    Form1.ActiveForm.Hide();
                    new MainMenuForm().Show();
                }
                else if (dialogResult == DialogResult.No)
                {
                    Environment.Exit(0);
                }
            }
        }
Ejemplo n.º 5
0
        private Vector2D velocity; //for storing the value

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor for the bullet.
        /// </summary>
        /// <param name="imagePath"></param>
        /// <param name="startPos"></param>
        /// <param name="scaleFactor"></param>
        /// <param name="speed">Bullet speed</param>
        /// <param name="player">Player to follow</param>
        public Bullet(string imagePath, Vector2D startPos, float scaleFactor, float speed, GameObject player)
            : base(imagePath, startPos, scaleFactor)
        {
            this.player = player;
            this.speed = speed;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns true if GameObject's collision box is colliding
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool IsCollidingWith(GameObject other)
 {
     return CollisionBox.IntersectsWith(other.CollisionBox);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Base OnCollision
 /// </summary>
 /// <param name="other"></param>
 public virtual void OnCollision(GameObject other)
 {
 }