Esempio n. 1
0
        void aiMove()
        {
            this.Speed = 8f;

            if (Vector2.Distance(this.Position, this.moveTo) < 50f)
                moveTo = new Vector2(Config.Rand.Next(50, 1550), Config.Rand.Next(50, 910));

            for (int i = Powerup.Powerups.Count - 1; i >= 0; i--)
            {
                if ((Vector2.Distance(this.Position, moveTo) > (Vector2.Distance(this.Position, Powerup.Powerups[i].Position))))
                {
                    moveTo = Powerup.Powerups[i].Position;
                }
            }

            this.rotation = Steering.TurnToFace(this.Position, moveTo, this.rotation, 0.2f);

            for (int i = enemyProjectile.EnemyProjectiles.Count - 1; i >= 0; i--)
            {
                if (Vector2.Distance(this.Position, enemyProjectile.EnemyProjectiles[i].Position) < 100)
                {
                    this.rotation = Steering.TurnToFace(enemyProjectile.EnemyProjectiles[i].Position, this.Position, this.rotation, 0.4f);
                }
            }

            for (int i = AIProjectile.AIProjectiles.Count - 1; i >= 0; i--)
            {
                if (Vector2.Distance(this.Position, AIProjectile.AIProjectiles[i].Position) < 100)
                {
                    this.rotation = Steering.TurnToFace(AIProjectile.AIProjectiles[i].Position, this.Position, this.rotation, 0.4f);
                }
            }

            //if (this.target != null)
            //    if (Vector2.Distance(this.Position, this.target.Position) < 200)
            //        this.rotation = Steering.TurnToFace(this.Position, moveTo, this.rotation, 0.4f);

            for (int i = Enemy.Enemies.Count - 1; i >= 0; i--)
            {
                if (Vector2.Distance(this.Position, Enemy.Enemies[i].Position) < 250)
                {
                    this.rotation = Steering.TurnToFace(Enemy.Enemies[i].Position, this.Position, this.rotation, 0.4f);
                }
            }

            this.Direction = new Vector2((float)Math.Cos(this.rotation), (float)Math.Sin(this.rotation));
            this.Direction.Normalize();
            this.Rotation = rotation + MathHelper.PiOver2;

            if (this.moveTo.X < 5)
                moveTo = new Vector2(Config.Rand.Next(50, 1550), Config.Rand.Next(50, 910));
            else if (this.moveTo.X > Config.WorldBoundsX - 5)
                moveTo = new Vector2(Config.Rand.Next(50, 1550), Config.Rand.Next(50, 910));

            if (this.moveTo.Y < 5)
                moveTo = new Vector2(Config.Rand.Next(50, 1550), Config.Rand.Next(50, 910));
            else if (this.moveTo.Y > Config.WorldBoundsY - 5)
                moveTo = new Vector2(Config.Rand.Next(50, 1550), Config.Rand.Next(50, 910));

            //ability usage
            if (GameplayScreen.playerAbilityUses > 0 && Enemy.Enemies.Count > 30)
            {
                if (Config.ship1Active)
                {
                    if (Player.Ship != null)
                    {
                        //Player.Ship.Health = (int)MathHelper.Min(Player.Ship.Health + 25, Player.Ship.MaxHealth);
                        Player.Ship.Health = (int)MathHelper.Min(Player.Ship.Health + 10, Player.Ship.MaxHealth);
                        Player.Ship.Shield.ShieldRegen(20);
                        GameplayScreen.playerAbilityUses--;
                    }
                }
                else if (Config.ship2Active)
                {
                    if (Player.Ship != null)
                    {
                        PowerupDamageAll AoEDamage = new PowerupDamageAll(Config.PowerupSlowAllSpriteSheet);
                        AoEDamage.Position = Player.Ship.Position;
                        GameplayScreen.playerAbilityUses--;
                    }
                }
                else if (Config.ship3Active)
                {
                    if (Player.Ship != null)
                    {
                        Player.Ship.InvulnerableTimer.Start(10);
                        Player.Ship.isInvulnerable = true;
                        GameplayScreen.playerAbilityUses--;
                        Player.Ship.InvulnAbilityBar = new Bar(100, 20, new Color(255, 255, 255, 5));
                        Player.Ship.InvulnAbilityBar.Position = new Vector2(5, 290);
                    }
                }
            }
        }
