public void Initialize(SpriteSheetCollection spriteSheets) { SpriteSheet spriteSheet = spriteSheets.getSpriteSheet("Tree"); if (spriteSheet == null) { return; } for (int i = 1; i < 9; i += 1) { Sprite sprite = spriteSheet.getSprite(string.Concat("Tree ", i.ToString())); if (sprite == null) { return; } //chris edited this sprite.m_SpriteDepth = 0.49f; m_lTreeSprites.Add(sprite); } for (int i = 0; i < TOTAL_STARTING_TREES; i++) { Vector2 pos = new Vector2(Firecracker.random.Next(0, Firecracker.level.dimensions.X * Firecracker.level.gridSize), Firecracker.random.Next(0, Firecracker.level.dimensions.Y * Firecracker.level.gridSize)); if (Terrain.Instance == null || Terrain.Instance.isPositionWalkable(pos)) { int RandomIndex = Firecracker.random.Next(0, 4); StaticObject newTree = new StaticObject(pos, m_lTreeSprites[RandomIndex]); if (newTree != null) { Firecracker.level.addObject(newTree); m_lForestList.Add(newTree); } } } }
public static GameTile parseFrom(StreamReader input, SpriteSheetCollection spriteSheets) { if (input == null || spriteSheets == null) { return(null); } // get the object's position Variable position = Variable.parseFrom(input.ReadLine()); if (position == null || !position.id.Equals("Position", StringComparison.OrdinalIgnoreCase)) { return(null); } // Get the layer depth of this sprite Variable layerDepth = Variable.parseFrom(input.ReadLine()); if (layerDepth == null || !layerDepth.id.Equals("LayerDepth", StringComparison.OrdinalIgnoreCase)) { return(null); } // get the sprite's name Variable spriteName = Variable.parseFrom(input.ReadLine()); if (spriteName == null || !spriteName.id.Equals("Sprite Name", StringComparison.OrdinalIgnoreCase)) { return(null); } // get the name of the spritesheet in which the sprite is found Variable spriteSheetName = Variable.parseFrom(input.ReadLine()); if (spriteSheetName == null || !spriteSheetName.id.Equals("SpriteSheet Name", StringComparison.OrdinalIgnoreCase)) { return(null); } // get the object's sprite SpriteSheet spriteSheet = spriteSheets.getSpriteSheet(spriteSheetName.value); if (spriteSheet == null) { return(null); } Sprite sprite = spriteSheet.getSprite(spriteName.value); if (sprite == null) { return(null); } // parse the sprite's position String[] positionData = position.value.Split(','); if (positionData.Length != 2) { return(null); } Vector2 newPosition; try { newPosition.X = Int32.Parse(positionData[0]); newPosition.Y = Int32.Parse(positionData[1]); } catch (Exception) { return(null); } // create the object GameTile newObject = new GameTile(newPosition, sprite); newObject.sprite.m_SpriteDepth = float.Parse(layerDepth.value); newObject.updateInitialValues(); return(newObject); }
public static NPCObject parseFrom(StreamReader input, SpriteSheetCollection spriteSheets) { if (input == null || spriteSheets == null) { return(null); } // get the object's position Variable position = Variable.parseFrom(input.ReadLine()); if (position == null || !position.id.Equals("Position", StringComparison.OrdinalIgnoreCase)) { return(null); } // parse the sprite's position String[] positionData = position.value.Split(','); if (positionData.Length != 2) { return(null); } Vector2 newPosition; try { newPosition.X = Int32.Parse(positionData[0]); newPosition.Y = Int32.Parse(positionData[1]); } catch (Exception) { return(null); } // Get the layer depth of this sprite Variable layerDepth = Variable.parseFrom(input.ReadLine()); if (layerDepth == null || !layerDepth.id.Equals("LayerDepth", StringComparison.OrdinalIgnoreCase)) { return(null); } // get the name of the spritesheet in which the sprite is found Variable spriteSheetName = Variable.parseFrom(input.ReadLine()); if (spriteSheetName == null || !spriteSheetName.id.Equals("SpriteSheet Name", StringComparison.OrdinalIgnoreCase)) { return(null); } // create the object NPCObject newObject = new NPCObject(newPosition, (Sprite)null); // get the sprite's name newObject.AnimNameN = Variable.parseFrom(input.ReadLine()); if (newObject.AnimNameN == null || !newObject.AnimNameN.id.Equals("Anim Name N", StringComparison.OrdinalIgnoreCase)) { return(null); } newObject.AnimNameE = Variable.parseFrom(input.ReadLine()); if (newObject.AnimNameE == null || !newObject.AnimNameE.id.Equals("Anim Name E", StringComparison.OrdinalIgnoreCase)) { return(null); } newObject.AnimNameS = Variable.parseFrom(input.ReadLine()); if (newObject.AnimNameS == null || !newObject.AnimNameS.id.Equals("Anim Name S", StringComparison.OrdinalIgnoreCase)) { return(null); } newObject.AnimNameW = Variable.parseFrom(input.ReadLine()); if (newObject.AnimNameW == null || !newObject.AnimNameW.id.Equals("Anim Name W", StringComparison.OrdinalIgnoreCase)) { return(null); } Variable isKillable = Variable.parseFrom(input.ReadLine()); if (isKillable == null || !isKillable.id.Equals("IsKillable", StringComparison.OrdinalIgnoreCase)) { return(null); } // get the object's sprite SpriteSheet spriteSheet = spriteSheets.getSpriteSheet(spriteSheetName.value); if (spriteSheet == null) { return(null); } newObject.m_bKillable = bool.Parse(isKillable.value); //newObject.sprite.m_SpriteDepth = float.Parse(layerDepth.value); newObject.SetIsDirectionBased(true); newObject.SetDirAnimation(AnimDirection.DIR_N, newObject.AnimNameN.value); newObject.SetDirAnimation(AnimDirection.DIR_E, newObject.AnimNameE.value); newObject.SetDirAnimation(AnimDirection.DIR_S, newObject.AnimNameS.value); newObject.SetDirAnimation(AnimDirection.DIR_W, newObject.AnimNameW.value); newObject.updateInitialValues(); return(newObject); }
public static SpriteAnimation parseFrom(StreamReader input, SpriteSheetCollection spriteSheets) { if (input == null || spriteSheets == null) { return(null); } SpriteAnimation animation; VariableSystem animationProperties = new VariableSystem(); // store all of the animation properties String data; Variable property; do { data = input.ReadLine(); if (data == null) { return(null); } data = data.Trim(); if (data.Length == 0) { continue; } property = Variable.parseFrom(data); if (property == null) { return(null); } animationProperties.add(property); } while(animationProperties.size() < 7); // parse the animation name String animationName = animationProperties.getValue("Animation Name"); if (animationName == null) { return(null); } // parse the animation type SpriteAnimationType animationType = parseType(animationProperties.getValue("Animation Type")); if (animationType == SpriteAnimationType.Invalid) { return(null); } // parse the duration of the animation float duration; try { duration = float.Parse(animationProperties.getValue("Animation Duration")); } catch (Exception) { return(null); } if (duration <= 0) { return(null); } // parse the number of frames in the animation int numberOfFrames; try { numberOfFrames = int.Parse(animationProperties.getValue("Number of Frames")); } catch (Exception) { return(null); } if (numberOfFrames <= 0) { return(null); } // get the sprite sheet name String spriteSheetName = animationProperties.getValue("SpriteSheet Name"); if (spriteSheetName == null) { return(null); } // get the sprite name String spriteName = animationProperties.getValue("Sprite Name"); if (spriteName == null) { return(null); } string startIndex = animationProperties.getValue("Start Index"); int iStartIndex = 1; if (startIndex != null) { iStartIndex = int.Parse(startIndex); } animation = new SpriteAnimation(animationName, duration, animationType); // get the sprite sheet which contains the animation SpriteSheet spriteSheet = spriteSheets.getSpriteSheet(spriteSheetName); if (spriteSheet == null) { return(null); } // obtain and add the sprites to the sprite animation Sprite sprite; for (int i = 0; i < numberOfFrames; i++) { sprite = spriteSheet.getSprite(spriteName + " " + (i + iStartIndex)); if (sprite == null) { return(null); } animation.addSprite(sprite); } return(animation); }