Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            //if (target != null)
            //{
            //    destination = target.position;
            //}

            // Check if arrived at destination
            //if (destinationPlanet != null)
            //{
            //    if (CollisionDetection.IsRectInRect(this.Bounds, destinationPlanet.Bounds))
            //    {
            //        hasArrived = true;
            //        Game.stateManager.overworldState.RemoveOverworldObject(this);
            //    }
            //}
            //else
            //{
            //    if (CollisionDetection.IsPointInsideCircle(position, destination, 200))
            //    {
            //        this.Wait();
            //        hasArrived = true;
            //    }
            //}

            // Rotate ship
            angle = (float)(MathFunctions.RadiansFromDir(new Vector2(
                                                             Direction.GetDirectionAsVector().X, Direction.GetDirectionAsVector().Y)) + (Math.PI / 180) * 270);
            base.Update(gameTime);
        }
Exemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            angle = (float)(MathFunctions.RadiansFromDir(new Vector2(
                                                             Direction.GetDirectionAsVector().X, Direction.GetDirectionAsVector().Y)) + (Math.PI) / 2 + Math.PI);

            base.Update(gameTime);
        }
Exemplo n.º 3
0
        protected void BasicBulletSetup(PlayerBullet bullet, Vector2 direction)
        {
            bullet.Direction = direction;
            bullet.Radians   = MathFunctions.RadiansFromDir(bullet.Direction);

            BasicBulletSetupInternal(bullet);
        }
Exemplo n.º 4
0
        private void SetRotation(Vector2 playerPosition)
        {
            Vector2 targetDir       = new Vector2(targetCoordinate.X - playerPosition.X, targetCoordinate.Y - playerPosition.Y);
            Vector2 targetDirScaled = MathFunctions.ScaleDirection(targetDir);
            double  radiansDir      = MathFunctions.RadiansFromDir(targetDirScaled);

            rotation = (float)(radiansDir - Math.PI / 2);
        }
Exemplo n.º 5
0
        public override void Update(GameTime gameTime, GameObjectOverworld obj)
        {
            base.Update(gameTime, obj);

            color    = GetFadingBlueFireColor(gameTime, color) * opacity;
            yScale   = scale + speed * ScaleStretch;
            parAngle = (float)((Math.PI * 90) / 180) + (float)(MathFunctions.RadiansFromDir(Direction.GetDirectionAsVector()));
        }
        public override void Setup(GameObjectVertical obj)
        {
            Vector2 centerDir = new Vector2(0, 1.0f);

            double dirRadians = MathFunctions.RadiansFromDir(centerDir);

            dirRadians += random.NextDouble() * 3 * Math.PI / 24 - Math.PI / 24;

            obj.Direction = MathFunctions.DirFromRadians(dirRadians);
        }
Exemplo n.º 7
0
        //Skapar riktning inom spridningsintervall angivet kring initialriktning.
        public static Vector2 SpreadDir(Vector2 dir, double spread)
        {
            double dirRadians = MathFunctions.RadiansFromDir(dir);

            dirRadians += ((rand.NextDouble() * spread) - spread / 2);

            Vector2 newDir = DirFromRadians(dirRadians);

            return(newDir);
        }
Exemplo n.º 8
0
        // Used to create a missile according to given parameters, and add it to the game
        private void CreateMissile(PlayerVerticalShooter player, float xDiff, Vector2 direction, float speedFactor = 1)
        {
            RegularMissile missile = new RegularMissile(Game, spriteSheet);

            missile.PositionX = player.PositionX + xDiff;
            missile.PositionY = player.PositionY;
            missile.Direction = direction;
            missile.Radians   = MathFunctions.RadiansFromDir(missile.Direction);
            missile.Initialize();
            missile.Speed *= speedFactor;

            Game.stateManager.shooterState.gameObjects.Add(missile);
        }
