public void Initialize()
        {
            subProjectile1 = new Projectile(contentManager, spriteBatch, activeProjectiles,
                "Textures/Ammo/rock_ammo", ProjectileStartPosition, hitOffset,
                isRightPlayer, gravity);
            subProjectile1.Initialize();

            subProjectile2 = new Projectile(contentManager, spriteBatch, activeProjectiles,
                "Textures/Ammo/rock_ammo", ProjectileStartPosition, hitOffset,
                isRightPlayer, gravity);
            subProjectile2.Initialize();

            subProjectile3 = new Projectile(contentManager, spriteBatch, activeProjectiles,
                "Textures/Ammo/rock_ammo", ProjectileStartPosition, hitOffset,
                isRightPlayer, gravity);
            subProjectile3.Initialize();
        }
예제 #2
0
        public override void Initialize()
        {
            arrow = contentManager.Load<Texture2D>("Textures/HUD/arrow");
            guideDot = contentManager.Load<Texture2D>("Textures/HUD/guideDot");

            Catapult.Initialize();

            guideProjectile =
                new Projectile(contentManager, spriteBatch, null,
                "Textures/Ammo/rock_ammo", Catapult.ProjectileStartPosition,
                Catapult.GroundHitOffset, playerSide == PlayerSide.Right,
                Catapult.Gravity);
        }
예제 #3
0
 private void PerformNothingHit(Projectile projectile)
 {
     VibrateController.Default.Start(TimeSpan.FromMilliseconds(100));
     // Play hit sound only on a missed hit,
     // a direct hit will trigger the explosion sound
     AudioManager.PlaySound("boulderHit");
     projectile.HitAnimation = animations["fireMiss"];
 }
예제 #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))
                    {
                        projectile.HitAnimation = animations["hitSmoke"];
                    }
                    break;
                case HitCheckResult.EnemyCatapult:
                    if ((enemy.Catapult.CurrentState == CatapultState.HitKill) ||
                        (enemy.Catapult.CurrentState == CatapultState.HitDamage))
                    {
                        projectile.HitAnimation = animations["hitSmoke"];
                    }
                    else
                    {
                        PerformNothingHit(projectile);
                    }
                    break;
                case HitCheckResult.EnemyCrate:
                    if (enemy.Catapult.crate.CurrentState == CrateState.Idle)
                    {
                        AudioManager.PlaySound("catapultExplosion");
                        projectile.HitAnimation = animations["hitSmoke"];
                        enemy.Catapult.crate.Hit();
                        self.Weapon = WeaponType.Split;
                    }
                    else
                    {
                        PerformNothingHit(projectile);
                    }
                    break;
                default:
                    throw new InvalidOperationException("Hit invalid entity");
            }

            projectile.HitAnimation.PlayFromFrameIndex(0);
        }
예제 #5
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(animations["Fire"].FrameSize.X,
                    animations["Fire"].FrameSize.Y), 0);
            BoundingBox selfBox = new BoundingBox(min, max);

            // Check enemy - create a bounding box around the enemy
            min = new Vector3(enemy.Catapult.Position, 0);
            max = new Vector3(enemy.Catapult.Position +
                new Vector2(animations["Fire"].FrameSize.X,
                    animations["Fire"].FrameSize.Y), 0);
            BoundingBox enemyBox = new BoundingBox(min, max);

            // Check self-crate - Create bounding box around own crate
            min = new Vector3(crate.Position, 0);
            max = new Vector3(crate.Position + new Vector2(crate.Width, crate.Height), 0);
            BoundingBox selfCrateBox = new BoundingBox(min, max);

            // Check enemy-crate - Create bounding box around enemy crate
            min = new Vector3(enemy.Catapult.crate.Position, 0);
            max = new Vector3(enemy.Catapult.crate.Position +
                new Vector2(enemy.Catapult.crate.Width, enemy.Catapult.crate.Height), 0);
            BoundingBox enemyCrateBox = new BoundingBox(min, max);

            // Check self hit
            if (sphere.Intersects(selfBox) && currentState != CatapultState.HitKill)
            {
                AudioManager.PlaySound("catapultExplosion");
                // 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)
            {
                AudioManager.PlaySound("catapultExplosion");
                // Launch enemy hit animaton
                UpdateHealth(enemy, sphere, enemyBox);
                if (enemy.Health <= 0)
                {
                    enemy.Catapult.Hit(true);
                    if (self.IsActive)
                    {
                        self.Score++;
                        if (App.g_isTwoHumanPlayers)
                        {
                            Dictionary<string, object> scoreProperties = new Dictionary<string, object>();
                            if (GlobalContext.PlayerIsFirstOnAppWarp)
                            {
                                GlobalContext.tableProperties["Player1Score"] = self.Score;
                                scoreProperties.Add("Player1Score", self.Score);
                            }
                            else
                            {
                                scoreProperties.Add("Player2Score", self.Score);
                                GlobalContext.tableProperties["Player2Score"] = self.Score;
                            }
                            WarpClient.GetInstance().UpdateRoomProperties(GlobalContext.GameRoomId, scoreProperties, null);
                        }
                    }
                }

                hitRes = HitCheckResult.EnemyCatapult;
                currentState = CatapultState.Reset;
            }
            // Check if own crate was hit
            else if (sphere.Intersects(selfCrateBox))
            {
                hitRes = HitCheckResult.SelfCrate;
            }
            // Check if enemy crate was hit
            else if (sphere.Intersects(enemyCrateBox))
            {
                hitRes = HitCheckResult.EnemyCrate;
            }

            return hitRes;
        }
예제 #6
0
        /// <summary>
        /// Function initializes the catapult instance and loads the animations from XML definition sheet
        /// </summary>
        public 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 =
                        contentManager.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));

                    Animation animation = new Animation(texture, frameSize, sheetSize);

                    // 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"))
                    {
                        animation.Offset = new Vector2(int.Parse(animationDefinition.Attribute("OffsetX").Value),
                            int.Parse(animationDefinition.Attribute("OffsetY").Value));
                    }

                    animations.Add(animatonAlias, animation);
                }
            }

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

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

            normalProjectile = new Projectile(contentManager, spriteBatch, activeProjectiles,
                "Textures/Ammo/rock_ammo", ProjectileStartPosition,
                animations["Fire"].FrameSize.Y, isLeftSide, Gravity);
            normalProjectile.Initialize();

            splitProjectile = new SplitProjectile(contentManager, spriteBatch, activeProjectiles,
                "Textures/Ammo/split_ammo", ProjectileStartPosition,
                animations["Fire"].FrameSize.Y, isLeftSide, Gravity);
            splitProjectile.Initialize();

            crate = new SupplyCrate(contentManager, spriteBatch, "Textures/Crate/box",
                Position + new Vector2(animations["Fire"].FrameSize.X / 2, 0), isLeftSide);
            crate.Initialize();

            // Initialize randomizer
            random = new Random();
        }