示例#1
0
        private static void handleMovement(IProjectile projectile, IEnviromental enviromental, ICollision side)
        {
            Rectangle projectileRectangle   = projectile.returnCollisionRectangle();
            Rectangle enviroRectangle       = enviromental.returnCollisionRectangle();
            Rectangle intersectionRectangle = Rectangle.Intersect(enviroRectangle, projectileRectangle);
            Vector2   projectileLocation    = projectile.returnLocation();
            int       locationDiffToChange  = UtilityClass.zero;

            if (side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newProjectileX = (int)projectileLocation.X - locationDiffToChange;
                projectile.updateLocation(new Vector2(newProjectileX, projectileLocation.Y));
                projectile.RigidBody().RightCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Right))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newProjectileX = (int)projectileLocation.X + locationDiffToChange;
                projectile.updateLocation(new Vector2(newProjectileX, projectileLocation.Y));
                projectile.RigidBody().LeftCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Top))
            {
                projectile.RigidBody().BottomCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Bottom))
            {
                projectile.RigidBody().TopCollision();
            }
        }
 public static void handleCollision(IItemObjects item, IEnviromental enviro, ICollision side)
 {
     if (!(side.returnCollisionSide().Equals(CollisionSide.None)))
     {
         handleItemMovement(item, enviro, side);
     }
 }
示例#3
0
 public static void handleCollision(IProjectile projectile, IEnviromental enviromental, ICollision side)
 {
     if (!(side.returnCollisionSide().Equals(CollisionSide.None)))
     {
         handleMovement(projectile, enviromental, side);
     }
 }
示例#4
0
        private static void handleMarioMovement(Mario mario, IEnviromental enviromental, ICollision side)
        {
            Rectangle enviromentalRectangle = enviromental.returnCollisionRectangle();
            Rectangle marioRectangle        = mario.returnCollisionRectangle();
            Rectangle intersectionRectangle = Rectangle.Intersect(marioRectangle, enviromentalRectangle);
            int       locationDiffToChange  = UtilityClass.zero;

            if (side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newMarioX = (int)mario.Location.X - locationDiffToChange;
                mario.Location = new Vector2(newMarioX, mario.Location.Y);
                mario.rigidbody.HorizontalCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Right))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newMarioX = (int)mario.Location.X + locationDiffToChange;
                mario.Location = new Vector2(newMarioX, mario.Location.Y);
                mario.rigidbody.HorizontalCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Top))
            {
                locationDiffToChange = intersectionRectangle.Height;
                int newMarioY = (int)mario.Location.Y - locationDiffToChange;
                mario.Location = new Vector2(mario.Location.X, newMarioY);
                mario.rigidbody.BottomCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Bottom))
            {
                locationDiffToChange = intersectionRectangle.Height;
                int newMarioY = (int)mario.Location.Y + locationDiffToChange;
                mario.Location = new Vector2(mario.Location.X, newMarioY);
            }
        }
示例#5
0
 public static void handleCollision(Mario mario, IEnviromental enviromental, ICollision side)
 {
     if (!(side.returnCollisionSide().Equals(CollisionSide.None)))
     {
         handleMarioMovement(mario, enviromental, side);
     }
 }
 public static void handleCollision(IEnemyObject enemy, IEnviromental enviromental, ICollision side)
 {
     if (!(side.returnCollisionSide().Equals(CollisionSide.None)))
     {
         handleEnemyMovement(enemy, enviromental, side);
     }
 }
示例#7
0
 private void handleEnemySpawning(IEnviromental enviromental)
 {
     if (enviromental is EnemySpawner)
     {
         int  enemySpawnerRelativeXLocation = ((int)((EnemySpawner)enviromental).returnLocation().X - ((int)camera.GetPosition().X + camera.GetWidth()));
         bool spawnEnemyTime = ((EnemySpawner)enviromental).timeToSpawnAnEnemy();
         bool inEnableRange  = (enemySpawnerRelativeXLocation <= UtilityClass.enableEnemyPixelWidth);
         if (inEnableRange && spawnEnemyTime && enemyCount < maxSpawnedEnemiesCount)
         {
             enemiesList.Add(((EnemySpawner)enviromental).SpawnAnEnemy());
             increaseEnemyCount();
         }
     }
 }
        private static void handleItemMovement(IItemObjects item, IEnviromental enviro, ICollision side)
        {
            Rectangle blockRectangle        = enviro.returnCollisionRectangle();
            Rectangle itemRectangle         = item.returnCollisionRectangle();
            Rectangle intersectionRectangle = Rectangle.Intersect(itemRectangle, blockRectangle);
            Vector2   itemLocation          = item.returnLocation();
            int       locationDiffToChange  = UtilityClass.zero;

            if (side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newItemX = (int)itemLocation.X - locationDiffToChange;
                item.updateLocation(new Vector2((newItemX), itemLocation.Y));
                item.RigidBody().RightCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Right))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newItemX = (int)itemLocation.X + locationDiffToChange;
                item.updateLocation(new Vector2((newItemX), itemLocation.Y));
                item.RigidBody().LeftCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Top))
            {
                locationDiffToChange = intersectionRectangle.Height;
                int newItemY = (int)itemLocation.Y - locationDiffToChange;
                item.updateLocation(new Vector2(itemLocation.X, newItemY));
                item.RigidBody().BottomCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Bottom))
            {
                locationDiffToChange = intersectionRectangle.Height;
                int newItemY = (int)itemLocation.Y + locationDiffToChange;
                item.updateLocation(new Vector2(itemLocation.X, newItemY));
                item.RigidBody().TopCollision();
            }
        }
        private static void handleEnemyMovement(IEnemyObject enemy, IEnviromental enviromental, ICollision side)
        {
            Rectangle enviromentalRectangle = enviromental.returnCollisionRectangle();
            Rectangle enemyRectangle        = enemy.returnCollisionRectangle();
            Rectangle intersectionRectangle = Rectangle.Intersect(enemyRectangle, enviromentalRectangle);
            Vector2   enemyLocation         = enemy.returnLocation();
            int       locationDiffToChange  = UtilityClass.zero;

            if (side.returnCollisionSide().Equals(CollisionSide.Left))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newEnemyX = (int)enemyLocation.X - locationDiffToChange;
                enemy.updateLocation(new Vector2((newEnemyX), enemyLocation.Y));
                enemy.RightCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Right))
            {
                locationDiffToChange = intersectionRectangle.Width;
                int newEnemyX = (int)enemyLocation.X + locationDiffToChange;
                enemy.updateLocation(new Vector2((newEnemyX), enemyLocation.Y));
                enemy.LeftCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Top))
            {
                locationDiffToChange = intersectionRectangle.Height;
                int newEnemyY = (int)enemyLocation.Y - locationDiffToChange;
                enemy.updateLocation(new Vector2(enemyLocation.X, newEnemyY));
                enemy.BottomCollision();
            }
            else if (side.returnCollisionSide().Equals(CollisionSide.Bottom))
            {
                locationDiffToChange = intersectionRectangle.Height;
                int newEnemyY = (int)enemyLocation.Y + locationDiffToChange;
                enemy.updateLocation(new Vector2(enemyLocation.X, newEnemyY));
                enemy.TopCollision();
            }
        }