Exemplo n.º 9
0
        public virtual void Update(GameTime gameTime, GameObjectOverworld obj)
        {
            Direction = obj.Direction;

            //Note to self: This code needs to be fixed to compensate for diagonal movement

            float particleMoveDistance = 0.5f * MathFunctions.FPSSyncFactor(gameTime);

            if (position.X < obj.position.X)
            {
                position.X += particleMoveDistance;
            }

            else if (position.X > obj.position.X)
            {
                position.X -= particleMoveDistance;
            }

            if (position.Y < obj.position.Y)
            {
                position.Y += particleMoveDistance;
            }

            else if (position.Y > obj.position.Y)
            {
                position.Y -= particleMoveDistance;
            }

            if (scale > 0)
            {
                scale -= 0.03f * MathFunctions.FPSSyncFactor(gameTime);
            }
            else
            {
                scale = 0;
            }

            color = GetFadingFireColor(gameTime, color) * opacity;

            if (lifeSpawn > 0)
            {
                lifeSpawn -= 1.0f * MathFunctions.FPSSyncFactor(gameTime);
            }

            yScale   = scale + speed * ScaleStretch;
            parAngle = (float)((Math.PI * 90) / 180) + (float)(MathFunctions.RadiansFromDir(Direction.GetDirectionAsVector()));

            base.Update(gameTime);
        }
        protected override void ShootingPattern(GameTime gameTime)
        {
            Vector2 centerDir  = new Vector2(0, 1.0f);
            double  dirRadians = MathFunctions.RadiansFromDir(centerDir);

            dirRadians += random.NextDouble() * Math.PI / 8 - Math.PI / 16;

            EnemyMine mine = new EnemyMine(Game, spriteSheet, player);

            mine.Position  = Position;
            mine.Direction = MathFunctions.DirFromRadians(dirRadians);
            mine.Initialize();

            mine.SetActivationTime(mineActivationTime);

            Game.stateManager.shooterState.gameObjects.Add(mine);
        }
        public override Boolean Activate(PlayerVerticalShooter player, GameTime gameTime)
        {
            Vector2 centerDir  = new Vector2(0, -1.0f);
            double  dirRadians = MathFunctions.RadiansFromDir(centerDir);

            dirRadians += random.NextDouble() * Math.PI / 2 - Math.PI / 4;

            RegularBomb bomb = new RegularBomb(Game, spriteSheet);

            bomb.Position  = player.Position;
            bomb.Direction = MathFunctions.DirFromRadians(dirRadians);
            bomb.Initialize();
            bomb.Damage = damage;

            Game.stateManager.shooterState.gameObjects.Add(bomb);
            return(true);
        }
Exemplo n.º 12
0
        public override Boolean Activate(PlayerVerticalShooter player, GameTime gameTime)
        {
            Vector2 centerDir  = new Vector2(0, -1.0f);
            double  dirRadians = MathFunctions.RadiansFromDir(centerDir);

            dirRadians += random.NextDouble() * Math.PI / 8 - Math.PI / 16;

            Mine mine = new Mine(Game, spriteSheet);

            mine.Position  = player.Position;
            mine.Direction = MathFunctions.DirFromRadians(dirRadians);
            mine.Initialize();
            mine.Speed    = 0.03f;
            mine.Duration = 20000;

            Game.stateManager.shooterState.gameObjects.Add(mine);
            return(true);
        }
        public override Boolean Activate(PlayerVerticalShooter player, GameTime gameTime)
        {
            Vector2 centerDir = new Vector2(0, -1.0f);

            double dirRadians = MathFunctions.RadiansFromDir(centerDir);

            dirRadians += random.NextDouble() * 2 * Math.PI / 12 - Math.PI / 12;

            YellowBullet bullet = new YellowBullet(Game, spriteSheet);

            bullet.Position  = player.Position;
            bullet.Direction = MathFunctions.DirFromRadians(dirRadians);
            bullet.Initialize();

            bullet.SetSpreadSpeed(random);

            Game.stateManager.shooterState.gameObjects.Add(bullet);
            return(true);
        }
Exemplo n.º 14
0
        public override Boolean Activate(PlayerVerticalShooter player, GameTime gameTime)
        {
            float speedFactor    = 0.5f;
            float durationFactor = 1f;

            for (int dir = -sideShots; dir <= sideShots; dir++)
            {
                AdvancedLaser shot1 = new AdvancedLaser(Game, spriteSheet);
                shot1.PositionX = player.PositionX;
                shot1.PositionY = player.PositionY;
                BasicBulletSetup(shot1);
                shot1.Radians   = MathFunctions.RadiansFromDir(shot1.Direction) - dir * Math.PI / 30;
                shot1.Direction = MathFunctions.DirFromRadians(shot1.Radians);
                shot1.Speed    *= speedFactor;
                shot1.Duration *= durationFactor;

                Game.stateManager.shooterState.gameObjects.Add(shot1);
            }

            return(true);
        }
Exemplo n.º 15
0
        public void Draw(SpriteBatch spriteBatch, bool hyperSpeedOn, float speed, Direction direction)
        {
            if (!hyperSpeedOn)
            {
                spriteBatch.Draw(sprite.Texture, position, sprite.SourceRectangle, color,
                                 0f, centerPoint, scale, SpriteEffects.None, layerDepth);
            }
            else
            {
                starAngle = (float)((Math.PI * 90) / 180) + (float)(MathFunctions.RadiansFromDir(direction.GetDirectionAsVector()));

                yScale = scale + speed * STRETCH;

                if (yScale < scale)
                {
                    yScale = scale;
                }

                spriteBatch.Draw(sprite.Texture, position, sprite.SourceRectangle, color,
                                 starAngle, centerPoint, new Vector2(scale, yScale), SpriteEffects.None, layerDepth);
            }
        }
