Ejemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            amount = 0;
            for (int i = 0; i < childComponents.Count; i++)
            {
                if (childComponents[i] is Meteor)
                {
                    amount += (childComponents[i] as Meteor).CurrentHP;
                }
            }
            ChangeText(guiManager["points"] as Label, "" + amount);

            addAmmo();

            float time = (float)gameTime.TotalGameTime.TotalSeconds;

            //updates the text for time
            ChangeText(guiManager["time"] as Label, "Time: " + string.Format("{0:0.00}", time) + " sec");
            timer = time;

            prevoiusms = ms;
            ms         = Mouse.GetState();
            Point mouseLoc = new Point(ms.X, ms.Y);


            kPrevState = kState;
            kState     = Keyboard.GetState();


            if (ms.LeftButton == ButtonState.Pressed /* && ms != prevoiusms*/)
            {
                if (guage.guageLoaded() && guage.Stockpile.Peek().FallingSpeed == 0)
                {
                    float angle = 0;

                    if (player.getMidPoint().X > mouseLoc.X && player.getMidPoint().Y > mouseLoc.Y)
                    {
                        angle = (float)Math.Atan2(mouseLoc.Y - player.getMidPoint().Y, mouseLoc.X - player.getMidPoint().X);
                    }
                    else if (player.getMidPoint().X > mouseLoc.X && player.getMidPoint().Y < mouseLoc.Y)
                    {
                        angle = (float)Math.Atan2(player.getMidPoint().Y - mouseLoc.Y, mouseLoc.X - player.getMidPoint().X);
                    }
                    else if (player.getMidPoint().X < mouseLoc.X && player.getMidPoint().Y > mouseLoc.Y)
                    {
                        angle = (float)Math.Atan2(mouseLoc.Y - player.getMidPoint().Y, mouseLoc.X - player.getMidPoint().X);
                    }
                    else
                    {
                        angle = (float)Math.Atan2(mouseLoc.Y - player.getMidPoint().Y, mouseLoc.X - player.getMidPoint().X);
                    }

                    shot = new FreezeShot(new Rectangle((int)player.getMidPoint().X - 2, (int)player.getMidPoint().Y - 2, 15, 15), gameRef.Content, angle, guage.getAmmo());
                    childComponents.Add(shot);
                }
            }
            if (amount < 5)
            {
                addMeteor();
            }
            if (kPrevState.IsKeyDown(Keys.Space) && kState.IsKeyUp(Keys.Space))
            {
                addMeteor2();
            }

            count++;
            // TODO: Add your update logic here

            for (int i = 0; i < childComponents.Count; i++)
            {
                Rectangle windowBounds = new Rectangle(0, 0, 1000, 700);
                if (windowBounds.Contains(childComponents[i].Position) && childComponents[i].Active)
                {
                    childComponents[i].Update(gameTime, childComponents);
                }

                else
                {
                    childComponents.Remove(childComponents[i]);
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            prevoiusms = ms;
            ms         = Mouse.GetState();
            Point mouseLoc = new Point(ms.X, ms.Y);


            kPrevState = kState;
            kState     = Keyboard.GetState();


            if (ms.LeftButton == ButtonState.Pressed && ms != prevoiusms)
            {
                if (guage.guageLoaded() && guage.Stockpile.Peek().FallingSpeed == 0)
                {
                    float angle = 0;

                    if (player.getMidPoint().X > mouseLoc.X && player.getMidPoint().Y > mouseLoc.Y)
                    {
                        angle = (float)Math.Atan2(mouseLoc.Y - player.getMidPoint().Y, mouseLoc.X - player.getMidPoint().X);
                    }
                    else if (player.getMidPoint().X > mouseLoc.X && player.getMidPoint().Y < mouseLoc.Y)
                    {
                        angle = (float)Math.Atan2(player.getMidPoint().Y - mouseLoc.Y, mouseLoc.X - player.getMidPoint().X);
                    }
                    else if (player.getMidPoint().X < mouseLoc.X && player.getMidPoint().Y > mouseLoc.Y)
                    {
                        angle = (float)Math.Atan2(mouseLoc.Y - player.getMidPoint().Y, mouseLoc.X - player.getMidPoint().X);
                    }
                    else
                    {
                        angle = (float)Math.Atan2(mouseLoc.Y - player.getMidPoint().Y, mouseLoc.X - player.getMidPoint().X);
                    }

                    shot = new FreezeShot(new Rectangle((int)player.getMidPoint().X - 2, (int)player.getMidPoint().Y - 2, 2, 2), this.Content, angle, guage.getAmmo());
                    childComponent.Add(shot);
                }
            }

            addMeteor();
            addAmmo();

            if (kPrevState.IsKeyDown(Keys.Space) && kState.IsKeyUp(Keys.Space))
            {
                addAmmo();
            }



            count++;
            // TODO: Add your update logic here

            for (int i = 0; i < childComponent.Count; i++)
            {
                if (GraphicsDevice.Viewport.Bounds.Intersects(childComponent[i].Position) || childComponent[i].Active)
                {
                    childComponent[i].Update(gameTime, childComponent);
                }
                else
                {
                    childComponent.RemoveAt(i);
                }
            }

            base.Update(gameTime);
        }