public override void Update(GameTime someTime)
        {
            myTraveledDistance += (AccessPosition - myPreviousPosition).Length();

            if (AccessHealth <= 0)
            {
                double tempValue = myRandom.NextDouble();

                if (tempValue < 0.8)
                {
                    Game1.myObjects.Add(new GoldCoin(AccessPosition.ToPoint()));
                }

                if (tempValue < 0.4)
                {
                    Game1.myObjects.Add(new PlatinumCoin(AccessPosition.ToPoint()));
                }

                if (tempValue < 0.7)
                {
                    Game1.myObjects.Add(new HealthPowerUp(AccessPosition.ToPoint()));
                }

                Game1.myObjects.Remove(this);
            }

            Move(someTime, Vector2.UnitX);

            if (myTraveledDistance >= 600000)
            {
                Game1.myObjects.Remove(this);
            }
        }
        public override void Update(GameTime someTime)
        {
            myTraveledDistance += (AccessPosition - myPreviousPosition).Length();

            if (AccessHealth <= 0)
            {
                double tempValue = myRandom.NextDouble();

                if (tempValue < 0.4) // 40 % chans att en fiende släpper ett guldmynt.
                {
                    Game1.myObjects.Add(new GoldCoin(AccessPosition.ToPoint()));
                }

                else if (tempValue < 0.6) // 20 % chans att en fiende släpper en hälso-powerup.
                {
                    Game1.myObjects.Add(new HealthPowerUp(AccessPosition.ToPoint()));
                }

                else if (tempValue < 0.8) // 20 % chans att en fiende släpper ett platinamynt.
                {
                    Game1.myObjects.Add(new PlatinumCoin(AccessPosition.ToPoint()));
                }

                Game1.myObjects.Remove(this);
                (Game1.myObjects.Where(x => x is ScoreUI).First() as ScoreUI).AddScore(myScore);
            }

            if (myTraveledDistance >= 1000)
            {
                Game1.myObjects.Remove(this); // Förstör fienden efter 1500 längdenheter.
            }

            myPreviousPosition = AccessPosition;
        }
        public override void Update(GameTime someTime)
        {
            float tempDeltaTime = (float)someTime.ElapsedGameTime.TotalSeconds;

            myElapsedTime      += tempDeltaTime;
            myElapsedSpawnTime += tempDeltaTime;

            IEnumerable <GameObject> tempPlayers = Game1.myObjects.Where(x => x is Player.Player);

            if (tempPlayers.Count() < 1)
            {
                return;
            }

            Vector2 tempPlayerPosition  = tempPlayers.ElementAt(0).AccessRectangle.Location.ToVector2();
            Vector2 tempTargetDirection = Vector2.Normalize(tempPlayerPosition - AccessRectangle.Location.ToVector2());

            Move(someTime, tempTargetDirection);

            if (myElapsedSpawnTime >= 3)
            {
                myElapsedSpawnTime = 0;
                Game1.myObjects.Add(new EnemyBossMinion(AccessPosition.ToPoint()));
            }

            if (AccessHealth <= 0)
            {
                Game1.myObjects.Remove(this);
                (Game1.myObjects.Where(x => x is ScoreUI).First() as ScoreUI).AddScore(1000);

                Game1.myIsShowingUpgradeMenu = true;
                Game1.NextLevel();
            }
        }
Exemple #4
0
 public void BoatIsFoundAt(Rectangle aLocation, GameTime gameTime)
 {
     //Check if we are within -50 - 0 - +50 from the boat
     if (AccessPosition.NearByHorizontal(aLocation.Center.ToVector2(), 50))
     {
         //Allow drop of mines every third second
         if (gameTime.TotalGameTime.TotalSeconds > myLatestDroppedMine + 3)
         {
             myLatestDroppedMine = gameTime.TotalGameTime.TotalSeconds;
             ReleaseMine();
         }
     }
 }
Exemple #5
0
        public override void Update(GameTime aGameTime)
        {
            base.Update(aGameTime);

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                AccessDirection = -1.0f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                AccessDirection = 1.0f;
            }
            else
            {
                AccessDirection = 0.0f;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                //The else statement below will make this into a "one time trigger"
                if (mySpacePressed == false)
                {
                    mySpacePressed = true;
                    SinkBombElement sinkBomb = mySinkBombList.FirstOrDefault();
                    if (sinkBomb != null)
                    {
                        AccessSinkBombReleased?.Invoke(sinkBomb);
                        mySinkBombList.Remove(sinkBomb);
                    }
                }
            }
            else
            {
                //Force to unpress space before it is allowed to drop next sink bomb, "one time trigger"
                mySpacePressed = false;
            }

            if (myLevel > 5 && AccessDirection > 0.0f && Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                //The else statement below will make this into a "one time trigger"
                if (myEnterPressed == false)
                {
                    myEnterPressed = true;
                    //TODO! Add proper values
                    Vector2 bulletOrigin = new Vector2(AccessPosition.X + (AccessSize.Width * AccessScale), AccessPosition.Y);
                    float   bulletSpeed  = 120.0f;
                    float   bulletAngle  = 50.2f;
                    Bullet  bullet       = new Bullet(myBulletTexture, bulletOrigin, bulletSpeed, bulletAngle);
                    if (bullet != null)
                    {
                        BulletFired?.Invoke(bullet);
                    }
                }
            }
            else
            {
                //Force to unpress enter before it is allowed to shoot next bullet, "one time trigger"
                myEnterPressed = false;
            }

            //Keep the boat within screens left and right edge
            if (AccessPosition.X <= myLeftEdge && AccessDirection < 0.0f)
            {
                AccessDirection = 0.0f;
            }
            else if (AccessPosition.X > (myRightEdge) && AccessDirection > 0.0f)
            {
                AccessDirection = 0.0f;
            }

            CalcHorizontalMovement(AccessSpeed);
            AccessWhereIsTheBoat?.Invoke(new Rectangle(AccessPosition.ToPoint(), AccessSize.Size), aGameTime);

            foreach (SinkBombElement sinkBomb in mySinkBombList)
            {
                //Make all not dropped sinkbombs follow the boat
                sinkBomb.AccessPosition = new Vector2(AccessPosition.X + AccessSize.Center.X, AccessPosition.Y + AccessSize.Center.Y);
            }
        }
Exemple #6
0
 public override void Draw(GameTime someTime, SpriteBatch aSpriteBatch)
 {
     aSpriteBatch.Draw(AccessTexture, new Rectangle(AccessPosition.ToPoint(), new Point(2000)), Color.White);
     aSpriteBatch.Draw(mySecondTexture, new Rectangle(mySecondPosition.ToPoint(), new Point(2000)), Color.White);
 }