/** * Method overloaded for multi player games. * @param playerID ID of the player to query. */ public Vector2 getAvatarPosition(int playerID) { if (isEnded) { VGDLUtils.getDirection(VGDLUtils.VGDLDirections.NIL); } return(avatars[playerID].getPosition()); }
public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game) { if (sprite1 == null) { throw new ArgumentException("1st sprite can't be EOS with flipDirection interaction"); } sprite1.orientation = VGDLUtils.RandomCardinalDirection(); }
private Sprite getImage(string imgPath) { const float pixelsPerUnit = 24f; //All of the VGDL images are 24x24 pixels try { return(VGDLUtils.LoadNewSprite(imgPath, pixelsPerUnit, Vector2.up)); } catch (Exception e) { Debug.LogException(e); } return(null); }
private List <Sprite> getAnimatedImages(string imagePath) { const float pixelsPerUnit = 24f; //All of the VGDL images are 24x24 pixels var theImages = new List <Sprite>(); try { var noMoreFiles = false; var i = 0; do { var currentFile = imagePath + i; if (!VGDLUtils.CheckSpriteExists(currentFile)) { noMoreFiles = true; } else { var sprite = VGDLUtils.LoadNewSprite(currentFile, pixelsPerUnit, Vector2.up); theImages.Add(sprite); } i += 1; } while (!noMoreFiles); if (theImages.Count == 0) { Debug.LogWarning("Image not found: " + imagePath); } else { image = theImages[0]; //Default. } } catch (Exception e) { Debug.LogException(e); } return(theImages); }
public virtual void preMovement() { lastrect = new Rect(rect); lastmove += 1; frameRemaining -= 1; if (images.Count > 0) { List <Sprite> allImages; var isOrientedImg = !string.IsNullOrEmpty(orientedImg); if (!isOrientedImg) { allImages = images["NONE"]; } else { allImages = images[VGDLUtils.DirectionStringFromOrientation(orientation)]; } if (allImages.Count > 0) { if (frameRate > 0 && frameRemaining <= 0) { if (allImages.Count > 0) { currentFrame = (currentFrame + 1) % allImages.Count; frameRemaining = frameRate; image = allImages[currentFrame]; } } else if (!autotiling) { image = allImages[0]; } } } }
/// <summary> /// Parse arguments from argument list and set their values on the object given. /// </summary> /// <param name="obj"></param> /// <param name="args"></param> /// <exception cref="ArgumentException"></exception> private static void parseParameters(object obj, IEnumerable <KeyValuePair <string, string> > args, bool suppressWarnings = false) { var type = obj.GetType(); var fields = type.GetFields(); var fieldMap = new Dictionary <string, FieldInfo>(); foreach (var field in fields) { if (fieldMap.ContainsKey(field.Name)) { Debug.LogError("Key [" + field.Name + "] already in fieldMap for: " + type); } fieldMap.Add(field.Name, field); } foreach (var keyValuePair in args) { if (fieldMap.ContainsKey(keyValuePair.Key)) { var fieldInfo = fieldMap[keyValuePair.Key]; if (keyValuePair.Value.Contains("[")) { //value seems to be array, validate that. if (keyValuePair.Value.Contains("]")) { var trimmed = keyValuePair.Value.Trim('[', ']'); //find list of value strings var values = trimmed.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //Reflect the ParseToArray method var methodDefinition = typeof(VGDLParser).GetMethod("ParseToArray"); //Generate the generic method, based on the field type // ReSharper disable once PossibleNullReferenceException var parseMethod = methodDefinition.MakeGenericMethod(fieldInfo.FieldType.GetElementType()); //Invoke the parse method with our values. var array = parseMethod.Invoke(null, new object[] { values }); fieldInfo.SetValue(obj, array); //this keyvalue pair has been handled, continue to the next one. continue; } else { throw new ArgumentException("Parsing parameter [" + keyValuePair.Key + "] failed, array missing ']'"); } } if (fieldInfo.FieldType.IsAssignableFrom(typeof(Color))) { //Special case for color parsing! Color color; var success = VGDLColors.ParseColor(keyValuePair.Value, out color); if (success) { fieldInfo.SetValue(obj, color); } else { Debug.LogWarning("Color [" + keyValuePair.Value + "] not found, using magenta instead"); fieldInfo.SetValue(obj, Color.magenta); } } else if (fieldInfo.FieldType.IsAssignableFrom(typeof(Vector2))) { //Special case for orientation parsing! var direction = VGDLUtils.ParseVGDLDirection(keyValuePair.Value); if (direction != VGDLUtils.VGDLDirections.NIL.getDirection()) { fieldInfo.SetValue(obj, direction); } else { Debug.LogWarning("Direction [" + keyValuePair.Value + "] not found, using 'LEFT' instead"); fieldInfo.SetValue(obj, Vector2.left); } } else { try { fieldInfo.SetValue(obj, Convert.ChangeType(keyValuePair.Value, fieldInfo.FieldType)); } catch (Exception e) { Debug.LogError("Unable to parse [" + keyValuePair.Value + "] for field [" + keyValuePair.Key + " with type: " + fieldInfo.FieldType.Name + "] on " + type.Name); throw; } } } else { //We suppress warnings for TimeEffects, because of the way they are defined //eg. [sprite1 TIME > transformToAll stype=portal stypeTo=goalPortal nextExecution=500 timer=500 repeating=False] //This means that these parameters don't all belong to the timer, some belong to the desired effect. if (!suppressWarnings) { Debug.LogWarning("Field [" + keyValuePair.Key + "] does not exist on " + type.Name); } else { if (verbose) { Debug.Log("Parameter [" + keyValuePair.Key + "] ignored on " + type.Name); } } } } }
public void loadImage() { var imgPath = string.IsNullOrEmpty(img) ? orientedImg : img; var isOrientedImg = !string.IsNullOrEmpty(orientedImg); //If no image is found, don't try and load one. if (string.IsNullOrEmpty(imgPath)) { return; } if (images.Count == 0) { //There is autotiling (disabled now) or animations if (autotiling || randomtiling >= 0 || frameRate >= 0) { if (imgPath.Contains(".png")) { imgPath = imgPath.Substring(0, imgPath.Length - 4); } var imagePathBase = imgPath + "_"; //Get all the images for each orientation if (isOrientedImg) { foreach (var dir in VGDLUtils.BASEDIRS) { var strDir = VGDLUtils.DirectionStringFromOrientation(dir); var imagePath = imagePathBase + strDir + "_"; var theImages = getAnimatedImages(imagePath); images[strDir] = theImages; } } else { var theImages = getAnimatedImages(imagePathBase); images["NONE"] = theImages; } } else { //Get all the images for each orientation if (isOrientedImg) { if (imgPath.Contains(".png")) { imgPath = imgPath.Substring(0, imgPath.Length - 4); } var base_image_file = imgPath; foreach (var dir in VGDLUtils.BASEDIRS) { var strDir = VGDLUtils.DirectionStringFromOrientation(dir); var theImages = new List <Sprite>(); var image_file = base_image_file + "_" + strDir; var onlyImage = getImage(image_file); theImages.Add(onlyImage); images[strDir] = theImages; image = theImages[0]; } } else { //Only one image. images stays empty. image = getImage(imgPath); } } } }