public override void Update(GameTime gameTime, List <GameObject> objectList) { if (active) { top = new Rectangle(position.X, position.Y - 5, position.Width, 1); bottom = new Rectangle(position.X, position.Y + position.Height + 1, position.Width, 1); currentVelocity = velocity; foreach (GameObject obj in objectList) { if (obj == this) { continue; } if (!obj.Active) { continue; } if (obj is Platform) { if (obj.Position.X >= position.X) { position.X = obj.Position.X + obj.Position.Width - position.Width; } else if (obj.Position.X + obj.Position.Width <= position.Width + position.X) { position.X = obj.Position.X; } else if (frozen) { if (bottom.Intersects(new Rectangle(obj.Position.X, obj.Position.Y + obj.Position.Height - 15, obj.Position.Width, 10))) { currentVelocity.Y = 0; } } } if (velocity.Y > 0 && position.Intersects(obj.Position) && obj != this) { if (obj is FreezeShot && !frozen && obj.Active) { FreezeShot shot = obj as FreezeShot; if (shot.CurrentState == State.fire) { shot.CurrentState = State.explosion; currentHP--; } } else if (obj is Meteor) { Meteor tmp = obj as Meteor; if (frozen != tmp.Frozen) { tmp.Active = false; active = false; } if ((frozen && tmp.frozen)) { tmp.currentVelocity.Y = 0; currentVelocity.Y = 0; } /* * if (!frozen && !tmp.Frozen) * { * if (currentVelocity == tmp.currentVelocity) * { * currentVelocity *= -1; * } * } * * /* * else * { * if (VelocityX == 0 && tmp.VelocityX == 0) * { * float avgVelocityY = ((velocity.Y + tmp.VelocityY) / 4) * 3; * * VelocityY = avgVelocityY; * tmp.VelocityY = avgVelocityY; * } * }*/ } } } if (currentHP <= 0) { position.Width = 30; position.Height = 30; frozen = true; currentVelocity.X = 0; currentVelocity.Y = (int)1.5 * currentVelocity.Y; position.Width = 30; position.Height = 30; texture = frozenTexture; if (position.X % 30 != 0) { if (currentVelocity.X > 0) { position.X = (int)(position.X + 30 / 30) * 30; } else { position.X = (int)(position.X / 30) * 30; } Console.WriteLine(position.X); } } else { BreakApart(objectList); position.Width = 35 + currentHP * 5; position.Height = 35 + currentHP * 5; } Physics(); } position.X += (int)currentVelocity.X / 10; position.Y += (int)currentVelocity.Y / 10; fireEmitter.Update(gameTime, position); base.Update(gameTime, objectList); }
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); }
/// <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); }