Exemplo n.º 16
0
        private void PlayerMovement(GameTime gameTime)
        {
            if (speed > maxSpeed)
            {
                speed = maxSpeed;
            }

            else if (speed < -maxSpeed)
            {
                speed = -maxSpeed;
            }

            if (StatsManager.Fuel >= normalFuelCost)
            {
                if (ControlManager.CheckHold(RebindableKeys.Action3) &&
                    isHyperSpeedUnlocked &&
                    !isDevelopSpeedUnlocked &&
                    controlsEnabled)
                {
                    maxSpeed     = boostSpeed;
                    turningSpeed = boostTurningSpeed;
                    playerAcc    = commonAcc;
                    usingBoost   = true;
                }

                else if (ControlManager.CheckHold(RebindableKeys.Action3) &&
                         isDevelopSpeedUnlocked &&
                         controlsEnabled)
                {
                    maxSpeed     = developSpeed;
                    turningSpeed = boostTurningSpeed;
                    playerAcc    = developAcc;
                    usingBoost   = true;
                }

                else
                {
                    maxSpeed     = commonSpeed;
                    turningSpeed = commonTurningSpeed;
                    playerAcc    = commonAcc;
                    usingBoost   = false;
                }
            }

            if (ControlManager.CheckHold(RebindableKeys.Up) && controlsEnabled)
            {
                if (StatsManager.Fuel > normalFuelCost)
                {
                    if (ControlManager.GamepadReady && ControlManager.ThumbStickAngleY != 0)
                    {
                        if (StatsManager.Fuel > normalFuelCost)
                        {
                            speed += playerAcc * MathFunctions.FPSSyncFactor(gameTime);
                        }

                        AddParticle();
                    }
                    else
                    {
                        if (StatsManager.Fuel > normalFuelCost)
                        {
                            speed += playerAcc * MathFunctions.FPSSyncFactor(gameTime);
                        }

                        AddParticle();

                        Game.soundEffectsManager.PlaySoundEffect(SoundEffects.OverworldEngine, 0f, 0f);
                    }
                }
            }

            if (ControlManager.CheckHold(RebindableKeys.Right) && controlsEnabled)
            {
                if (StatsManager.Fuel > normalFuelCost)
                {
                    Direction.SetDirection(Direction.GetDirectionAsDegree() + turningSpeed * MathFunctions.FPSSyncFactor(gameTime));
                }
            }

            else if (ControlManager.CheckHold(RebindableKeys.Left) &&
                     controlsEnabled)
            {
                if (StatsManager.Fuel > normalFuelCost)
                {
                    Direction.SetDirection(Direction.GetDirectionAsDegree() - turningSpeed * MathFunctions.FPSSyncFactor(gameTime));
                }
            }

            if (!ControlManager.CheckHold(RebindableKeys.Up) && controlsEnabled)
            {
                if (speed > 0)
                {
                    speed -= playerAcc * MathFunctions.FPSSyncFactor(gameTime);
                }

                else if (speed <= 0)
                {
                    speed = 0;
                }

                Game.soundEffectsManager.FadeOutSoundEffect(SoundEffects.OverworldEngine);
            }

            angle = (float)(MathFunctions.RadiansFromDir(new Vector2(
                                                             Direction.GetDirectionAsVector().X, Direction.GetDirectionAsVector().Y)) + (Math.PI * 90) / 180);
        }
Exemplo n.º 17
0
        public override void Update(GameTime gameTime)
        {
            damageTimer -= gameTime.ElapsedGameTime.Milliseconds;

            if (StatsManager.GetShipLife() <= 0 &&
                GameStateManager.currentState == "OverworldState")
            {
                Game.stateManager.outroState.SetOutroType(OutroType.GameOver);
                Game.stateManager.ChangeState("OutroState");
            }

            foreach (Particle par in particles)
            {
                par.Update(gameTime, this);
            }

            if (IsUsed && !hyperspeedOn)
            {
                PlayerMovement(gameTime);
                base.Update(gameTime);
            }

            if (!IsControlsEnabled &&
                !Game.stateManager.overworldState.IsBurnOutEndingActivated)
            {
                AddParticle();
            }

            if (isInvincible)
            {
                UpdateInvincibility(gameTime);
            }

            #region UpdateHyperSpeed

            if (hyperspeedOn == true)
            {
                HyperSpeedMovement(gameTime);
                AddHyperSpeedParticle();
                base.Update(gameTime);
                angle = (float)(MathFunctions.RadiansFromDir(
                                    new Vector2(Direction.GetDirectionAsVector().X, Direction.GetDirectionAsVector().Y)) + (Math.PI * 90) / 180);

                if (currentHyperspeedDistance <= 20 || speed <= 0)
                {
                    hyperspeedOn = false;
                    CheckForMoreJumps();
                }
            }

            #endregion

            #region UpdateParticles

            for (int i = 0; i < particles.Count; i++)
            {
                if (particles[i].lifeSpawn <= 0)
                {
                    deadParticles.Add(particles[i]);
                }
            }

            RemoveParticle();

            #endregion
        }