public VictimLeaf( MegaTile ParentMegaTile, Animation GroundAnimation, Animation StumpAnimation, Animation ExplodeAnimation, Animation TornadoAnimation, string SoundFileName, Vector2 Position) { this.megatile = ParentMegaTile; this.GroundAnimation = GroundAnimation; this.StumpAnimation = StumpAnimation; this.ExplodeAnimation = ExplodeAnimation; this.TornadoAnimation = TornadoAnimation; this.soundHit = SoundFileName; GroundHealth = 0; TornadoHealth = 0; Mass = 0.1f; bounds = new Rectangle2D(Position.X, Position.Y, TornadoAnimation.FrameWidth, TornadoAnimation.FrameHeight); state = State.Flying; PreLoadSounds(); }
public bool Intersects(Rectangle2D rect) { bool intersect = false; if (X < rect.X + rect.Width) { if (X + Width > rect.X) { if (Y + Height > rect.Y) { if (Y < rect.Y + rect.Height) { intersect = true; } } } } return intersect; }
public VictimSkyscraper(MegaTile ParentMegaTile, Animation GroundAnimation, Animation StumpAnimation, Animation ExplodeAnimation, Animation TornadoAnimation, string SoundFileName, Vector2 Position) { this.megatile = ParentMegaTile; this.GroundAnimation = GroundAnimation; this.StumpAnimation = StumpAnimation; this.ExplodeAnimation = ExplodeAnimation; this.TornadoAnimation = TornadoAnimation; this.soundHit = SoundFileName; removeFromMegaTileOnDeath = false; bounds = new Rectangle2D(Position.X, Position.Y, GroundAnimation.FrameWidth, GroundAnimation.FrameHeight); state = State.Ground; PreLoadSounds(); }
/// <summary> /// Try and damage our victims with our stats /// </summary> /// <param name="victimsToCollideWith"></param> protected virtual void HitCheck(Victim groundObject) { if (groundObject.state == State.Ground) { float diameter = 0.0f; if (bounds.Width > bounds.Height) { diameter = bounds.Width; } else { diameter = bounds.Height; } Rectangle2D collideBox = new Rectangle2D(this.bounds.Center.X - (diameter / 2.0f), this.bounds.Center.Y - (diameter / 2.0f), diameter, diameter); switch (state) { case State.Flying: if (collideBox.Rectangle.Intersects(groundObject.bounds.Rectangle)) //we need to add damage { SoundEffectEngine.Play(soundHit,SoundEffectEngine.Priority.Normal); float damageDone = getDamage(groundObject); float resdamage = groundObject.RecieveHit(damageDone, this.tornado); if (resdamage > 0) { this.TornadoHealth = 0; //If we can't kill the ground } if (this.TornadoHealth <= 0) { state = State.Exploding; } } break; } } }
public bool IsWithin(Rectangle2D InnerRect) { bool inner = false; if (this.X < InnerRect.X && this.Y < InnerRect.Y && this.X + this.Width > InnerRect.X + InnerRect.Width && this.Y + this.Height > InnerRect.Y + InnerRect.Height) { inner = true; } return inner; }
/// <summary> /// Draw a frame of the animation to the screen at the given location. /// dest specifies the rectangle to be filled by the frame /// Direction value orients the frame, and is given in radians /// </summary> public void Draw(SpriteBatch sBatch, Rectangle2D dest, double direction) { sBatch.Draw(texture, dest.DrawingOffset, new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameHeight), color, (float)direction, new Vector2(frameWidth/2, frameHeight/2), SpriteEffects.None, 0); }
//randomly place object in world on construction protected virtual void PlaceInWorld() { int border = rnd.Next(0, 3); float X; float Y; switch (border) { case (int)Heading.North: flyHeading = rnd.Next() * ((float)Math.PI / 4f) + 3f * (float)Math.PI / 4f; Y = 1 - squareDimensions; X = rnd.Next(0, (int)level.Bounds.Width - squareDimensions); break; case (int)Heading.East: flyHeading = rnd.Next() * ((float)Math.PI / 4f) + 5f * (float)Math.PI / 4f; X = level.Bounds.Width - 1; Y = rnd.Next(0, (int)level.Bounds.Height - squareDimensions); break; case (int)Heading.South: flyHeading = rnd.Next() * ((float)Math.PI / 4f) + 7f * (float)Math.PI / 4f; Y = level.Bounds.Height - 1; X = rnd.Next(0, (int)level.Bounds.Width - squareDimensions); break; case (int)Heading.West: flyHeading = rnd.Next() * (float)Math.PI / 4f + (float)Math.PI / 4f; X = 1 - squareDimensions; Y = rnd.Next(0, (int)level.Bounds.Height - squareDimensions); break; default: throw new Exception("Unknown Border Of The Level to Generate"); break; } bounds = new Rectangle2D(X, Y, squareDimensions, squareDimensions); }