public static void draw(StationarySprite a,SpriteBatch drawer, GraphicsDevice graphics, SpriteEffects effect, float rot, float depth) { drawer.Draw(a.img, new Rectangle((int)a.pos.X, (int)a.pos.Y, (int)a.dim.X, (int)a.dim.Y) , null, Color.White, rot, new Vector2(a.dim.X / 2, a.dim.Y / 2), effect, depth); }
public Boolean isAbove(GameTime gameTime, StationarySprite b) { float newY = (float)pos.Y - speed.Y * (float)gameTime.ElapsedGameTime.TotalSeconds; float newX = (float)pos.X - speed.X * (float)gameTime.ElapsedGameTime.TotalSeconds; return speed.Y > 0 && newY + dim.Y < b.pos.Y - (b is Platform ? (b as Platform).maxHeight((int)newX, (int)(newX + dim.X)) : 0) + dim.Y; }
public Boolean isRightOf(GameTime gameTime,StationarySprite b) { return speed.X < 0 && pos.X - speed.X * (float)gameTime.ElapsedGameTime.TotalSeconds > b.pos.X + b.dim.X; }
public Boolean isLeftOf(GameTime gameTime, StationarySprite b) { return speed.X > 0 && dim.X + pos.X - 2 * speed.X * (float)gameTime.ElapsedGameTime.TotalSeconds < b.pos.X; }
public virtual Boolean intersects(StationarySprite other) { return new Rectangle((int)pos.X, (int)pos.Y, (int)dim.X, (int)dim.Y).Intersects( new Rectangle((int)other.pos.X, (int)other.pos.Y, (int)(other.dim.X), (int)(other.dim.Y))); }
public float distance(StationarySprite other) { double xDist = Math.Abs(getCenter().X-other.getCenter().X); double yDist = Math.Abs(getCenter().Y-other.getCenter().Y); return (float)Math.Sqrt(Math.Pow(xDist, 2) + Math.Pow(yDist, 2)); }
public StationarySprite(StationarySprite a) { img = a.img; pos = a.pos; dim = a.dim; }
//Checks whether a sprite (really a player) is in a wind area public int isInWindArea(StationarySprite a) { foreach (Area r in areas) if (r.intersects(a) && r is WindArea) { WindArea ar = r as WindArea; if(ar.left) return -1; else { return 1; } } return 0; }
//Checks whether a sprite is in a time-stopped area public Boolean timeStop(StationarySprite a) { foreach (Area r in areas) if (r.intersects(a) && r is TStopArea) return true; return false; }
public float getLandFriction(StationarySprite a) { foreach (Area r in areas) if (r.intersects(a) && r is HeavyArea) return GROUND_FRICTION * 2; return GROUND_FRICTION; }
//If a player is on land in an anti-grav area, they should go up public float getLandGravity(StationarySprite a) { foreach (Area r in areas) if (r.intersects(a) && r is ReverseArea) return GRAVITY * -.5f; return 0; }
//Gets the local gravity for a sprite public float getGravity(StationarySprite a) { foreach (Area r in areas) if (r.intersects(a)&& r is ReverseArea) return GRAVITY * -1; foreach (Area r in areas) if (r.intersects(a) && r is HeavyArea) return GRAVITY * 2; return GRAVITY; }
//Check whether a sprite intersects with anything public Boolean allIntersects(StationarySprite a) { List<StationarySprite> all = All(); foreach (Area r in areas) all.Remove(r); for (int i = 0; i < all.Count; i++) { if (!all[i].Equals(a) && (all[i].intersects(a) || a.intersects(all[i]))) return true; } return false; }
public Boolean intersectsHill(StationarySprite other) { for (int i = 0; i < heights.Length; i++) if (new Rectangle(i + (int)pos.X, (int)pos.Y - heights[i], 1, heights[i]).Intersects( new Rectangle((int)other.pos.X, (int)other.pos.Y, (int)other.dim.X, (int)other.dim.Y))) return true; return false; }
public Boolean intersectsBase(StationarySprite other) { return base.intersects(other); }
public override Boolean intersects(StationarySprite other) { return (base.intersects(other) || intersectsHill(other)); }