//Environment Constructor public Environment() { background = Game1.environmentBackground; Input = new InputManager(); map = new Map(); justClicked = false; }
public override void Create(Map map) { DestructableBrick newBrick = new DestructableBrick(position, false); position = toolBoxPosition; map.TBIList.NewBricks.Add(newBrick); map.TBIList.FixedBrickList.Add(newBrick); }
//Environment Constructor public AngryBallsEnvironment() { //Initialize the Buttons playPauseButton = new PlayPauseButton(gameState); builderButton = new BuilderButton(gameState); background = Game1.environmentBackground; border = Game1.borderImage; bigCog = Game1.bigCog; clawOpen = Game1.clawOpen; Input = new InputManager(); map = new Map(); //justClicked = false; toolBox = new ToolBox(); gameState = GameState.run; angryBall = new FarseerBall(ballStartPose); //Physics Bodies for Walls leftWall = BodyFactory.CreateRectangle(Game1.world, UnitConverter.toSimSpace(10), UnitConverter.toSimSpace(2450), 1.0f, leftWallPosition); leftWall.BodyType = BodyType.Static; rightWall = BodyFactory.CreateRectangle(Game1.world, UnitConverter.toSimSpace(10), UnitConverter.toSimSpace(2550), 1.0f, rightWallPosition); rightWall.BodyType = BodyType.Static; ceiling = BodyFactory.CreateRectangle(Game1.world, UnitConverter.toSimSpace(960), UnitConverter.toSimSpace(10), 1.0f, ceilingPosition); ceiling.BodyType = BodyType.Static; floor = BodyFactory.CreateRectangle(Game1.world, UnitConverter.toSimSpace(960), UnitConverter.toSimSpace(10), 1.0f, floorPosition); floor.BodyType = BodyType.Static; }
public void WriteLevel(Map map, string name, AngryBallsEnvironment.GameState gameState) { if (gameState == AngryBallsEnvironment.GameState.dialog) { AngryBallsEnvironment.name = name; jsonWriter = new JSONEditor(); jsonWriter.WriteLevel(map, name); } }
public void ReadLevel(Map map, string name, AngryBallsEnvironment.GameState gameState) { if (name == null) name = "default"; if (File.Exists("Levels/LevelDemo/" + name + ".json")) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(TBIList)); //clear out all the existing TBI's foreach (FixedBrick element in map.TBIList.FixedBrickList.Reverse<FixedBrick>()) { map.TBIList.FixedBrickList.Remove(element); } foreach (ProxMine element in map.TBIList.placedMines.Reverse<ProxMine>()) { map.TBIList.placedMines.Remove(element); } foreach (ProxMine element in map.TBIList.unPlacedMines.Reverse<ProxMine>()) map.TBIList.unPlacedMines.Remove(element); foreach (DestructableTriangleBrick element in map.TBIList.unplacedTriangleBrickList.Reverse<DestructableTriangleBrick>()) map.TBIList.unplacedTriangleBrickList.Remove(element); foreach (Bomb element in map.TBIList.PlacedBomb.Reverse<Bomb>()) { map.TBIList.PlacedBomb.Remove(element); } //attempt to pull an entire TBIList out of the JSON serializer StreamReader readFileBetter = new StreamReader("Levels/LevelDemo/" + name + ".json"); string objectString; //read file contents into a string, then close the file reader objectString = readFileBetter.ReadToEnd(); readFileBetter.Close(); //Convert the string to a byte[] and load it into a stream MemoryStream streamsBlow = new MemoryStream(); byte[] byteFucker = Encoding.UTF8.GetBytes(objectString); streamsBlow.Write(byteFucker, 0, byteFucker.Length); //Fingers crossed... streamsBlow.Position = 0; if (streamsBlow.Length != 0) { TBIList tempTBIList = (TBIList)ser.ReadObject(streamsBlow); initObject(tempTBIList, map, gameState); } } }
public void WriteLevel(Map map, string name) { FileStream file = null; FileStream stream1 = null; if (!Directory.Exists("Levels")) Directory.CreateDirectory("Levels"); if (!Directory.Exists("Levels/LevelDemo")) Directory.CreateDirectory("Levels/LevelDemo"); if (!File.Exists("Levels/LevelDemo/Default")) { file = File.Create("Levels/LevelDemo/Default"); file.Close(); } if (!string.IsNullOrEmpty(name)) { if (stream1 == null) { file = File.Open("Levels/LevelDemo/" + name + ".json", FileMode.Create); file.Close(); stream1 = new FileStream("Levels/LevelDemo/" + name + ".json", FileMode.Create); } } else { file = File.Open("Levels/LevelDemo/test.json", FileMode.Create); file.Close(); stream1 = new FileStream("Levels/LevelDemo/test.json", FileMode.Create); } if(stream1 != null) { StringBuilder SB = new StringBuilder(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(TBIList)); ser.WriteObject(stream1, map.TBIList); } stream1.Close(); }
private void initObject(TBIList tempTBIList, Map map, AngryBallsEnvironment.GameState gameState) { map.TBIList = tempTBIList; if (gameState == AngryBallsEnvironment.GameState.dialog) placed = false; else placed = true; foreach (TBoxItem element in map.TBIList.FixedBrickList) { element.initialize(placed); } foreach (Bomb element in map.TBIList.PlacedBomb) { element.initialize(placed); } foreach (ProxMine element in map.TBIList.placedMines) { element.initialize(placed); } foreach (Hazard element in map.TBIList.hazardList) element.initialize(placed); foreach (ProxMine element in map.TBIList.unPlacedMines) { element.initialize(false); } foreach (FixedBrick element in map.TBIList.unplacedTriangleBrickList) element.initialize(false); map.TBIList.endGoal.initialize(placed); }
public override void Create(Map map) { ProxMine newMine = new ProxMine(position); position = toolBoxPosition; map.TBIList.placedMines.Add(newMine); }
//Environment Constructor public AngryBallsEnvironment() { //Instantiate the Buttons gameState = GameState.initialize; playPauseButton = new PlayPauseButton(gameState); resetButton = new ResetButton(gameState); builderButton = new BuilderButton(gameState); saveButton = new SaveButton(gameState); loadButton = new LoadButton(gameState); // Instantiate Dialog Box dialog = new Dialog(loadButton, saveButton); //Instantiate Start Positions for environment items clawopenPosition = clawStartPosition; ballStartPose = new Vector2(clawStartPosition.X + 47, clawStartPosition.Y + 150); //Instantiate local images background = Game1.environmentBackground; border = Game1.borderImage; bigCogImage = Game1.bigCog; bigCogOrigin = new Vector2(bigCogImage.Width / 2, bigCogImage.Height / 2); springImage = Game1.springImage; chickenImage = Game1.chickenImage; clawOpen = Game1.clawOpen; //Instantiate environment containers Input = new InputManager(); map = new Map(); toolBox = new ToolBox(); }
public override void Create(Map map) { FixedBrick newBrick = new FixedBrick(position, false); position = toolBoxPosition; map.TBIList.FixedBrickList.Add(newBrick); }
public virtual void Create(Map map) { }
public override void Create(Map map) { Hazard newBrick = new Hazard(position, false); position = toolBoxPosition; map.TBIList.hazardList.Add(newBrick); }