コード例 #1
0
ファイル: Coin.cs プロジェクト: stetar/The-Goodnight-Man
 /// <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);
 }
コード例 #2
0
ファイル: Bullet.cs プロジェクト: stetar/The-Goodnight-Man
        /// <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;
                    }
                }
            }
        }
コード例 #3
0
ファイル: GameWorld.cs プロジェクト: stetar/The-Goodnight-Man
 /// <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;
             }
         }
     }
 }
コード例 #4
0
ファイル: Player.cs プロジェクト: stetar/The-Goodnight-Man
        /// <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);
                }
            }
        }
コード例 #5
0
ファイル: Bullet.cs プロジェクト: stetar/The-Goodnight-Man
        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;
        }
コード例 #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);
 }
コード例 #7
0
 /// <summary>
 /// Base OnCollision
 /// </summary>
 /// <param name="other"></param>
 public virtual void OnCollision(GameObject other)
 {
 }