//----------------------------------------------------------------------------- // Override //----------------------------------------------------------------------------- public CollisionModelSR(TemporaryResources resources = null) { this.resources = resources; //===================================================================================== AddCommand("Model", "string name", delegate(CommandParam parameters) { modelName = parameters.GetString(0); model = new CollisionModel(); }); //===================================================================================== AddCommand("End", "", delegate(CommandParam parameters) { if (model != null) { Resources.AddResource(modelName, model); model = null; } }); //===================================================================================== AddCommand("Add", "int x, int y, int width, int height", delegate(CommandParam parameters) { model.AddBox( parameters.GetInt(0), parameters.GetInt(1), parameters.GetInt(2), parameters.GetInt(3)); }); //===================================================================================== }
public TilesetBuilder CreateLedge(CollisionModel model, int ledgeDirection) { tileData.CollisionModel = model; tileData.LedgeDirection = ledgeDirection; tileData.SolidType = TileSolidType.Ledge; return this; }
public CollisionModel(CollisionModel copy) { bounds = Rectangle2I.Zero; boxes = new List<Rectangle2I>(); for (int i = 0; i < copy.boxes.Count; ++i) boxes.Add(copy.boxes[i]); }
public CollisionModel(CollisionModel copy) { bounds = Rectangle2I.Zero; boxes = new List <Rectangle2I>(); for (int i = 0; i < copy.boxes.Count; ++i) { boxes.Add(copy.boxes[i]); } }
public static bool Intersecting(CollisionModel model, Vector2F modelPosition, Rectangle2F box, Vector2F boxPosition) { Rectangle2F boxTranslated = Rectangle2F.Translate(box, boxPosition - modelPosition); for (int i = 0; i < model.boxes.Count; i++) { Rectangle2F modelBox = model.boxes[i]; if (boxTranslated.Intersects(modelBox)) { return(true); } } return(false); }
//----------------------------------------------------------------------------- // Circular Collisions //----------------------------------------------------------------------------- private void ResolveCircularCollision(Entity entity, Tile tile, Vector2F modelPos, CollisionModel model) { for (int i = 0; i < model.BoxCount; i++) { Rectangle2F box = model.Boxes[i]; box.Point += modelPos; ResolveCircularCollision(entity, tile, box); } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void OnInitialize() { base.OnInitialize(); direction = Properties.GetInteger("direction", Directions.Down); extendLength = 0.0f; isBeingPulled = false; SetLength(0.0f); CollisionStyle = CollisionStyle.Circular; IsSolid = true; ClingWhenStabbed = false; SolidType = TileSolidType.HalfSolid; Rectangle2I collisionBox = new Rectangle2I(4, 4, 8, 8); collisionBox.ExtendEdge(direction, 5); CollisionModel = new CollisionModel(collisionBox); if (direction == Directions.Right) Graphics.PlaySprite(GameData.SPR_TILE_PULL_HANDLE_RIGHT); else if (direction == Directions.Up) Graphics.PlaySprite(GameData.SPR_TILE_PULL_HANDLE_UP); else if (direction == Directions.Left) Graphics.PlaySprite(GameData.SPR_TILE_PULL_HANDLE_LEFT); else if (direction == Directions.Down) Graphics.PlaySprite(GameData.SPR_TILE_PULL_HANDLE_DOWN); }
// Begins reading the script. protected override void BeginReading() { modelName = ""; model = null; }
//----------------------------------------------------------------------------- // Debug drawing //----------------------------------------------------------------------------- // Draw a collision model as a solid color. public void DrawCollisionModel(CollisionModel model, Vector2F position, Color color) { for (int i = 0; i < model.Boxes.Count; i++) FillRectangle(Rectangle2F.Translate(model.Boxes[i], position), color); }
public TilesetBuilder SetSolidModel(CollisionModel model) { tileData.SolidType = TileSolidType.Solid; tileData.CollisionModel = model; return this; }
//----------------------------------------------------------------------------- // Building //----------------------------------------------------------------------------- public TilesetBuilder SetModel(CollisionModel model) { tileData.CollisionModel = model; return this; }
//----------------------------------------------------------------------------- // Static methods //----------------------------------------------------------------------------- public static bool Intersecting(CollisionModel model, Vector2F modelPosition, Rectangle2F box) { return(Intersecting(model, modelPosition, box, Vector2F.Zero)); }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void OnInitialize() { base.OnInitialize(); // Create the turnstile collision model. // It loooks like this: (each character is a quarter-tile) // X X // X X // XX // XX // X X // X X CollisionModel = new CollisionModel(); CollisionModel.AddBox( 0, 0, 8, 8); CollisionModel.AddBox( 8, 8, 8, 8); CollisionModel.AddBox(40, 0, 8, 8); CollisionModel.AddBox(32, 8, 8, 8); CollisionModel.AddBox( 0, 40, 8, 8); CollisionModel.AddBox( 8, 32, 8, 8); CollisionModel.AddBox(40, 40, 8, 8); CollisionModel.AddBox(32, 32, 8, 8); CollisionModel.AddBox(16, 16, 16, 16); // center. SolidType = TileSolidType.Solid; IsSolid = true; turnDirection = -1; // Setup based on the winding order. windingOrder = (Properties.GetBoolean("clockwise", false) ? WindingOrder.Clockwise : WindingOrder.CounterClockwise); if (windingOrder == WindingOrder.Clockwise) { arrowsAnimationPlayer.Play(GameData.ANIM_TURNSTILE_ARROWS_CLOCKWISE); turnstileAnimationPlayer.SubStripIndex = 0; } else { arrowsAnimationPlayer.Play(GameData.ANIM_TURNSTILE_ARROWS_COUNTERCLOCKWISE); turnstileAnimationPlayer.SubStripIndex = 1; } turnstileAnimationPlayer.Play(GameData.ANIM_TURNSTILE_ROTATE_CLOCKWISE); turnstileAnimationPlayer.SkipToEnd(); }
public static bool Intersecting(CollisionModel model, Vector2F modelPosition, Rectangle2F box, Vector2F boxPosition) { Rectangle2F boxTranslated = Rectangle2F.Translate(box, boxPosition - modelPosition); for (int i = 0; i < model.boxes.Count; i++) { Rectangle2F modelBox = model.boxes[i]; if (boxTranslated.Intersects(modelBox)) return true; } return false; }
//----------------------------------------------------------------------------- // Static methods //----------------------------------------------------------------------------- public static bool Intersecting(CollisionModel model, Vector2F modelPosition, Rectangle2F box) { return Intersecting(model, modelPosition, box, Vector2F.Zero); }