Example #1
0
        /// <summary>
        /// Checks if rotRectangle blocks the Path from position in direction
        /// </summary>
        /// <param name="position"></param>
        /// <param name="direction"></param>
        /// <param name="rotRectangle"></param>
        /// <returns></returns>
        public static bool CheckCollision(Vector2 position, Vector2 direction, float width, RotRectangle rotRectangle)
        {
            //Vector2 direction = target - position;
            float        angle = (float)Math.Atan(direction.Y / direction.X);
            RotRectangle line  = new RotRectangle(0, position + direction / 2, new Vector2(direction.Length() / 2, width / 2));

            line.Rotate(angle);
            return(CheckCollision(rotRectangle, line));
        }
Example #2
0
 private bool CheckCollisions(RotRectangle hitbox)
 {
     //if (worldObjects.Count == 0) return false;
     foreach (RotRectangle playerSpawnPosition in spawnPositons)
     {
         if (CollisionCheck.CheckCollision(hitbox, playerSpawnPosition))
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
        public Animation(AnimationType animationType, RotRectangle hitbox)
        {
            this.animationType = animationType;
            timeExisting       = new TimeSpan(0, 0, 0, 0, 0);
            this.hitbox        = hitbox;


            currentFrame = 0;

            switch (animationType)
            {
            case AnimationType.Explosion:
                repeating   = false;
                frameTime   = new TimeSpan(0, 0, 0, 0, 100);
                frameCount  = 11;
                spritesheet = TextureCollection.Instance.GetTexture(TextureType.Explosion_Animation);
                break;

            case AnimationType.Flamethrower:
                repeating   = true;
                frameTime   = new TimeSpan(0, 0, 0, 0, 100);
                frameCount  = 10;
                spritesheet = TextureCollection.Instance.GetTexture(TextureType.Active_FlamethrowerAnimation);
                break;

            case AnimationType.Zombie_Slow:
                repeating   = true;
                frameTime   = new TimeSpan(0, 0, 0, 0, 150);
                frameCount  = 8;
                spritesheet = TextureCollection.Instance.GetTexture(TextureType.Enemy_Zombie_Slow_Animation);
                break;

            case AnimationType.Zombie_Fast:
                repeating   = true;
                frameTime   = new TimeSpan(0, 0, 0, 0, 150);
                frameCount  = 8;
                spritesheet = TextureCollection.Instance.GetTexture(TextureType.Enemy_Zombie_Fast_Animation);
                break;

            case AnimationType.Shockwave:
                repeating   = false;
                frameCount  = 7;
                frameTime   = new TimeSpan(0, 0, 0, 0, 500 / 7);
                spritesheet = TextureCollection.Instance.GetTexture(TextureType.Active_ShockwaveAnimation);
                break;
            }

            animationOffset = new Vector2((spritesheet.Width / frameCount) / 2, spritesheet.Height / 2);
        }
Example #4
0
        public TrapLauncher(Scene scene, Player player, int objectID) : base(scene, player, objectID)
        {
            damage                       = 200;
            resetLivingTimer             = 8;
            resetActivationCooldownTimer = 5;

            texture    = TextureCollection.Instance.GetTexture(TextureType.Active_Trap);
            hitbox     = new RotRectangle(0, player.Hitbox.Center, new Vector2(texture.Width / 2, texture.Height / 2));
            isExploded = false;

            explosionAnimation = new Animation(AnimationType.Explosion, hitbox);
            soundExplosion     = SoundCollection.Instance.GetSoundInstance(SoundType.RocketLauncher_Explosion);
            soundTrapLaunch    = SoundCollection.Instance.GetSoundInstance(SoundType.Trap_Launch);
            UpdateVolume();
        }
Example #5
0
        public FlameThrower(Scene scene, Player player, int objectID) : base(scene, player, objectID)
        {
            damage = 400;
            resetActivationCooldownTimer = 6;
            resetLivingTimer             = 4;
            damagePerTick = (int)(damage / (resetLivingTimer * 4));

            texture = TextureCollection.Instance.GetTexture(TextureType.Active_FlameThrower);
            hitbox  = new RotRectangle(0, new Vector2((player.Hitbox.Corners[1].X + player.Hitbox.Corners[2].X) / 2, player.Hitbox.Corners[2].Y - texture.Height / 2), new Vector2(texture.Width / 2, texture.Height / 2));

            damageTick = false;
            tickTimer  = new TimeSpan(0, 0, 0, 0, 0);
            soundFlame = SoundCollection.Instance.GetSoundInstance(SoundType.FlameThrower);
            UpdateVolume();
            animation = new Animation(AnimationType.Flamethrower, hitbox);
        }
Example #6
0
        public Shockwave(Scene scene, Player player, int objectID) : base(scene, player, objectID)
        {
            damage = 70;
            resetActivationCooldownTimer = 2.5f;
            resetLivingTimer             = 0.5f;
            collidedEntities             = new List <Entity>();

            textureShockwave = TextureCollection.Instance.GetTexture(TextureType.Active_Shockwave);


            soundShockWave = SoundCollection.Instance.GetSoundInstance(SoundType.Shockwave);
            UpdateVolume();
            hitbox    = new RotRectangle(player.Hitbox.RotationRad, player.Hitbox.Center, new Vector2(textureShockwave.Width / 2, textureShockwave.Height / 2));
            animation = new Animation(AnimationType.Shockwave, hitbox);
            // animation = new Animation(AnimationType.Explosion, new RotRectangle(hitbox.RotationRad, hitbox.Center /* -offset */, new Vector2(textureExplosion.Width / 2, textureExplosion.Height / 2)));
        }
Example #7
0
        /// <summary>
        /// Checks Collision of two rotated Rectangles
        /// </summary>
        /// <param name="r1"></param>
        /// <param name="r2"></param>
        /// <returns>True, if there is a collision</returns>
        public static bool CheckCollision(RotRectangle r1, RotRectangle r2)
        {
            //Check if they are not in range of each other
            if (r1.Offset.Length() + r2.Offset.Length() < (r1.Center - r2.Center).Length())
            {
                return(false);
            }
            else
            {
                //If they are in range of each other
                //Use the seperating axis theorem (SAT) to check if they collide
                Vector2 r1Axis1 = r1.Corners[3] - r1.Corners[0];
                Vector2 r1Axis2 = r1.Corners[1] - r1.Corners[0];
                Vector2 r2Axis1 = r2.Corners[3] - r2.Corners[0];
                Vector2 r2Axis2 = r2.Corners[1] - r2.Corners[0];

                //for each axis
                //project the Corners of both rectangles on the axis and check if there is a gap between them
                //if there is a gap then there is no colission
                List <float> valuesR1 = new List <float>();
                List <float> valuesR2 = new List <float>();
                //r1Axis1
                for (int i = 0; i < 4; i++)
                {
                    valuesR1.Add(Vector2.Dot(r1.Corners[i], r1Axis1) / r1Axis1.LengthSquared());
                }
                for (int i = 0; i < 4; i++)
                {
                    valuesR2.Add(Vector2.Dot(r2.Corners[i], r1Axis1) / r1Axis1.LengthSquared());
                }
                if (valuesR1.Min() > valuesR2.Max() || valuesR1.Max() < valuesR2.Min())
                {
                    return(false);
                }
                //r1Axis2
                valuesR1.Clear();
                valuesR2.Clear();
                for (int i = 0; i < 4; i++)
                {
                    valuesR1.Add(Vector2.Dot(r1.Corners[i], r1Axis2) / r1Axis2.LengthSquared());
                }
                for (int i = 0; i < 4; i++)
                {
                    valuesR2.Add(Vector2.Dot(r2.Corners[i], r1Axis2) / r1Axis2.LengthSquared());
                }
                if (valuesR1.Min() > valuesR2.Max() || valuesR1.Max() < valuesR2.Min())
                {
                    return(false);
                }

                //r2Axis1
                valuesR1.Clear();
                valuesR2.Clear();
                for (int i = 0; i < 4; i++)
                {
                    valuesR1.Add(Vector2.Dot(r1.Corners[i], r2Axis1) / r2Axis1.LengthSquared());
                }
                for (int i = 0; i < 4; i++)
                {
                    valuesR2.Add(Vector2.Dot(r2.Corners[i], r2Axis1) / r2Axis1.LengthSquared());
                }
                if (valuesR1.Min() > valuesR2.Max() || valuesR1.Max() < valuesR2.Min())
                {
                    return(false);
                }

                //r2Axis2
                valuesR1.Clear();
                valuesR2.Clear();
                for (int i = 0; i < 4; i++)
                {
                    valuesR1.Add(Vector2.Dot(r1.Corners[i], r2Axis2) / r2Axis2.LengthSquared());
                }
                for (int i = 0; i < 4; i++)
                {
                    valuesR2.Add(Vector2.Dot(r2.Corners[i], r2Axis2) / r2Axis2.LengthSquared());
                }
                if (valuesR1.Min() > valuesR2.Max() || valuesR1.Max() < valuesR2.Min())
                {
                    return(false);
                }


                //if there is no gap on any axe the rectangles collide
                return(true);
            }
        }