//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void OnInitialize() { if (IsRaised) Graphics.PlayAnimation(GameData.ANIM_TILE_CROSSING_GATE_RAISE); else Graphics.PlayAnimation(GameData.ANIM_TILE_CROSSING_GATE_LOWER); bool isFacingLeft = Properties.GetBoolean("face_left", false); Graphics.AnimationPlayer.SkipToEnd(); Graphics.SubStripIndex = (isFacingLeft ? 1 : 0); CollisionModel = (isFacingLeft ? GameData.MODEL_EDGE_W : GameData.MODEL_EDGE_E); Point2I trackLocation = Location; if (isFacingLeft) trackLocation.X -= 1; else trackLocation.X += 1; // Create the dummy tile to serve as the solid dummySolidTile = Tile.CreateTile(new TileData()); dummySolidTile.CollisionModel = new CollisionModel(new Rectangle2I(0, 0, 16, 8)); dummySolidTile.ClingWhenStabbed = false; dummySolidTile.SolidType = TileSolidType.Solid; dummySolidTile.IsSolid = !IsRaised; RoomControl.PlaceTile(dummySolidTile, trackLocation, Layer); }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void OnCoverComplete(Tile tile) { if (tile is TileColorCube) { TileColorCube colorCube = (TileColorCube) tile; Color = ((TileColorCube) tile).TopColor; } }
public override void OnCollideTile(Tile tile, bool isInitialCollision) { // Move 3 pixels into the block from where it collided. if (!isInitialCollision) position += Physics.PreviousVelocity.Normalized * 3.0f; Intercept(); }
public PlayerCarryState(Tile carryTile) { this.carryObject = new CarriedTile(carryTile); this.throwDuration = 2; this.pickupFrame1Duration = 6; this.pickupFrame2Duration = 4; this.carryObject.Graphics.ImageVariant = carryTile.Zone.ImageVariantID; }
public override void OnUncoverBegin(Tile tile) { isCovered = false; if (tile.IsMoving) uncoverTimer = GameSettings.TILE_BUTTON_UNCOVER_RELEASE_DELAY; else uncoverTimer = 0; tilesCovering.Remove(tile); }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public TileGraphicsComponent(Tile tile) { this.tile = tile; this.animationPlayer = new AnimationPlayer(); this.isVisible = true; this.depthLayer = DepthLayer.TileLayer1; this.imageVariant = 0; this.raisedDrawOffset = Point2I.Zero; this.drawOffset = Point2I.Zero; this.syncPlaybackWithRoomTicks = true; this.isAnimatedWhenPaused = false; this.absoluteDrawPosition = Vector2F.Zero; this.useAbsoluteDrawPosition = false; }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- public CarriedTile(Tile tile) { this.tile = tile; EnablePhysics(PhysicsFlags.Bounces | PhysicsFlags.HasGravity | PhysicsFlags.DestroyedOutsideRoom | PhysicsFlags.CollideWorld | PhysicsFlags.HalfSolidPassable | PhysicsFlags.LedgePassable | PhysicsFlags.DestroyedInHoles); //OriginOffset = new Point2I(8, 14); Physics.CollisionBox = new Rectangle2F(-3, -5, 6, 1); Physics.SoftCollisionBox = new Rectangle2F(-3, -5, 6, 1); graphics.DrawOffset = new Point2I(-8, -14); centerOffset = new Point2I(0, -6); }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- public CarriedTile(Tile tile) { this.tile = tile; // Physics. Physics.CollisionBox = new Rectangle2F(-3, -5, 6, 1); Physics.SoftCollisionBox = new Rectangle2F(-7, -7, 14, 14); EnablePhysics( PhysicsFlags.HasGravity | PhysicsFlags.DestroyedOutsideRoom | PhysicsFlags.CollideWorld | PhysicsFlags.HalfSolidPassable | PhysicsFlags.LedgePassable | PhysicsFlags.DestroyedInHoles); // Graphics. Graphics.DepthLayer = DepthLayer.ProjectileCarriedTile; Graphics.DrawOffset = new Point2I(-8, -13); centerOffset = new Point2I(0, -5); }
public override void OnCollideTile(Tile tile, bool isInitialCollision) { // Keep track of number of rebounds. if (reboundOffWalls && !isInitialCollision && !tile.Flags.HasFlag(TileFlags.AbsorbSeeds)) { reboundCounter++; if (reboundCounter >= GameSettings.SEED_PROJECTILE_REBOUND_COUNT) { CrashOnTile(tile, false); return; } else if (!(tile is TileSeedBouncer)) tileLocation = new Point2I(-1, -1); } // Bounce off of seed bouncers. if (tile is TileSeedBouncer) { if (AttemptBounce((TileSeedBouncer) tile)) return; } // Crash into the tile. if (!reboundOffWalls || isInitialCollision || tile.Flags.HasFlag(TileFlags.AbsorbSeeds)) CrashOnTile(tile, isInitialCollision); }
// Move the given tile to a new location. public void MoveTile(Tile tile, Point2I newLocation, int newLayer) { tile.Location = newLocation; /* if (tile.Layer != newLayer) { Rectangle2I area = tile.TileGridArea; for (int x = area.Left; x < area.Right; x++) { for (int y = area.Top; y < area.Bottom; y++) { tiles[x, y, tile.Layer] = null; tiles[x, y, newLayer] = tile; } } tile.Layer = newLayer; }*/ }
private void UpdateTileGridArea(Tile tile) { Rectangle2F tileBounds = new Rectangle2F(tile.Position, tile.Size * GameSettings.TILE_SIZE); Rectangle2I nextArea = GetTileAreaFromRect(tileBounds); Rectangle2I prevArea = tile.TileGridArea; if (nextArea != prevArea) { // Determine the highest free layer for the tile to move to. int newLayer = -1; for (int i = tile.Layer; i < layerCount; i++) { bool isLayerFree = true; for (int x = nextArea.Left; x < nextArea.Right && isLayerFree; x++) { for (int y = nextArea.Top; y < nextArea.Bottom && isLayerFree; y++) { Tile t = tiles[x, y, i]; if (t != null && t != tile) isLayerFree = false; } } if (isLayerFree) { newLayer = i; break; } } if (newLayer < 0) { RemoveTile(tile); return; } // Remove the tile from its old area. for (int x = prevArea.Left; x < prevArea.Right; x++) { for (int y = prevArea.Top; y < prevArea.Bottom; y++) { tiles[x, y, tile.Layer] = null; } } // Place the tile into its new area. for (int x = nextArea.Left; x < nextArea.Right; x++) { for (int y = nextArea.Top; y < nextArea.Bottom; y++) { tiles[x, y, tile.Layer] = tile; } } tile.TileGridArea = nextArea; } // Check for covered/uncovered tiles. Rectangle2F tileBoundsOld = tile.PreviousBounds; Rectangle2F tileBoundsNew = tile.Bounds; if (tileBoundsOld != tileBoundsNew) { foreach (Tile t in GetTilesInArea(nextArea).Union(GetTilesInArea(prevArea))) { Rectangle2F tBounds = t.Bounds; if (t != tile) { if (tileBoundsNew.Contains(tBounds) && !tileBoundsOld.Contains(tBounds)) t.OnCoverComplete(tile); else if (tileBoundsNew.Intersects(tBounds) && !tileBoundsOld.Intersects(tBounds)) t.OnCoverBegin(tile); else if (tileBoundsOld.Contains(tBounds) && !tileBoundsNew.Contains(tBounds)) t.OnUncoverBegin(tile); else if (tileBoundsOld.Intersects(tBounds) && !tileBoundsNew.Intersects(tBounds)) t.OnUncoverComplete(tile); } } } }
private bool IsTileAtGridLocation(Tile tile, int x, int y) { return (tile.TileGridArea.X == x && tile.TileGridArea.Y == y); }
//----------------------------------------------------------------------------- // Internal Methods //----------------------------------------------------------------------------- private bool IsTileAtGridLocation(Tile tile, Point2I gridLocation) { return (tile.TileGridArea.Point == gridLocation); }
// Check for climbing off the top of the ladder. private void CheckClimbingOffLadderTop(Player player, Tile ladderTile) { Rectangle2F entityBoxPrev = player.Physics.PositionedCollisionBox; Rectangle2F entityBox = Rectangle2F.Translate(entityBoxPrev, player.Physics.Velocity); Rectangle2F solidBox = ladderTile.Bounds; Rectangle2F pollLadderBoxPrev = player.Movement.ClimbCollisionBox; pollLadderBoxPrev.Point += player.Position; if (pollLadderBoxPrev.Intersects(solidBox) && entityBoxPrev.Bottom > solidBox.Top && entityBox.Bottom <= solidBox.Top) { player.Physics.VelocityY = 0.0f; player.Y = solidBox.Top - player.Physics.CollisionBox.Bottom; player.Physics.MovementCollisions[Directions.Down] = true; if (!player.Physics.CollisionInfo[Directions.Down].IsColliding) player.Physics.CollisionInfo[Directions.Down].SetCollision(ladderTile, Directions.Down); player.Movement.IsOnSideScrollLadder = false; } }
// Returns true if the entity moving up the ledge. public bool IsMovingUpLedge(Entity entity, Tile ledgeTile) { return entity.Physics.Velocity.Dot(Directions.ToVector(ledgeTile.LedgeDirection)) < 0.0f; }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- public PlayerLedgeJumpState() { ledgeBeginTile = null; isHoldingSword = false; }
private void StabTile(Tile tile) { if (player.IsOnGround) { tile.OnSwordHit(weapon); // Create cling effect. if (!tile.IsDestroyed && tile.ClingWhenStabbed) { Effect clingEffect = new EffectCling(true); Vector2F pos = player.Center + (13 * Directions.ToVector(direction)); player.RoomControl.SpawnEntity(clingEffect, pos); AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING); } } // Begin the player stab state. player.SwordStabState.Weapon = weapon; player.SwordStabState.ContinueHoldingSword = true; player.BeginState(player.SwordStabState); }
public override void OnCollideTile(Tile tile, bool isInitialCollision) { if (!isReturning && !isHooked && !isLifting) { if (tile.IsSwitchable) { // TODO: Switch with tile. hookedObject = tile; isHooked = true; timer = 0; graphics.PlayAnimation(); } else { BeginReturn(false); } // Create cling effect. Effect effect = new EffectCling(); RoomControl.SpawnEntity(effect, position + Directions.ToVector(direction) * 5.0f, zPosition); AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING); } }
public override void OnCollideTile(Tile tile, bool isInitialCollision) { Crash(isInitialCollision); }
public override void OnCollideTile(Tile tile, bool isInitialCollision) { // Create cling effect. RoomControl.SpawnEntity(new EffectCling(), position, zPosition); AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING); BeginReturn(); }
public override void OnCollideTile(Tile tile, bool isInitialCollision) { Intercept(); }
// Place a tile in the tile grid at the given location and layer. public void PlaceTile(Tile tile, int x, int y, int layer, bool initializeTile = true) { PlaceTile(tile, new Point2I(x, y), layer, initializeTile); }
public void SetTileCollision(Tile tile, int direction) { this.type = CollisionType.Tile; this.solidObject = tile; this.direction = direction; }
// Use this for placing tiles at runtime. public void PlaceTile(Tile tile, Point2I location, int layer, bool initializeTile = true) { tile.Location = location; tile.PreviousLocation = location; tile.Layer = layer; Rectangle2I area = GetTileArea(tile); tile.TileGridArea = area; for (int x = area.Left; x < area.Right; x++) { for (int y = area.Top; y < area.Bottom; y++) { tiles[x, y, layer] = tile; } } if (initializeTile) tile.Initialize(roomControl); // Check for covered tiles. Rectangle2F tileBounds = tile.Bounds; foreach (Tile t in GetTilesTouching(tileBounds)) { if (t != tile) { t.OnCoverBegin(tile); if (tileBounds.Contains(t.Bounds)) t.OnCoverComplete(tile); } } }
//----------------------------------------------------------------------------- // 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); } }
//----------------------------------------------------------------------------- // Tile Mutators //----------------------------------------------------------------------------- // Place a tile in highest empty layer at the given location. // Returns true if there was an empty space to place the tile. public bool PlaceTileOnHighestLayer(Tile tile, Point2I location) { Rectangle2F tileBounds = new Rectangle2F( location * GameSettings.TILE_SIZE, tile.Size * GameSettings.TILE_SIZE); Rectangle2I area = GetTileAreaFromRect(tileBounds); // Determine which layers are free. bool[] freeLayers = new bool[layerCount]; for (int i = 0; i < layerCount; i++) { freeLayers[i] = true; for (int x = area.Left; x < area.Right && freeLayers[i]; x++) { for (int y = area.Top; y < area.Bottom && freeLayers[i]; y++) { Tile t = tiles[x, y, i]; if (t != null) freeLayers[i] = false; } } } // Choose the highest free layer. int layer = -1; for (int i = layerCount - 1; i >= 0; i--) { if (freeLayers[i]) { layer = i; break; } } if (layer < 0) return false; // Place the tile in that layer. PlaceTile(tile, location, layer); return true; }
// Returns true if the entity is able to collide with a tile. private bool CanCollideWithTile(Entity entity, Tile checkTile) { if (checkTile.CollisionModel == null || !checkTile.IsSolid || (checkTile.IsHalfSolid && entity.Physics.PassOverHalfSolids)) return false; if (checkTile.IsLedge && entity.Physics.PassOverLedges) { if (entity.Physics.LedgeAltitude > 0 || entity.Physics.LedgeTileLocation == checkTile.Location || IsMovingDownLedge(entity, checkTile)) return false; } if (entity.Physics.CustomTileCollisionCondition != null) return entity.Physics.CustomTileCollisionCondition(checkTile); return true; }
// Remove a tile from the room. public void RemoveTile(Tile tile) { Rectangle2I area = tile.TileGridArea; for (int x = area.Left; x < area.Right; x++) { for (int y = area.Top; y < area.Bottom; y++) { tiles[x, y, tile.Layer] = null; } } tile.IsAlive = false; tile.OnRemoveFromRoom(); // Check for uncovered tiles. Rectangle2F tileBounds = tile.Bounds; foreach (Tile t in GetTilesTouching(tileBounds)) { t.OnUncoverBegin(tile); t.OnUncoverComplete(tile); } }
private void CheckLadderCollision(Player player, Tile tile) { Rectangle2F solidBox = tile.Bounds; Rectangle2F entityBoxPrev = player.Physics.PositionedCollisionBox; Rectangle2F entityBox = Rectangle2F.Translate(entityBoxPrev, player.Physics.Velocity); Rectangle2F pollLadderBox = player.Movement.ClimbCollisionBox; Rectangle2F pollLadderBoxPrev = pollLadderBox; pollLadderBox.Point += player.Position + player.Physics.Velocity; pollLadderBoxPrev.Point += player.Position; // Check if this tile is a top-most ladder. Tile checkAboveTile = player.RoomControl.TileManager.GetSurfaceTile(tile.Location - new Point2I(0, 1)); bool isTopLadder = (checkAboveTile == null || !checkAboveTile.IsLadder); // Check if stepping off of a solid object and onto the ladder. // Make sure the player is not on a flat surface aligned with the ladder top. if (!player.Movement.IsOnSideScrollLadder && pollLadderBox.Intersects(solidBox) && player.Physics.PreviousCollisionInfo[Directions.Down].IsColliding && player.Physics.PreviousCollisionInfo[Directions.Down].Tile != tile && !player.Physics.CollisionInfo[Directions.Down].IsColliding && player.Physics.VelocityY >= 0.0f && (!isTopLadder || entityBoxPrev.Bottom > solidBox.Top || player.Physics.PreviousCollisionInfo[Directions.Down].Tile == null || player.Physics.PreviousCollisionInfo[Directions.Down].Tile.Bounds.Top != solidBox.Top)) { player.Movement.IsOnSideScrollLadder = true; return; } // Make sure the player: // - This tile is a top-most ladder. // - The player isn't already climbing a ladder. // - The player is touching the ladder, // - The player was previously above the ladder, // - The player and isn't standing on something else with clipping. if (isTopLadder && !player.Movement.IsOnSideScrollLadder && entityBox.Intersects(solidBox) && entityBoxPrev.Bottom <= solidBox.Top && !player.Physics.ClipCollisionInfo[Directions.Down].IsColliding) { // If holding the [Down] button, then begin climbing the ladder instead. if (player.Movement.AllowMovementControl && Controls.Down.IsDown() && !Controls.Up.IsDown()) { player.Movement.IsOnSideScrollLadder = true; } else { // Collide with the top of the ladder. player.Physics.VelocityY = 0.0f; player.Y = solidBox.Top - player.Physics.CollisionBox.Bottom; player.Physics.MovementCollisions[Directions.Down] = true; if (!player.Physics.CollisionInfo[Directions.Down].IsColliding) player.Physics.CollisionInfo[Directions.Down].SetCollision(tile, Directions.Down); } } }
private Rectangle2I GetTileArea(Tile tile) { return GetTileAreaFromRect(tile.Bounds); }