Esempio n. 2
0
        void SpawnItem(LevelItem_1 item)
        {
            GameNode node = null;

            if (item.Type == ItemType_1.EnemyInterceptor) node = new EnemyInterceptor(Config.EnemyInterceptorSpriteSheet);
            else if (item.Type == ItemType_1.EnemyAvoider) node = new EnemyAvoider(Config.EnemyAvoiderSpriteSheet);
            else if (item.Type == ItemType_1.EnemyChaser) node = new EnemyChaser(Config.EnemyChaserSpriteSheet);
            else if (item.Type == ItemType_1.EnemyDasher) node = new EnemyDasher(Config.EnemyDasherSpriteSheet);
            else if (item.Type == ItemType_1.EnemyShooter) node = new EnemyShooter(Config.EnemyShooterSpriteSheet);
            else if (item.Type == ItemType_1.PowerupHealth) node = new PowerupHealth(Config.PowerupSlowAllSpriteSheet);
            else if (item.Type == ItemType_1.PowerupMissiles) node = new PowerupMissiles(Config.PowerupMissileSpriteSheet);
            else if (item.Type == ItemType_1.PowerupWeaponAutoBurst) node = new PowerupWeaponAutoBurst(Config.PowerupSlowAllSpriteSheet);
            else if (item.Type == ItemType_1.boss1) node = new boss1(Config.BossSpriteSheet);
            else if (item.Type == ItemType_1.PowerupDamageAll) node = new PowerupDamageAll(Config.PowerupSlowAllSpriteSheet);
            else if (item.Type == ItemType_1.PowerupFreeze) node = new PowerupFreeze(Config.PowerupMissileSpriteSheet);
            else if (item.Type == ItemType_1.PowerupDoubleShot) node = new PowerupDoubleShot(Config.PowerupSlowAllSpriteSheet);
            else if (item.Type == ItemType_1.PowerupTripleShot) node = new PowerupTripleShot(Config.PowerupSlowAllSpriteSheet);
            else if (item.Type == ItemType_1.PowerupAddBullet) node = new PowerupAddBullet(Config.PowerupAddProjectileSpriteSheet);
            else if (item.Type == ItemType_1.PowerupShotSpeed) node = new PowerupShotSpeed(Config.PowerupProjectileSpeedSpriteSheet);
            else if (item.Type == ItemType_1.Coin) node = new Coin(Config.CoinSpriteSheet);

            if (node != null)
            {
                //TODO: suppy levelItem Y position from item
                //node.Position = new Vector2(item.PositionX, -node.Sprite.Origin.Y);
                node.Position = new Vector2(item.PositionX, item.PositionY);
                node.Speed = item.Speed;
                node.Direction = item.Direction;
            }

        }
        /// <summary>
        /// Updates the virtual thumbsticks based on current touch state. This must be called every frame.
        /// </summary>
        public static void Update()
        {
            TouchLocation? leftTouch = null, rightTouch = null;
            TouchCollection touches = TouchPanel.GetState();
            //TouchCollection touches = input.TouchState;

            // Examine all the touches to convert them to virtual dpad positions. Note that the 'touches'
            // collection is the set of all touches at this instant, not a sequence of events. The only
            // sequential information we have access to is the previous location for of each touch.
            foreach (var touch in touches)
            {
                if (touch.Id == leftId)
                {
                    // This is a motion of a left-stick touch that we're already tracking
                    leftTouch = touch;
                    continue;
                }

                if (touch.Id == rightId)
                {
                    // This is a motion of a right-stick touch that we're already tracking
                    rightTouch = touch;
                    continue;
                }

                // We're didn't continue an existing thumbstick gesture; see if we can start a new one.
                //
                // We'll use the previous touch position if possible, to get as close as possible to where
                // the gesture actually began.
                TouchLocation earliestTouch;
                if (!touch.TryGetPreviousLocation(out earliestTouch))
                    earliestTouch = touch;

                if (earliestTouch.Position.X > 300 && earliestTouch.Position.X < 500 && earliestTouch.Position.Y > 430 && earliestTouch.Position.Y < 480)
                {
                    if (GamePage.playerAbilityUses > 0)
                    {
                        if (Config.ship1Active)
                        {
                            if (Player.Ship != null)
                            {
                                //Player.Ship.Health = (int)MathHelper.Min(Player.Ship.Health + 25, Player.Ship.MaxHealth);
                                Player.Ship.Health = (int)MathHelper.Min(Player.Ship.Health + 10, Player.Ship.MaxHealth);
                                Player.Ship.Shield.ShieldRegen(20);
                                GamePage.playerAbilityUses--;
                            }
                        }
                        else if (Config.ship2Active)
                        {
                            if (Player.Ship != null)
                            {
                                PowerupDamageAll AoEDamage = new PowerupDamageAll(Config.PowerupSlowAllSpriteSheet);
                                AoEDamage.Position = Player.Ship.Position;
                                GamePage.playerAbilityUses--;
                            }
                        }
                        else if (Config.ship3Active)
                        {
                            if (Player.Ship != null)
                            {
                                Player.Ship.InvulnerableTimer.Start(10);
                                Player.Ship.isInvulnerable = true;
                                Player.Ship.megaMagnetActive = true;
                                GamePage.playerAbilityUses--;
                                Player.Ship.InvulnAbilityBar = new Bar(100, 20, new Color(255, 255, 255, 5));
                                Player.Ship.InvulnAbilityBar.Position = new Vector2(5, 290);
                            }
                        }
                    }
                }

                if (leftId == -1)
                {
                    // if we are not currently tracking a left thumbstick and this touch is on the left
                    // half of the screen, start tracking this touch as our left stick
                    if (earliestTouch.Position.X < TouchPanel.DisplayWidth / 2)
                    {
                        leftTouch = earliestTouch;
                        continue;
                    }
                }

                if (rightId == -1)
                {
                    // if we are not currently tracking a right thumbstick and this touch is on the right
                    // half of the screen, start tracking this touch as our right stick
                    if (earliestTouch.Position.X >= TouchPanel.DisplayWidth / 2)
                    {
                        rightTouch = earliestTouch;
                        continue;
                    }
                }
            }

            // if we have a left touch
            if (leftTouch.HasValue)
            {
                // if we have no center, this position is our center
                if (Config.ControlOption == 2)
                {
                    LeftThumbstickCenter = LeftThumbstickFixed;
                }
                else if (!LeftThumbstickCenter.HasValue)
                    LeftThumbstickCenter = leftTouch.Value.Position;

                // save the position of the touch
                leftPosition = leftTouch.Value.Position;

                if (Config.ControlOption == 0)
                {
                    if (Vector2.Distance(LeftThumbstickCenter.Value, leftPosition) > 50)
                        LeftThumbstickCenter -= Vector2.Normalize(LeftThumbstickCenter.Value - leftPosition);
                }
                // save the ID of the touch
                leftId = leftTouch.Value.Id;
            }
            else
            {
                // otherwise reset our values to not track any touches
                // for the left thumbstick
                LeftThumbstickCenter = null;
                leftId = -1;
            }

            // if we have a right touch
            if (rightTouch.HasValue)
            {
                // if we have no center, this position is our center
                if (Config.ControlOption == 2)
                {
                    RightThumbstickCenter = RightThumbstickFixed;
                }
                else if (!RightThumbstickCenter.HasValue)
                    RightThumbstickCenter = rightTouch.Value.Position;

                // save the position of the touch
                rightPosition = rightTouch.Value.Position;

                if (Config.ControlOption == 0)
                {
                    if (Vector2.Distance(RightThumbstickCenter.Value, rightPosition) > 50)
                        RightThumbstickCenter -= Vector2.Normalize(RightThumbstickCenter.Value - rightPosition);
                }

                // save the ID of the touch
                rightId = rightTouch.Value.Id;
            }
            else
            {
                // otherwise reset our values to not track any touches
                // for the right thumbstick
                RightThumbstickCenter = null;
                rightId = -1;
            }
        }