public static void SaveGame(Player player, string path) { Stream stream = File.Open(path, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, player); stream.Close(); }
public void dettachPlayer() { if (attachedPlayer!=null) { attachedPlayer = null; //sets to null if player is not null } platformJoint.Dispose(); platformJoint = null; //gets rid of the joint }
public static Player StartGame(string name) { List<Item> inventory = new List<Item>(); inventory.Add(ItemGenerator.CreateItem(7)); Weapon weapon = (Weapon)ItemGenerator.CreateItem(-1); Armour armour = (Armour)ItemGenerator.CreateItem(-2); Player player = new Player(name, 10, 1, 100, 0, 80, 3, 7, 1001, inventory, weapon, armour); GameInProgress = true; return player; }
//the player that will be attatched public void attachPlayer(Player p) { if (platformJoint == null) { attachedPlayer = p; //creates a revolute joint between the platform and player body at the platforms position platformJoint = JointFactory.Instance.CreateRevoluteJoint(body, p.Body, body.Position); sim.Add(platformJoint); platformJoint.Broke += new EventHandler<EventArgs>(platformJoint_Broke);//fires platformJOint_broke event handler } }
public void LoadLevel(string LevelName) { background = content.Load<Texture2D>("LevelBackground"); //override the background image each level. if (levelIndex == 2) { background = content.Load<Texture2D>("Background\\stu1"); } if (levelIndex == 3) { background = content.Load<Texture2D>("Background\\stu2"); } if (levelIndex == 4) { background = content.Load<Texture2D>("Background\\stu3"); } if (levelIndex == 5) { background = content.Load<Texture2D>("Background\\stu4"); } if (levelIndex == 6) { background = content.Load<Texture2D>("Background\\stu5"); } if (levelIndex == 7) { background = content.Load<Texture2D>("Background\\level 7"); } if (levelIndex == 8) { background = content.Load<Texture2D>("Background\\level 8"); } if (levelIndex == 9) { background = content.Load<Texture2D>("Background\\Level9"); } if (levelIndex == 10) { background = content.Load<Texture2D>("Background\\level 10"); } if (levelIndex == 11) { background = content.Load<Texture2D>("Background\\Rob1"); } if (levelIndex == 12) { background = content.Load<Texture2D>("Background\\Rob2"); } if (levelIndex == 13) { background = content.Load<Texture2D>("Background\\Rob3"); } if (levelIndex == 14) { background = content.Load<Texture2D>("Background\\Rob4"); } if (levelIndex == 15) { background = content.Load<Texture2D>("Background\\Rob5"); } gameParam.LoadParama("gameParam.txt");//loads parameters from the gameParam.txt files //Cue cue = soundBank.GetCue("Level music loop"); //cue.Play(); //level parameters quarkSpeed = gameParam.QuarkSpeed; platformSpeed = gameParam.PlatformSpeed; selectedQuark = 1; if (beingReset) { //this should ONLY be loaded during a reset. retain energy otherwise quarkEnergy = gameParam.loadQuarkEnergy(levelIndex); beingReset = false; } using (StreamReader sr = new StreamReader(LevelName)) { int x = 0; int y = 0; while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] elements = line.Split(','); foreach (string e in elements) { //type is the number that will be retreived from the text file int type = int.Parse(e); if (type == 1) { tile = new Sprite(); tile.Position = new Vector2(x, y); int number = random.Next(1, 10);// choose a random number between 1 and 10 //selects a tile depending on the number above if (number == 1) { tile.Load("plat", content, simulator); } if (number == 2) { tile.Load("plat2", content, simulator); } if (number == 3) { tile.Load("plat3", content, simulator); } if (number == 4) { tile.Load("plat4", content, simulator); } if (number == 5) { tile.Load("plat5", content, simulator); } if (number == 6) { tile.Load("plat6", content, simulator); } if (number == 7) { tile.Load("plat7", content, simulator); } if (number == 8) { tile.Load("plat8", content, simulator); } if (number == 9) { tile.Load("plat9", content, simulator); } if (number == 10) { tile.Load("plat10", content, simulator); } tile.IsStatic = true; //so gravity doesnt pull the tile down tiles.Add(tile);//adds it to the array tile.Geom.FrictionCoefficient = 0.5f;//friction to improve unit movement } if (type == 2) { playerSprite = new Player(); playerSprite.Position = new Vector2(x, y); playerSprite.Load("still", content, simulator);//default image for the player playerSprite.Body.Mass = 10; tiles.Add(playerSprite);//added to the tile array playerSprite.Speed = gameParam.ParamSpeed; //some param's from the text files playerSprite.JumpForce = gameParam.ParamJumpForce; playerSprite.CanJump = true; //player is allowed to jump when this is true previousPlayerState = playerSprite.Body.LinearVelocity;//?? playerSprite.Geom.OnSeparation += OnSeparation;//tocheck for seperation playerSprite.Geom.OnCollision += OnCollision;//fired when in contact } if (type == 3) { //end of level object portal = new End(); portal.portalAnimation = new Animation(content.Load<Texture2D>("Portal"), gameParam.PortalAnimationSpeed, true); portal.Position = new Vector2(x, y); portal.Load("Portal", content, simulator); portal.Geom.CollisionEnabled = false; portal.IsStatic = true; tiles.Add(portal); } if (type == 4) { //alternative tiles tile = new Sprite(); tile.Position = new Vector2(x, y); //tile.Load("Platform\\rockright", content, simulator); tile.Load("box", content, simulator); tile.IsStatic = true; tiles.Add(tile); tile.Geom.FrictionCoefficient = 0.5f; } if (type == 5) { //alternative tiles tile = new Sprite(); tile.Position = new Vector2(x, y); // tile.Load("Platform\\rockleft", content, simulator); tile.Load("box", content, simulator); tile.IsStatic = true; tiles.Add(tile); tile.Geom.FrictionCoefficient = 0.5f; } if (type == 6) { //alternative tiles tile = new Sprite(); tile.Position = new Vector2(x, y); //tile.Load("Platform\\rockbottom", content, simulator); tile.Load("box", content, simulator); tile.IsStatic = true; tiles.Add(tile); tile.Geom.FrictionCoefficient = 0.5f; } if (type == 7) { //this tile will propel the player in the air BouncyTile bouncyTile; bouncyTile = new BouncyTile(); bouncyTile.Position = new Vector2(x, y); bouncyTile.Load("Sprites\\Bouncing platform2", content, simulator); bouncyTile.IsStatic = true; bouncytiles.Add(bouncyTile); } if (type == 8) { Pickup pickup = new Pickup(); pickup.Position = new Vector2(x, y); pickup.Load("Pickup", content, simulator); pickup.IsStatic = true; pickup.Geom.CollisionResponseEnabled = false; //so player doesnt bump into pickups while collecting pickups.Add(pickup); } if (type == 11) { quark1 = new Quark(quarkIndex);//each quarks are assigned an index number for selection quark1.Position = new Vector2(x, y); quark1.Load("platform//gasstile", content, simulator); quark1.IsStatic = true; quarks.Add(quark1);//quarks are added to the quark array quark1.Geom.FrictionCoefficient = 0.5f; quark1.inFocus = true;//quark number 1 has focus (is selected) by default quark1.Coordinates.SetValue(new Vector2(x, y), type - 11);//quark starting coordinate quark1.Speed = quarkSpeed; } if (type == 12) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); // quark second coordinate } if (type == 13) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); // quark third coordinate } if (type == 14) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 15) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 16) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 17) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 18) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 19) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 20) { quark1.Coordinates.SetValue(new Vector2(x, y), type - 11); } if (type == 21) { quark2 = new Quark(quarkIndex+1); quark2.Position = new Vector2(x, y); quark2.Load("quarkplatform", content, simulator); quark2.IsStatic = true; quarks.Add(quark2); quark2.Geom.FrictionCoefficient = 0.5f; quark2.inFocus = false; quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); quark2.Speed = quarkSpeed; } if (type == 22) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 23) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 24) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 25) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 26) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 27) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 28) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 29) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 30) { quark2.Coordinates.SetValue(new Vector2(x, y), type - 21); } if (type == 31) { quark3 = new Quark(quarkIndex + 2); quark3.Position = new Vector2(x, y); quark3.Load("quarkplatform", content, simulator); quark3.IsStatic = true; quarks.Add(quark3); quark3.Geom.FrictionCoefficient = 0.5f; quark3.inFocus = false; quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); quark3.Speed = quarkSpeed; } if (type == 32) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 33) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 34) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 35) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 36) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 37) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 38) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 39) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 40) { quark3.Coordinates.SetValue(new Vector2(x, y), type - 31); } if (type == 41) { quark4 = new Quark(quarkIndex + 3); quark4.Position = new Vector2(x, y); quark4.Load("quarkplatform", content, simulator); quark4.IsStatic = true; quarks.Add(quark4); quark4.Geom.FrictionCoefficient = 0.5f; quark4.inFocus = false; quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); quark4.Speed = quarkSpeed; } if (type == 42) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 43) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 44) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 45) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 46) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 47) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 48) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 49) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 50) { quark4.Coordinates.SetValue(new Vector2(x, y), type - 41); } if (type == 51) { quark5 = new Quark(quarkIndex + 4); quark5.Position = new Vector2(x, y); quark5.Load("quarkplatform", content, simulator); quark5.IsStatic = true; quarks.Add(quark5); quark5.Geom.FrictionCoefficient = 0.5f; quark5.inFocus = false; quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); quark5.Speed = quarkSpeed; } if (type == 52) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 53) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 54) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 55) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 56) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 57) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 58) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 59) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 60) { quark5.Coordinates.SetValue(new Vector2(x, y), type - 51); } if (type == 61) { quark6 = new Quark(quarkIndex + 5); quark6.Position = new Vector2(x, y); quark6.Load("quarkplatform", content, simulator); quark6.IsStatic = true; quarks.Add(quark6); quark6.Geom.FrictionCoefficient = 0.5f; quark6.inFocus = false; quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); quark6.Speed = quarkSpeed; } if (type == 62) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 63) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 64) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 65) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 66) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 67) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 68) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 69) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 70) { quark6.Coordinates.SetValue(new Vector2(x, y), type - 61); } if (type == 71) { quark7 = new Quark(quarkIndex + 6); quark7.Position = new Vector2(x, y); quark7.Load("quarkplatform", content, simulator); quark7.IsStatic = true; quarks.Add(quark7); quark7.Geom.FrictionCoefficient = 0.5f; quark7.inFocus = false; quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); quark7.Speed = quarkSpeed; } if (type == 72) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 73) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 74) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 75) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 76) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 77) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 78) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 79) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 80) { quark7.Coordinates.SetValue(new Vector2(x, y), type - 71); } if (type == 81) { quark8 = new Quark(quarkIndex + 7); quark8.Position = new Vector2(x, y); quark8.Load("quarkplatform", content, simulator); quark8.IsStatic = true; quarks.Add(quark8); quark8.Geom.FrictionCoefficient = 0.5f; quark8.inFocus = false; quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); quark8.Speed = quarkSpeed; } if (type == 82) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 83) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 84) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 85) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 86) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 87) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 88) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 89) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } if (type == 90) { quark8.Coordinates.SetValue(new Vector2(x, y), type - 81); } //where you walk into teleport if (type == 100) { teleport = new Teleport(); teleport.Position = new Vector2(x, y); teleport.Load("portalv2", content, simulator); teleport.IsStatic = true; tiles.Add(teleport); HasTeleport = true; } //where you walk out of teleport if (type == 101) { place = new Teleport(); place.Position = new Vector2(x, y); place.Load("portalv2", content, simulator); place.IsStatic = true; tiles.Add(place); } if (type == 111) { platform1 = new MovingPlatform(); platform1.Position = new Vector2(x, y); platform1.Load("movingPlatform", content, simulator); platform1.IsStatic = true; //quark1.Body.IgnoreGravity = true; movingPlatforms.Add(platform1); platform1.Coordinates.SetValue(new Vector2(x, y), type - 111); platform1.Speed = platformSpeed; } if (type == 112) { platform1.Coordinates.SetValue(new Vector2(x, y), type - 111); } if (type == 113) { platform1.Coordinates.SetValue(new Vector2(x, y), type - 111); } if (type == 114) { platform1.Coordinates.SetValue(new Vector2(x, y), type - 111); } if (type == 121) { platform2 = new MovingPlatform(); platform2.Position = new Vector2(x, y); platform2.Load("movingPlatform", content, simulator); platform2.IsStatic = true; movingPlatforms.Add(platform2); platform2.Coordinates.SetValue(new Vector2(x, y), type - 121); platform2.Speed = platformSpeed; } if (type == 122) { platform2.Coordinates.SetValue(new Vector2(x, y), type - 121); } if (type == 123) { platform2.Coordinates.SetValue(new Vector2(x, y), type - 121); } if (type == 124) { platform2.Coordinates.SetValue(new Vector2(x, y), type - 121); } if (type == 131) { platform3 = new MovingPlatform(); platform3.Position = new Vector2(x, y); platform3.Load("movingPlatform", content, simulator); platform3.IsStatic = true; movingPlatforms.Add(platform3); platform3.Coordinates.SetValue(new Vector2(x, y), type - 131); platform3.Speed = platformSpeed; } if (type == 132) { platform3.Coordinates.SetValue(new Vector2(x, y), type - 131); } if (type == 133) { platform3.Coordinates.SetValue(new Vector2(x, y), type - 131); } if (type == 134) { platform3.Coordinates.SetValue(new Vector2(x, y), type - 131); } //tile hieght x += 20; //defualt 25 } x = 0; //tile width y += 20; } } star = new Star(); star.starAnimation = new Animation(content.Load<Texture2D>("Sprites\\star"), 0.9f, true); star.Position = new Vector2(1,1);//v; star.Load("Sprites\\star", content, simulator); star.IsStatic = true; star.Geom.CollisionEnabled = false; /* } } */ // } }