/// <summary> /// After a new effect is created based on an available effect mold, it's finally given life /// </summary> /// <param name="lifespan">The duration this effect should live for</param> /// <param name="offset">The offset of this effects spawn location. If it is not given a source, this will offset from 0,0</param> /// <param name="follow_source">Whether or not this effect should move with its source emitter</param> /// <param name="source">The source emitter of the effect</param> public void Create_Effect( float lifespan, Vector2 offset, bool follow_source, Character source, Vector2 velocity) { this.lifespan = lifespan; this.Velocity = velocity; if (source == null) { this.direction = Shared.Direction.RIGHT; follow_source = false; this.position = offset; this.Source_Offset = Vector2.Zero; } else { this.follow_source = follow_source; this.Source = source; this.direction = source.Direction; this.position = source.Position; this.Source_Offset = offset; } if (!follow_source) { position += Source_Offset; } }
// ---------------------------------- /// <summary> /// Safe walk logic- keeps NPC's from stepping to their DOOM /// decision making /// </summary> /// <param name="direction">The direction to walk</param> public bool Safe_Walk(Shared.Direction direction) { host.Direction = direction; if (CollisionManager.Safe_Step(host)) { if (CollisionManager.Wall_Collision(host, direction)) { if (CollisionManager.Jumpable_Terrain(host)) { host.Try_Jump(); } else if (!host.Airborne) { Turn_Around(); } } host.Try_Walk(direction); return(true); } else if (CollisionManager.Safe_Drop(host)) { host.Try_Walk(direction); return(true); } return(false); }
// ---------------------------------- /// <summary> /// Chase is similar to Smart Movement, but much more reckless. /// </summary> /// <param name="destination">The destination our host wants to move to</param> public void Chase(Vector2 destination, string movement = "walk") { // ---------------------------------- bool horizontal_tracking = false; Vector2 source_pos = host.Grid_Position; Shared.Direction dest_direction = Shared.Direction.NONE; // ---------------------------------- // If the destination X is greater, it's too the right if (destination.X > source_pos.X) { host.Direction = Shared.Direction.RIGHT; dest_direction = Shared.Direction.RIGHT; horizontal_tracking = true; } // ---------------------------------- // Less than, it's too the left. else if (destination.X < source_pos.X) { host.Direction = Shared.Direction.LEFT; dest_direction = Shared.Direction.LEFT; horizontal_tracking = true; } // ---------------------------------- // Begin tracking toward horizontal destination if (horizontal_tracking) { if (!CollisionManager.Safe_Step(host) && destination.Y <= host.Grid_Position.Y) { host.Try_Jump(); } if (movement == "run") { host.Try_Run(dest_direction); } else { host.Try_Walk(dest_direction); } // ---------------------------------- // We've hit a wall. Jump to see if that resolves our oh so // complicated dilemma if (CollisionManager.Wall_Collision(host, dest_direction)) { if (Shared.Active_World.Get_Terrain_At((int)destination.X, (int)destination.Y) == null) { if (CollisionManager.Jumpable_Terrain(host)) { host.Try_Jump(); } } } } }
// ---------------------------------- /// <summary> /// Try entity walk /// </summary> public virtual bool Try_Walk(Shared.Direction direction) { if (!dead && !busy) { walking = true; running = false; this.direction = direction; Set_State(Shared.EntityState.WALKING); return(true); } return(false); }
// ---------------------------------- /// <summary> /// Try entity run /// </summary> public bool Try_Run(Shared.Direction direction) { // Check all possible interferrence if (!dead && !busy) { walking = false; running = true; this.direction = direction; Set_State(Shared.EntityState.RUNNING); return(true); } return(false); }
public void FamFamSpritesButtonTestPassedAttributesObjectsForInnerSpan() { //Arrange HtmlHelper helper = null; string inText = string.Empty; FamFamSpritesEnum inIcon = new FamFamSpritesEnum(); Shared.ButtonType inButtonType = new Shared.ButtonType(); Shared.Direction inDirection = new Shared.Direction(); object htmlAttributes = null; object innerSpanHtmlAttributes = new { id = "idTest" }; string expected = "id=\"idTest\""; //Act string actual = FamFamSpritesIconButtonsHtmlHelper.FamFamSpritesButton(helper, inText, inIcon, inButtonType, inDirection, htmlAttributes, innerSpanHtmlAttributes); //Assert Assert.IsTrue(actual.Contains(expected)); }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #region Range & LoS checks /// <summary> /// Intersection method that tells a character entity if a target is within a range. /// </summary> /// <param name="source">The origin character of our search</param> /// <param name="target">The target they're looking for</param> /// <param name="range">The range in which to search</param> /// <param name="in_range">A boolean out telling us whether or not the target was in range</param> /// <param name="direction">The direction in which the target was found, if any</param> public static void In_Range(Character source, Entity target, int range, out bool in_range, out Shared.Direction direction) { // Produce the range rectangle //------------------------------------- Rectangle range_box = new Rectangle ( source.Get_Bounds().X - (int)(((range * Shared.Block_Dimension * Shared.Pixel_Scale) * 2) / 2), source.Get_Bounds().Y - (int)(((range * Shared.Block_Dimension * Shared.Pixel_Scale) * 2) / 2), source.Get_Bounds().Width + (int)(((range * Shared.Block_Dimension * Shared.Pixel_Scale) * 2)), source.Get_Bounds().Height + (int)(((range * Shared.Block_Dimension * Shared.Pixel_Scale) * 2)) ); //------------------------------------- // Debugger draws range boxes if (Shared.Debug) { source.Draw_Box(range_box, 1, Color.Green); } //------------------------------------- // Set default outs //------------------------------------- in_range = false; direction = Shared.Direction.NONE; if (range_box.Intersects(target.Get_Bounds())) { // Target is within range. //------------------------------------- in_range = true; int center_of = range_box.Left + (range_box.Width / 2); if (target.Get_Bounds().Right < center_of) { // Then the target is on the left side //------------------------------------- direction = Shared.Direction.LEFT; } else { // Otherwise the target is on the right. //------------------------------------- direction = Shared.Direction.RIGHT; } } }
/// <summary> /// Wall Collision Checker /// </summary> public static bool Wall_Collision(Character character_entity, Shared.Direction direction) { //------------------------------------- // Produce a quick list of terrain entities within a direct radius of the character //------------------------------------- List <Terrain> quick_terrain_list = new List <Terrain>(); // Get the side we're checking int x_side = 1; // 1 = Right side, -1 = Left side if (direction == Shared.Direction.LEFT) { x_side = -1; } //------------------------------------- // Block Adjacent Terrain block1 = Shared.Active_World.Get_Terrain_At( (int)character_entity.Grid_Position.X + x_side, (int)character_entity.Grid_Position.Y); if (block1 != null) { quick_terrain_list.Add(block1); } //------------------------------------- // Block Below Adjacent Terrain block2 = Shared.Active_World.Get_Terrain_At( (int)character_entity.Grid_Position.X + x_side, (int)character_entity.Grid_Position.Y + 1); if (block2 != null) { quick_terrain_list.Add(block2); } //------------------------------------- // Block Above Adjacent Terrain block3 = Shared.Active_World.Get_Terrain_At( (int)character_entity.Grid_Position.X + x_side, (int)character_entity.Grid_Position.Y - 1); if (block3 != null) { quick_terrain_list.Add(block3); } //------------------------------------- if (quick_terrain_list.Count() == 0) { return(false); // There are no blocks worth checking on this side, leave collision check } //------------------------------------- // Retrieve the character entities wall collision bound box //------------------------------------- Rectangle bound_box = new Rectangle ( character_entity.Get_Bounds().X - 3, character_entity.Get_Bounds().Y, character_entity.Get_Bounds().Width + 6, character_entity.Get_Bounds().Height ); //------------------------------------- foreach (Terrain terrain_entity in quick_terrain_list) { if (bound_box.Intersects(terrain_entity.Get_Bounds())) { Rectangle c_bound = bound_box; Rectangle t_bound = terrain_entity.Get_Bounds(); //-------------------- // We should first make sure this intersected peice of terrain isn't cleanly above or below // the character entity //-------------------- if (c_bound.Top > t_bound.Bottom || c_bound.Bottom < t_bound.Top) { return(false); } // Safety check informs us if this is a floor rather than a wall. // ------------------- if ((c_bound.Bottom - t_bound.Top) < 5) { return(false); } //-------------------- if (direction == Shared.Direction.LEFT) { // Left Wall Check // ------------------- if (c_bound.Left < t_bound.Right && c_bound.Right > t_bound.Right) { // This bit helps ensure players don't exploit spam // jumping against hole walls to breach the wall. if (character_entity.Get_Bounds().Left < t_bound.Right) { character_entity.Shift(new Vector2(-1, 0)); } // ------------------- return(true); } // ------------------- } if (direction == Shared.Direction.RIGHT) { // Right Wall Check // ------------------- if (c_bound.Right > t_bound.Left && c_bound.Left < t_bound.Left) { // This bit helps ensure players don't exploit spam // jumping against hole walls to breach the wall. if (character_entity.Get_Bounds().Right > t_bound.Left) { character_entity.Shift(new Vector2(1, 0)); } // ------------------- return(true); } // ------------------- } } } //------------------------------------- return(false); }
public void FamFamSpritesLinkTest() { HtmlHelper helper = null; // TODO: Initialize to an appropriate value string inText = string.Empty; // TODO: Initialize to an appropriate value FamFamSpritesEnum inIcon = new FamFamSpritesEnum(); // TODO: Initialize to an appropriate value string inUrl = string.Empty; // TODO: Initialize to an appropriate value Shared.Direction inDirection = new Shared.Direction(); // TODO: Initialize to an appropriate value object htmlAttributes = null; // TODO: Initialize to an appropriate value object innerSpanHtmlAttributes = null; // TODO: Initialize to an appropriate value object innerIconHtmlAttributes = null; // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; actual = FamFamSpritesIconButtonsHtmlHelper.FamFamSpritesLink(helper, inText, inIcon, inUrl, inDirection, htmlAttributes, innerSpanHtmlAttributes, innerIconHtmlAttributes); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }