private void ProcessTileProperties() { TileMapPropertyFinder finder = new TileMapPropertyFinder(currentLevel); foreach (var propertyLocation in finder.GetPropertyLocations()) { var properties = propertyLocation.Properties; if (properties.ContainsKey("EntityType")) { float worldX = propertyLocation.WorldX; float worldY = propertyLocation.WorldY; if (properties.ContainsKey("YOffset")) { string yOffsetAsString = properties ["YOffset"]; float yOffset = 0; float.TryParse(yOffsetAsString, out yOffset); worldY += yOffset; } bool created = TryCreateEntity(properties ["EntityType"], worldX, worldY); if (created) { propertyLocation.Layer.RemoveTile(propertyLocation.TileCoordinates); } } else if (properties.ContainsKey("RemoveMe")) { propertyLocation.Layer.RemoveTile(propertyLocation.TileCoordinates); } } touchScreen = new TouchScreenInput(gameplayLayer); }
private void ProcessTileProperties() { TileMapPropertyFinder finder = new TileMapPropertyFinder(currentLevel); foreach (var propertyLocation in finder.GetPropertyLocations()) { var properties = propertyLocation.Properties; if (properties.ContainsKey("EntityType")) /*Determines entity type ie. Player, Mouse*/ { float worldX = propertyLocation.WorldX; float worldY = propertyLocation.WorldY; if (properties.ContainsKey("YOffset")) /*Determines Y-axis pixel offset*/ { string yOffsetAsString = properties["YOffset"]; float yOffset = 0; float.TryParse(yOffsetAsString, out yOffset); worldY += yOffset; } bool created = TryCreateEntity(properties["EntityType"], worldX, worldY); if (created) { propertyLocation.Layer.RemoveTile(propertyLocation.TileCoordinates); } else if (properties.ContainsKey("RemoveMe")) /*Removes tiles*/ { propertyLocation.Layer.RemoveTile(propertyLocation.TileCoordinates); } } } touchScreen = new TouchScreenInput(gameplayLayer); ///ERROR FREE CLASS, ALL GOOD }
public void PopulateFrom(CCTileMap tileMap) { tileDimension = (int)(tileMap.TileTexelSize.Width + .5f); TileMapPropertyFinder finder = new TileMapPropertyFinder(tileMap); foreach (var propertyLocation in finder.GetPropertyLocations()) { if (propertyLocation.Properties.ContainsKey("SolidCollision")) { float centerX = propertyLocation.WorldX; float centerY = propertyLocation.WorldY; float left = centerX - tileDimension / 2.0f; float bottom = centerY - tileDimension / 2.0f; RectWithDirection rectangle = new RectWithDirection { Left = left, Bottom = bottom, Width = tileDimension, Height = tileDimension }; collisions.Add(rectangle); } } // Sort by XAxis to speed future searches: collisions = collisions.OrderBy(item => item.Left).ToList(); // now let's adjust the directions that these point for (int i = 0; i < collisions.Count; i++) { var rect = collisions[i]; // By default rectangles can reposition objects in all directions: int valueToAssign = (int)Directions.All; float centerX = rect.CenterX; float centerY = rect.CenterY; // If there are collisions on the sides, then this // rectangle can no longer repositon objects in that direction. if (HasCollisionAt(centerX - tileDimension, centerY)) { valueToAssign -= (int)Directions.Left; } if (HasCollisionAt(centerX + tileDimension, centerY)) { valueToAssign -= (int)Directions.Right; } if (HasCollisionAt(centerX, centerY + tileDimension)) { valueToAssign -= (int)Directions.Up; } if (HasCollisionAt(centerX, centerY - tileDimension)) { valueToAssign -= (int)Directions.Down; } rect.Directions = (Directions)valueToAssign; collisions[i] = rect; } for (int i = collisions.Count - 1; i > -1; i--) { if (collisions[i].Directions == Directions.None) { collisions.RemoveAt(i); } } }