//----------------------------------------------------------------------------- // 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); } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- // Called when the items button is pressed (A or B). public override void OnButtonPress() { // Shoot an arrow! if (ammo[currentAmmo].IsEmpty) return; Player.Direction = Player.UseDirection; Projectile projectile = new Projectile(); // General projectile.Owner = Player; projectile.Position = new Vector2F(Player.X, Player.Y - 8) + (Directions.ToVector(Player.Direction) * 8.0f); projectile.ZPosition = Player.ZPosition; projectile.Angle = Directions.ToAngle(Player.Direction); projectile.Physics.Velocity = Directions.ToVector(Player.Direction) * 3.0f; Player.Direction = Player.Direction; // Graphics. projectile.Graphics.SubStripIndex = projectile.Angle; projectile.Graphics.PlayAnimation(GameData.ANIM_PROJECTILE_PLAYER_ARROW); // Physics. projectile.Physics.CollisionBox = new Rectangle2F(-2, -2, 4, 4); projectile.EnablePhysics(PhysicsFlags.CollideWorld | PhysicsFlags.LedgePassable | PhysicsFlags.HalfSolidPassable | PhysicsFlags.DestroyedOutsideRoom); // Crash event. Vector2F v = projectile.Physics.Velocity; projectile.EventCollision += delegate() { // Create crash effect. Effect effect = new Effect(); effect.Position = projectile.Position; effect.CreateDestroyTimer(32); effect.Physics.Velocity = -(v.Normalized) * 0.25f; effect.Physics.ZVelocity = 1; effect.Physics.Gravity = 0.07f; effect.EnablePhysics(PhysicsFlags.HasGravity); effect.Graphics.IsShadowVisible = false; effect.Graphics.PlayAnimation(GameData.ANIM_PROJECTILE_PLAYER_ARROW_CRASH); RoomControl.SpawnEntity(effect); projectile.Destroy(); }; RoomControl.SpawnEntity(projectile); ammo[currentAmmo].Amount--; Player.Graphics.PlayAnimation(GameData.ANIM_PLAYER_THROW); Player.BeginBusyState(10); }
//----------------------------------------------------------------------------- // Projectile Methods //----------------------------------------------------------------------------- protected void Crash(bool isInitialCollision) { if (crashAnimation != null) { // Create crash effect. Effect effect; if (bounceOnCrash) { effect = new Effect(); effect.CreateDestroyTimer(32); effect.EnablePhysics(PhysicsFlags.HasGravity); if (!isInitialCollision) effect.Physics.Velocity = Angles.ToVector(Angles.Reverse(Angle)) * 0.25f; effect.Physics.ZVelocity = 1.0f; effect.Physics.Gravity = 0.07f; effect.Graphics.PlayAnimation(crashAnimation); } else { effect = new Effect(crashAnimation, Graphics.DepthLayer); } effect.Graphics.IsShadowVisible = false; effect.Graphics.DepthLayer = Graphics.DepthLayer; RoomControl.SpawnEntity(effect, position); DestroyAndTransform(effect); } else { Destroy(); } OnCrash(); }