Beispiel #1
0
        public override void Initialize()
        {
            // TODO: Initialize randomizer
            arrow = curGame.Content.Load<Texture2D>("Textures/HUD/arrow");
            guideDot = curGame.Content.Load<Texture2D>("Textures/HUD/guideDot");

            Catapult.Initialize();

            // TODO: Initialize guide projectile
            guideProjectile = new Projectile(curGame, spriteBatch, null,
                "Textures/Ammo/rock_ammo", Catapult.ProjectileStartPosition,
                Catapult.GroundHitOffset, playerSide == PlayerSide.Right,
                Catapult.gravity);

            base.Initialize();
        }
Beispiel #2
0
 private void PerformNothingHit(Projectile projectile)
 {
     if (Windows.Foundation.Metadata.ApiInformation
            .IsTypePresent(
                "Windows.Phone.Devices.Notification.VibrationDevice"))
     {
         Windows.Phone.Devices.Notification
             .VibrationDevice.GetDefault()
                 .Vibrate(TimeSpan.FromMilliseconds(100));
         //VibrateController.Default.Start(
         //    TimeSpan.FromMilliseconds(100));
     }
     // Play hit sound only on a missed hit,
     // a direct hit will trigger the explosion sound
     // TODO: Handle miss sounds and animation
 }
Beispiel #3
0
        /// <summary>
        /// Check what a projectile hit. The possibilities are:
        /// Nothing hit, Hit enemy, Hit self, hit own/enemy's crate.
        /// </summary>
        /// <param name="projectile">The projectile for which to 
        /// perform the check.</param>
        /// <returns>A result inidicating what, if anything, was hit</returns>
        private HitCheckResult CheckHit(Projectile projectile)
        {
            HitCheckResult hitRes = HitCheckResult.Nothing;

            // Build a sphere around a projectile
            Vector3 center = new Vector3(projectile.ProjectilePosition, 0);
            BoundingSphere sphere = new BoundingSphere(center,
                Math.Max(projectile.ProjectileTexture.Width / 2,
                projectile.ProjectileTexture.Height / 2));

            // Check Self-Hit - create a bounding box around self
            Vector3 min = new Vector3(catapultPosition, 0);
            Vector3 max = new Vector3(catapultPosition +
                new Vector2(0, 0), 0);
            // TODO: Support fire size
            BoundingBox selfBox = new BoundingBox(min, min);

            // Check enemy - create a bounding box around the enemy
            min = new Vector3(enemy.Catapult.Position, 0);
            max = new Vector3(enemy.Catapult.Position +
                      new Vector2(0, 0), 0);
            // TODO: Support fire size
            BoundingBox enemyBox = new BoundingBox(min, min);

            // Check self-crate - Create bounding box around own crate
            // TODO: Check self crate

            // Check enemy-crate - Create bounding box around enemy crate
            // TODO: Check enemy crate

            // Check self hit
            if (sphere.Intersects(selfBox)
                && currentState != CatapultState.HitKill)
            {
                // TODO: Play explosion sound
                // Launch hit animation sequence on self
                UpdateHealth(self, sphere, selfBox);
                if (self.Health <= 0)
                {
                    Hit(true);
                    enemy.Score++;
                }

                hitRes = HitCheckResult.SelfCatapult;
            }
            // Check if enemy was hit
            else if (sphere.Intersects(enemyBox)
                && enemy.Catapult.CurrentState != CatapultState.HitKill
                && enemy.Catapult.CurrentState != CatapultState.Reset)
            {
                // TODO: Play explosion sound
                // Launch enemy hit animaton
                UpdateHealth(enemy, sphere, enemyBox);
                if (enemy.Health <= 0)
                {
                    enemy.Catapult.Hit(true);
                    self.Score++;
                }

                hitRes = HitCheckResult.EnemyCatapult;
                currentState = CatapultState.Reset;
            }
            // Check if own crate was hit
            // TODO: Handle crate checking

            return hitRes;
        }
