public void Update_Platforms(Layer layer, Camera camera) { //updte camera position, then use distance travelled to lower platform density logarithmicly distance_travelled += Math.Abs(camera_position.Y - camera.Position.Y); camera_position = camera.Position; current_density = starting_density - (int)(Math.Log((distance_travelled + 1), 2) + (distance_travelled / 250)); current_density = (int)((-.001 * distance_travelled) + starting_density); // https://stackoverflow.com/questions/1582285/how-to-remove-elements-from-a-generic-list-while-iterating-over-it if (Remove_Platforms(layer.Objects)) { layer.Objects.Add(Valid_Keystone(layer.Objects)); } while (layer.Objects.Count < current_density) { PlatformObject new_platform = Valid_Platform(layer.Objects); layer.Objects.Add(new_platform); } updates++; if (updates % 1000 == 0) { AbsObject temp = Select_Item(layer.Objects); layer.Objects.Add(temp); } }
//try some weighted average selection changing by distance travelled private PlatformObject Select_Type(List <AbsObject> absObjects) { PlatformObject result; Random random_generator = new Random(DateTime.Now.Millisecond); //disappearing platforms have 10% chance, moving a 40% (50% culmulative), and normal 50% (total 100%) //get a random number, then adjust by distance travelled double odds = random_generator.NextDouble(); //40,000 gives 0.025 @1,000; 0.05 @2000; 0.75 @3000 etc, by 20,000 travelled there will be no more standard platforms double adjust = distance_travelled / 40000.0; odds -= adjust; if (odds < 0.1) { result = new PlatformObject(new Vector2(), new Vector2(), -1, content); } else if (odds < 0.5) { result = new PlatformObject(new Vector2(), 300, content); } else { result = new PlatformObject(new Vector2(), -1, content); } return(result); }
//private bool Check_Keystone(PlatformObject platformObject) //{ // bool result = false; // if((platformObject.Position.X > (avatarObject.Position.X + max_jump.X)) || platformObject.Position.X < (avatarObject.Position.X - max_jump.X) || !platformObject.isVisible) // { // result = true; // platformObject.isVisible = false; // } // return result; //} private bool Remove_Platforms(List <AbsObject> absObjects) { bool result = false; // make use of the isVisible bool in absObject, no need to add another variable to platObject foreach (AbsObject platform in absObjects) { if (platform is PlatformObject) { PlatformObject temp = (PlatformObject)platform; BoundingBox temp_box = (BoundingBox)temp.Hitbox; if (temp.Position.X != temp_box.Min.X && temp.Position.Y != temp_box.Min.Y) { //Console.WriteLine("hitbox mismatch"); temp.Sprite = new SpriteStatic(content.Load <Texture2D>("used_platform"), true); temp.hitbox_rep = content.Load <Texture2D>("hitbox_wrong"); } //50 is arbitrary padding if (platform.Position.Y > screen_dimensions.Y + camera_position.Y + 100) { platform.isVisible = false; if (temp.keystone) { result = true; } } } } absObjects.RemoveAll(platform => platform.isVisible == false); return(result); }
private bool Remove_Platforms(List <AbsObject> absObjects) { bool result = false; // make use of the isVisible bool in absObject, no need to add another variable to platObject foreach (AbsObject platform in absObjects) { if (platform is PlatformObject) { PlatformObject temp = (PlatformObject)platform; //50 is arbitrary padding if (temp.keystone) { result = result || Check_Keystone(temp); } if (platform.Position.Y > screen_dimensions.Y + camera_position.Y + 50) { platform.isVisible = false; if (temp.keystone) { result = true; } } } } absObjects.RemoveAll(platform => platform.isVisible == false); return(result); }
private bool Check_Keystone(PlatformObject platformObject) { bool result = false; if ((platformObject.Position.X > (avatarObject.Position.X + max_jump.X)) || platformObject.Position.X < (avatarObject.Position.X - max_jump.X) || !platformObject.isVisible) { result = true; platformObject.isVisible = false; } return(result); }
// add initial platoforms to the layer public void Initialize(Layer layer) { max_jump = Find_Max_Jump(); // use this max jump to make sure there are some platforms that the avatar can reach, // these platforms will be refered to as the 'keystone' platforms // layer.Objects.Add(Valid_Keystone(layer.Objects)); // layer.Objects.Add(Valid_Keystone(layer.Objects)); // assume the call to initalize is before adding the avatar to the layer while (layer.Objects.Count < starting_density) { PlatformObject new_platform = Valid_Platform_Init(layer.Objects); layer.Objects.Add(new_platform); } }
//this code duplication :( private PlatformObject Valid_Keystone(List <AbsObject> absObjects) { //60 updates, hoping for ~5 seconds PlatformObject result = new PlatformObject(Find_Keystone_Location(absObjects), 300, content); //First find some location on screen with the avatar, then check if that location is valid (does not //cause any overlapping with other platforms) int i = 0; while (!(Check_Location(result, absObjects)) && (i < 15)) { Vector2 possible_location = Find_Keystone_Location(absObjects); result.Position = possible_location; //n.b. hitbox does not currently update automatically when given a new position result.Hitbox = new BoundingBox(new Vector3(possible_location.X, possible_location.Y, 0), new Vector3(possible_location.X + platform_size.X, possible_location.Y + platform_size.Y, 0)); i++; } result.keystone = true; return(result); }
//creates (and returns) a new platform that does not intersect with any current platforms private PlatformObject Valid_Platform(List <AbsObject> absObjects) { PlatformObject result = Select_Type(absObjects); result.Position = Find_Location(absObjects); //PlatformObject result = new PlatformObject(Find_Location(absObjects), -1, content); //First find some location on screen with the avatar, then check if that location is valid (does not //cause any overlapping with other platforms) while (!(Check_Location(result, absObjects))) { Vector2 possible_location = Find_Location(absObjects); result.Position = possible_location; //n.b. hitbox does not currently update automatically when given a new position result.Hitbox = new BoundingBox(new Vector3(possible_location.X, possible_location.Y, 0), new Vector3(possible_location.X + platform_size.X, possible_location.Y + platform_size.Y, 0)); } if (result.IsMoving) { Vector2 start = result.Position; Vector2 end = new Vector2(start.X + 250, start.Y); result.Change_Range(start, end); } return(result); }
public NonMovingPlatformState(PlatformObject platObj) : base(platObj) { }
public AbsPlatState(PlatformObject platform) { this.platform = platform; // factory = new PlatformFactory(platform.content); this.platform.Sprite = factory.build(platform.Position, this); }