private static void SpawnEntity(EntityLayer layer, int entityIndex, int x, int y) { if (entityIndex < 0 || entityIndex >= classes.Length || classes[entityIndex] == null) return; Vector2 position = new Vector2((x + 0.5f) * tileSize, (y + 0.5f) * tileSize); Entity entity = (Entity)Activator.CreateInstance(classes[entityIndex], position); layer.AddComponent(entity); }
private static void ParseEntity(string line, EntityLayer entities) { string[] parameters = line.Split(' '); if (parameters.Length<5) { Trace.WriteLine("Entity requires at least 4 parameters (type x y orientation)."); return; } Vector2 position = new Vector2(); if (!float.TryParse(parameters[2], out position.X)) { Trace.WriteLine("Error parsing entity x."); return; } if (!float.TryParse(parameters[3], out position.Y)) { Trace.WriteLine("Error parsing entity y."); return; } float orientation = 0; if (!float.TryParse(parameters[4], out orientation)) { Trace.WriteLine("Error parsing entity orientation."); return; } int type = -1; for (int i = 0; i < EntityList.Length; i++) { if (ShortTypeName(EntityList[i]) == parameters[1]) { type =i; break; } } if (type < 0) { Trace.WriteLine("Could not find entity type "+parameters[1]+"."); return; } Entity entity = (Entity)Activator.CreateInstance(EntityList[type], position); entity.Orientation = MathHelper.ToRadians(orientation); entities.AddComponent(entity); ParseProperties(entity, parameters, 5); }
private static void AddTile(int x, int y, Type tile, EntityLayer entities) { Vector2 position = new Vector2((x + 0.5f) * TileSize, (y + 0.5f) * TileSize); Entity entity = (Entity)Activator.CreateInstance(tile, position); entity.Properties.Ints["isTile"] = 1; entities.AddComponent(entity); }