public Quadtree_sec(int plevel, CollisionBox pbounds) { level = plevel; bounds = pbounds; objects = new List<Sprite>(); nodes = new Quadtree_sec[4]; }
public bool Intersect(CollisionBox a, CollisionBox b) { if (a.Max_X < b.Min_X || a.Min_X > b.Max_X) return false; if (a.Max_Y < b.Min_Y || a.Min_Y > b.Max_Y) return false; return true; }
public Sprite(Scene scene, Vector2 position, Texture2D texture, Rectangle sourceRect, int timePerFrame, int numberOfFrames, bool isAnimated) { this.scene = scene; this.isAnimated = isAnimated; this.numberOfFrames = numberOfFrames; this.position = position; this.texture = texture; this.timePerFrame = timePerFrame; this.sourceRect = sourceRect; this.origin.X = 0; this.origin.Y = 0; Velocity = new Vector2(0, 0); blockFactory = new BlockFactory(scene.Game); itemFactory = new ItemFactory(scene.Game); enemyFactory = new EnemyFactory(scene.Game); this.sounds = new SoundMachine(scene.Game); // frameWidth = sourceRect.Width / numberOfFrames; frameWidth = 16; collisionBox = new CollisionBox(position.X, position.Y, 32, SourceRect.Height*2); }
protected MarioSprite(Vector2 position, Texture2D texture, Rectangle sourceRect, int timePerFrame, int numberOfFrames) { this.numberOfFrames = numberOfFrames; this.position = position; this.texture = texture; this.timePerFrame = timePerFrame; this.sourceRect = sourceRect; Direction = 1; this.origin.X = 0; // this.origin.Y = sourceRect.Height; position.Y = position.Y - sourceRect.Height; collisionBox = new CollisionBox(position.X, position.Y , 16, sourceRect.Height); }
public BGSprite(Vector2 pos, Texture2D tex) : base(pos, tex) { CollisionBox = new CollisionBox(pos.X, pos.Y, 0, 0); }
/* * Determine which node the object belongs to. -1 means * object cannot completely fit within a child node and is part * of the parent node */ private int GetIndex(CollisionBox pRect) { int index = -1; float verticalMidpoint = bounds.X + (bounds.Width / 2); float horizontalMidpoint = bounds.Y + (bounds.Height / 2); // Object can completely fit within the top quadrants bool topQuadrant = (pRect.Y < horizontalMidpoint && pRect.Y + pRect.Height < horizontalMidpoint); // Object can completely fit within the bottom quadrants bool bottomQuadrant = (pRect.Y > horizontalMidpoint); // Object can completely fit within the left quadrants if (pRect.X < verticalMidpoint && pRect.X + pRect.Width < verticalMidpoint) { if (topQuadrant) { index = 1; } else if (bottomQuadrant) { index = 2; } } // Object can completely fit within the right quadrants else if (pRect.X > verticalMidpoint) { if (topQuadrant) { index = 0; } else if (bottomQuadrant) { index = 3; } } return index; }