public override void OnLand() { // Collide with monsters. foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft)) { monster.TriggerInteraction(InteractionType.ThrownObject, this); if (IsDestroyed) { return; } } // Collide with surface tiles. Point2I tileLoc = RoomControl.GetTileLocation(position); if (RoomControl.IsTileInBounds(tileLoc)) { Tile tile = RoomControl.GetTopTile(tileLoc); if (tile != null) { tile.OnHitByThrownObject(this); if (IsDestroyed) { return; } } } Break(); }
public override void Update() { AudioSystem.LoopSoundWhileActive(GameData.SOUND_BOOMERANG_LOOP); // Check for boomerangable tiles. if (itemBoomerang.Level == Item.Level2) { Point2I tileLoc = RoomControl.GetTileLocation(position); if (tileLoc != tileLocation && RoomControl.IsTileInBounds(tileLoc)) { Tile tile = RoomControl.GetTopTile(tileLoc); if (tile != null) { tile.OnBoomerang(); } } tileLocation = tileLoc; } // Pickup collectibles. foreach (Collectible collectible in Physics.GetEntitiesMeeting <Collectible>(CollisionBoxType.Soft)) { if (collectible.IsPickupable && collectible.IsCollectibleWithItems) { collectibles.Add(collectible); collectible.Destroy(); BeginReturn(); } } base.Update(); }
protected void CheckInitialCollision() { if (physics.IsPlaceMeetingSolid(position, physics.CollisionBox)) { Point2I tileLocation = RoomControl.GetTileLocation(Position); Tile tile = RoomControl.GetTopTile(tileLocation); OnCollideTile(tile, true); } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void OnLand() { if (IsDestroyed) { return; } // Collide with monsters. foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft)) { monster.OnSeedHit(this); if (IsDestroyed) { return; } } // Notify the tile of the seed hitting it. Point2I location = RoomControl.GetTileLocation(position); Tile tile = RoomControl.GetTopTile(location); if (tile != null) { tile.OnHitByProjectile(this); if (IsDestroyed) { return; } } // Spawn the seed effect. Entity effect = DestroyWithSatchelEffect(); if (type == SeedType.Scent) { if (RoomControl.IsSideScrolling) { effect.Y += 3; } } else if (type == SeedType.Ember) { if (RoomControl.IsSideScrolling) { effect.Y += 1; } effect.Physics.HasGravity = false; } else if (type == SeedType.Mystery) { if (RoomControl.IsSideScrolling) { effect.Y -= 1; } } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void Initialize() { base.Initialize(); // Find the center position of the hole tile. Point2I location = RoomControl.GetTileLocation(position); holeCenterPosition = (Vector2F)location + new Vector2F(0.5f, 0.5f); holeCenterPosition *= GameSettings.TILE_SIZE; }
public override void Update() { base.Update(); // Mark jump pad tiles that are jumped over. Player player = RoomControl.Player; if (player.IsInAir && RoomControl.GetTileLocation(player.Position) == Location && !markedTiles.Contains(this)) { markedTiles.Add(this); } }
public override void Update() { faceDirection = direction; bool facePlayer = flags.HasFlag(NPCFlags.AlwaysFacePlayer); // Check if the player is nearby. if (!facePlayer && flags.HasFlag(NPCFlags.FacePlayerWhenNear)) { Point2I a = RoomControl.GetTileLocation(Center); Point2I b = RoomControl.GetTileLocation(RoomControl.Player.Center); if (Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y) <= sightDistance) { facePlayer = true; } } if (facePlayer) { if (flags.HasFlag(NPCFlags.OnlyFaceHorizontal)) { // Face the player horizontally. faceDirection = Directions.Right; if (RoomControl.Player.Center.X < Center.X) { faceDirection = Directions.Left; } } else if (flags.HasFlag(NPCFlags.OnlyFaceVertical)) { // Face the player vertically. faceDirection = Directions.Down; if (RoomControl.Player.Center.Y < Center.Y) { faceDirection = Directions.Up; } } else { // Face the player in all directions. Vector2F lookVector = RoomControl.Player.Center - Center; lookVector.Y *= -1; faceDirection = Directions.RoundFromRadians( GMath.ConvertToRadians(lookVector.Direction)); } } Graphics.SubStripIndex = faceDirection; base.Update(); }
public override void OnDestroyTimerDone() { // Burn tiles. Point2I location = RoomControl.GetTileLocation(position); if (RoomControl.IsTileInBounds(location)) { Tile tile = RoomControl.GetTopTile(location); if (tile != null) { tile.OnBurn(); } } Destroy(); }
private void OnPlayerLand(Player player) { Point2I playerTileLocation = RoomControl.GetTileLocation(player.Position); // Toggle all tiles that were jumped over (except the one landed on). if (playerJumpStartTileLocation != playerTileLocation) { foreach (TileColorJumpPad tile in markedTiles) { if (tile.Location != playerJumpStartTileLocation) { tile.CycleColor(); } } markedTiles.Clear(); } }
public override void Update() { base.Update(); // Check if the player is on top of this tile. Player player = RoomControl.Player; if (RoomControl.GetTileLocation(player.Position) == Location) { crumbleTimer++; if (crumbleTimer > GameSettings.TILE_CRACKED_FLOOR_CRUMBLE_DELAY) { Crumble(); } } else { crumbleTimer = 0; } }
public override void OnLand() { base.OnLand(); // Notify the tile we landed on. Tile tile = RoomControl.GetTopTile(RoomControl.GetTileLocation(Position)); if (tile != null) { tile.OnLand(movement.JumpStartTile); } movement.JumpStartTile = -Point2I.One; if (eventLand != null) { eventLand(this); } Physics.Gravity = GameSettings.DEFAULT_GRAVITY; AudioSystem.PlaySound(GameData.SOUND_PLAYER_LAND); }
private void OnPlayerJump(Player player) { // Remember the players location upon jumping. playerJumpStartTileLocation = RoomControl.GetTileLocation(player.Position); }
//----------------------------------------------------------------------------- // Internal methods //----------------------------------------------------------------------------- private void PerformDig(PlayerState state) { // Look for tiles to dig up. float distance = 6.5f; Vector2F center = Player.Center; if (Directions.IsVertical(Player.Direction)) { distance = 7.5f; } else { center.Y += 4.0f; } Vector2F hotspot = GMath.Round(center) + (Directions.ToVector(Player.Direction) * distance); Point2I tileLoc = RoomControl.GetTileLocation(hotspot); if (!RoomControl.IsTileInBounds(tileLoc)) { return; } Tile tile = RoomControl.GetTopTile(tileLoc); if (tile != null && tile.OnDig(Player.Direction)) { // Spawn dirt effect. Effect effect = new Effect(); effect.Graphics.DepthLayer = DepthLayer.EffectDirt; effect.CreateDestroyTimer(15); effect.EnablePhysics(PhysicsFlags.HasGravity); effect.Physics.Velocity = Directions.ToVector(Player.Direction) * 0.5f; effect.Graphics.IsShadowVisible = false; effect.Graphics.PlayAnimation(GameData.ANIM_EFFECT_DIRT); effect.Graphics.SubStripIndex = Player.Direction; if (Directions.IsHorizontal(Player.Direction)) { effect.Physics.ZVelocity = 3.0f; effect.Physics.Gravity = 0.5f; } else { effect.Physics.ZVelocity = 2.5f; effect.Physics.Gravity = 0.4f; } RoomControl.SpawnEntity(effect, tile.Center); AudioSystem.PlaySound(GameData.SOUND_SHOVEL); } else { AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING); } // Check for monster interactions. Rectangle2I shovelHitBox = new Rectangle2I(-4, -4, 8, 8); shovelHitBox.Point += (Point2I)Player.CenterOffset; shovelHitBox.ExtendEdge(Player.Direction, 7); foreach (Monster monster in Player.Physics.GetEntitiesMeeting <Monster>(shovelHitBox, CollisionBoxType.Soft)) { monster.TriggerInteraction(InteractionType.Shovel, Player); } }
public override void Update() { // Check if collided. if (physics.IsColliding && eventCollision != null) { eventCollision(); if (IsDestroyed) { return; } } // Collide with tiles. if (physics.IsColliding) { CollisionType type = CollisionType.RoomEdge; Tile tile = null; foreach (CollisionInfo collision in Physics.GetCollisions()) { type = collision.Type; tile = collision.Tile; break; } if (tile != null) { if (owner == RoomControl.Player) { tile.OnHitByProjectile(this); if (IsDestroyed) { return; } } OnCollideTile(tile, false); if (IsDestroyed) { return; } } else if (type == CollisionType.RoomEdge) { OnCollideRoomEdge(); if (IsDestroyed) { return; } } } // Notify surface tiles the projectile is hovering over. Point2I tileLoc = RoomControl.GetTileLocation(position); if (tileLoc != tileLocation && RoomControl.IsTileInBounds(tileLoc) && zPosition < 10.0f) // TODO: magic number { Tile tile = RoomControl.GetTopTile(tileLoc); if (tile != null) { tile.OnHitByProjectile(this); if (IsDestroyed) { return; } } } tileLocation = tileLoc; if (owner is Player) { // Collide with monster tools. foreach (Monster monster in RoomControl.GetEntitiesOfType <Monster>()) { foreach (UnitTool tool in monster.EquippedTools) { if (Physics.PositionedCollisionBox.Intersects(tool.PositionedCollisionBox)) { tool.OnHitProjectile(this); if (IsDestroyed) { return; } } } } // Collide with monsters. foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft)) { OnCollideMonster(monster); if (IsDestroyed) { return; } } } else { Player player = RoomControl.Player; // Collide with the player's tools. foreach (UnitTool tool in player.EquippedTools) { if (Physics.PositionedCollisionBox.Intersects(tool.PositionedCollisionBox)) { tool.OnHitProjectile(this); if (IsDestroyed) { return; } } } // Collide with the player. if (Physics.IsMeetingEntity(player, CollisionBoxType.Soft)) { OnCollidePlayer(player); if (IsDestroyed) { return; } } } if (syncAnimationWithDirection) { Graphics.SubStripIndex = direction; } else if (syncAnimationWithAngle) { Graphics.SubStripIndex = angle; } base.Update(); }