public BackgroundObject(World myWorld, ScrollingWorld myScrollingWorld, string myDisplayTextureName, Vector2 myPosition)
     : base(myWorld, myDisplayTextureName, 0f, .5f, 0.0f, 1, false)
 {
     displayTexture = GameEngine.TextureList[myDisplayTextureName];
     displayTextureName = myDisplayTextureName;
     world = myScrollingWorld;
     position = myPosition;
     destroyedBody = false;
     shapes[0].IsSensor = true;
 }
        public bool NewWorld()
        {
            // new game deletes the autosave
            if (File.Exists(GetCurrDir() + Constants.SAVED_GAME_FILENAME))
            {
                File.Delete(GetCurrDir() + "\\" + Constants.SAVED_GAME_FILENAME);
            }
            // either way, start a new saved game
            savedgame = new SavedGame();
            savedgame.disabledOptions.AddRange(new List<int> { 1, 2, 3 });

            //string currdir = (Directory.GetCurrentDirectory()).Replace("bin\\x86\\Debug", "Content").Replace("bin\\x86\\Release", "Content").Replace("\\Worlds", "");
            cwname = GetCurrDir() + "\\Levels\\" + Constants.NEW_GAME_NAME;
            ScrollingWorld world = new ScrollingWorld(cwname, true);

            if (world != null)
            {
                //this.world = world;
                currentWorld = world;
                //world.LoadContent(Content);
                currentWorld.reloadNonSerializedAssets();
                return true;
            }
            return false;
        }
        public bool LoadWorld(string worldpath)
        {
            ScrollingWorld world;

            if (worldpath!=null)
            {
                //world = Serializer.DeSerialize(worldpath);
                world = new ScrollingWorld(worldpath, true);
                cwname = worldpath;
            }
            else
            {
                return false;
            }

            if (world != null)
            {
                //this.world = world;
                currentWorld = world;
                //world.LoadContent(Content);
                currentWorld.reloadNonSerializedAssets();

                //Bug: When reloading a game, player starts at last known rotation, but kicking
                //box is always redrawn from initial rotaion. (So kicking box is offset)
                //Solution: Always create a new player, only transferring state. (No one will notice/care)
                //****//
                //world.player.Rotation = world.player.OriginalRotation;
                return true;
            }

            return false;
        }
        public bool LoadWorld()
        {
            ScrollingWorld world;

            //First, choose the file we want to load. This is slightly magic.
            Forms.OpenFileDialog dialog = new Forms.OpenFileDialog();
            dialog.Filter =
               "World Files | *.world";
            dialog.InitialDirectory = ".";
            dialog.Title = "Select a world file.";

            Forms.DialogResult result = dialog.ShowDialog();

            //If the result was ok, load the resultant file into world and return it. Otherwise,
            //return null.
            if (result == Forms.DialogResult.OK)
            {
                //world = Serializer.DeSerialize(dialog.FileName);
                world = new ScrollingWorld(dialog.FileName, true);
                cwname = dialog.FileName;
            }
            else
            {
                return false;
            }

            if (world != null)
            {
                //this.world = world;
                currentWorld = world;
                //world.LoadContent(Content);
                currentWorld.reloadNonSerializedAssets();

                //Bug: When reloading a game, player starts at last known rotation, but kicking
                //box is always redrawn from initial rotaion. (So kicking box is offset)
                //Solution: Always create a new player, only transferring state. (No one will notice/care)
                //****//
                //world.player.Rotation = world.player.OriginalRotation;
                return true;
            }

            return false;
        }
        //: base(world, texture, 1.0f, 0.0f, 0.0f)
        /**
         * Creates a new dude
         */
        //public DudeObject(World world, Texture2D texture, Texture2D objectTexture, Texture2D armTexture, string groundSensorName)
        public DudeObject(World world, ScrollingWorld theWorld, string texturename, string objectTexturename, string armTexturename, LaserObject Laser, string groundSensorName)
            : base(world, objectTexturename, DUDE_DENSITY, 0.0f, 0.0f, 1, false)
        {
            this.armTextureName = armTexturename;
            this.animTextureName = texturename;

            Texture2D objectTexture = GameEngine.TextureList[objectTexturename];
            Texture2D texture = GameEngine.TextureList[texturename];
            Texture2D armTexture = GameEngine.TextureList[armTexturename];
            deadTexture = GameEngine.TextureList["Art\\failure_cosmo"];

            Height = objectTexture.Height;
            Width = objectTexture.Width;

            boundingBox = new Rectangle((int)(Position.X * CASSWorld.SCALE), (int)(Position.Y * CASSWorld.SCALE), (int)Height, (int)Width);

            amDead = false;

            // Initialize
            isGrounded = false;
            isSloped = false;

            TextureFilename = objectTexturename;
            // BodyDef options
            BodyDef.FixedRotation = true;

            // Make a dude controller
            controllers.Add(new DudeController());

            armAngle = 0;

            myWorld = theWorld;

            //animation stuff
            myGameTime = 0;
            animTexture = texture;
            this.armTexture = armTexture;
            walkTimer = 0;
            walkInterval = 5;
            xFrame = 0;
            yFrame = 0;
            spriteWidth = 100;
            spriteHeight = 100;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);
            animOrigin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2);
            armOrigin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2) - new Vector2(10,18);

            // Ground Sensor
            // -------------
            //   We only allow the dude to jump when he's
            // on the ground.  After all, how can you jump
            // when you're flying in the air?  (Unless you
            // can double jump)
            //   To determine whether or not the dude is on
            // the ground, we create a thin sensor under his
            // feet, which reports collisions with the world
            // but has no collision response.
            //   Game logic in PlatformWorld tells the dude
            // whether or not he is grounded.

            //animation stuff
            /*
            // Compute dimensions of the ground sensor
            float halfWidth = (float)texture.Width / (2 * CASSWorld.SCALE);
            float halfHeight = (float)texture.Height / (2 * CASSWorld.SCALE);
            Vector2 sensorCenter = new Vector2(0, halfHeight);
             */
            float halfWidth = (float)objectTexture.Width / (2 * CASSWorld.SCALE);
            float halfHeight = (float)objectTexture.Height / (2 * CASSWorld.SCALE);
            //Vector2 sensorCenter = new Vector2(0, halfHeight);
            Vector2 sensorCenter = new Vector2(0, halfHeight - (5f / CASSWorld.SCALE));

            // Create collision shape of the ground sensor
            PolygonDef groundSensor = new PolygonDef();
            groundSensor.Density = 0.0f;
            groundSensor.IsSensor = true;
            groundSensor.UserData = groundSensorName;
            //groundSensor.SetAsBox(halfWidth*0.6f, halfHeight*0.5f, Utils.Convert(sensorCenter), 0);
            groundSensor.SetAsBox(2f/CASSWorld.SCALE, halfWidth/2f, Utils.Convert(sensorCenter), 0);
            shapes.Add(groundSensor);

            /* CIRCULAR GROUND SENSOR - just comment above out and uncomment this
            CircleDef groundSensor = new CircleDef();
            groundSensor.Radius = halfWidth * 0.95f;
            //groundSensor.Radius = (15f/2f) / CASSWorld.SCALE;
            groundSensor.LocalPosition = Utils.Convert(sensorCenter);
            groundSensor.UserData = groundSensorName;
            groundSensor.IsSensor = true;
            shapes.Add(groundSensor);
            */

            PolygonDef slopeSensor = new PolygonDef();
            slopeSensor.Density = 0.0f;
            slopeSensor.IsSensor = true;
            slopeSensor.UserData = groundSensorName + "SLOPE";
            slopeSensor.SetAsBox(halfWidth * 1.1f, 0.1f, Utils.Convert(sensorCenter + new Vector2(0, 0)), 0);
            shapes.Add(slopeSensor);

            lockDude = false;

            //animation stuff
            //base.(world, texture, 1.0f, 0.0f, 0.0f);
        }
 public PlatformContactListener(ScrollingWorld world)
 {
     this.world = world;
 }
 public PlatformBoundaryListener(ScrollingWorld world)
 {
     this.world = world;
 }