Beispiel #4
0
        /// <summary>
        /// Performs all logic necessary when a projectile hits the ground.
        /// </summary>
        /// <param name="projectile"></param>
        private void HandleProjectileHit(Projectile projectile)
        {
            projectile.HitHandled = true;

            switch (CheckHit(projectile))
            {
                case HitCheckResult.SelfCrate:
                // Ignore self crate hits
                case HitCheckResult.Nothing:
                    PerformNothingHit(projectile);
                    break;
                case HitCheckResult.SelfCatapult:
                    if ((CurrentState == CatapultState.HitKill) ||
                        (CurrentState == CatapultState.HitDamage))
                    {
                        // TODO: Play smoke animation
                    }
                    break;
                case HitCheckResult.EnemyCatapult:
                    if ((enemy.Catapult.CurrentState == CatapultState.HitKill) ||
                        (enemy.Catapult.CurrentState == CatapultState.HitDamage))
                    {
                        // TODO: Play smoke animation
                    }
                    else
                    {
                        PerformNothingHit(projectile);
                    }
                    break;
                case HitCheckResult.EnemyCrate:
                    // TODO: Handle EnemyCrate hit
                    break;
                default:
                    throw new InvalidOperationException("Hit invalid entity");
            }

            // TODO: Play hit animation
        }
Beispiel #5
0
        public override void Initialize()
        {
            // Define initial state of the catapult
            IsActive = true;
            AnimationRunning = false;
            currentState = CatapultState.Idle;
            stallUpdateCycles = 0;

            // Load multiple animations form XML definition
            XDocument doc = XDocument.Load(
                "Content/Textures/Catapults/AnimationsDef.xml");
            XName name = XName.Get("Definition");
            var definitions = doc.Document.Descendants(name);

            // Loop over all definitions in XML
            foreach (var animationDefinition in definitions)
            {
                bool? toLoad = null;
                bool val;
                if (bool.TryParse(animationDefinition.Attribute("IsAI").Value,
                                  out val))
                    toLoad = val;

                // Check if the animation definition need to be loaded
                // for current catapult
                if (toLoad == isLeftSide || null == toLoad)
                {
                    // Get a name of the animation
                    string animatonAlias =
                        animationDefinition.Attribute("Alias").Value;
                    Texture2D texture =
                        curGame.Content.Load<Texture2D>(
                            animationDefinition.Attribute("SheetName").Value);

                    // Get the frame size (width & height)
                    Point frameSize = new Point();
                    frameSize.X = int.Parse(
                        animationDefinition.Attribute("FrameWidth").Value);
                    frameSize.Y = int.Parse(
                        animationDefinition.Attribute("FrameHeight").Value);

                    // Get the frames sheet dimensions
                    Point sheetSize = new Point();
                    sheetSize.X = int.Parse(
                        animationDefinition.Attribute("SheetColumns").Value);
                    sheetSize.Y = int.Parse(
                        animationDefinition.Attribute("SheetRows").Value);

                    // If definition has a "SplitFrame" - means that other
                    // animation should start here - load it
                    if (null != animationDefinition.Attribute("SplitFrame"))
                        splitFrames.Add(animatonAlias,
                            int.Parse(
                              animationDefinition.Attribute("SplitFrame").Value));

                    // Defing animation speed
                    TimeSpan frameInterval = TimeSpan.FromSeconds((float)1 /
                        int.Parse(animationDefinition.Attribute("Speed").Value));

                    // TODO: Construct animations

                    // If definition has an offset defined - means that it should
                    // be rendered relatively to some element/other animation -
                    // load it
                    if (null != animationDefinition.Attribute("OffsetX") &&
                      null != animationDefinition.Attribute("OffsetY"))
                    {
                        // TODO: Set animation offset
                    }
                    // TODO: Add animation alias
                }
            }

            // Load the textures
            idleTexture = curGame.Content.Load<Texture2D>(idleTextureName);

            activeProjectiles = new List<Projectile>(MaxActiveProjectiles);
            activeProjectilesCopy = new List<Projectile>(MaxActiveProjectiles);
            destroyedProjectiles = new List<Projectile>(MaxActiveProjectiles);

            // TODO: Update normalProjectile instantiation
            normalProjectile = new Projectile(curGame, spriteBatch,
                activeProjectiles, "Textures/Ammo/rock_ammo",
                ProjectileStartPosition, 0, isLeftSide, gravity);
            normalProjectile.Initialize();

            // TODO: Add split projectile

            // TODO: Add SupplyCrate

            // Initialize randomizer
            random = new Random();

            base.Initialize();
        }