public override void Update(CASSWorld world, float dt)
        {
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);

            if (deadCosmo)
            { xFrame = 1; }
            else
            { xFrame = 0; }
            /*
            //animation stuff
            myGameTime++;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);

            animateTimer += myGameTime;

            if (animateTimer > animateInterval)
            {
                xFrame++;

                if (xFrame > numFrames - 1)
                {
                    xFrame = 0;
                }

                myGameTime = 0;
                animateTimer = 0;

            }
            */
            base.Update(world, dt);
        }
        public override void Update(CASSWorld world, float dt)
        {
            if (!destroyedBody)
            {

                RemoveFromWorld();
                destroyedBody = true;
            }
        }
        public override void Update(CASSWorld world, float dt)
        {
            if (hack)
            {
                RevoluteJointDef jointDef = new RevoluteJointDef();
                jointDef.Initialize(Body, theWholeWideWorld.GetGroundBody(), Common.Utils.Convert(Position));
                theWholeWideWorld.CreateJoint(jointDef);

                hack = false;
            }

            base.Update(world, dt);
        }
        public override void Update(CASSWorld world, float dt)
        {
            //animation stuff
            myGameTime++;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);

            animateTimer += myGameTime;

            if (animateTimer > animateInterval)
            {
                xFrame++;

                if (xFrame > 6 )
                {
                    xFrame = 0;
                }

                myGameTime = 0;
                animateTimer = 0;

            }

            base.Update(world, dt);
        }
 /**
  * Updates the object's game logic.
  * objects by default have no game logic significance.
  */
 public virtual void Update(CASSWorld world, float dt)
 {
     foreach (PhysicsObject child in children)
         child.Update(world, dt);
 }
        public override void Update(CASSWorld world, float dt)
        {
            if (mySwitch != null)
            {
                if (mySwitch.switchOn)
                {

                    if (isMoving == true)
                    {
                       // this.Body.ApplyForce(Utils.Convert(myForce), this.Body.GetWorldCenter());
                        Position = Position - new Vector2(0, 0.025f);
                        if (this.Position.Y < bound1)
                        {
                            isMoving = false;
                            mySwitch.switchOn = false;//end of launch path
                        }

                    }
                    else
                    {
                        Position = Position + new Vector2(0, 0.05f);
                       // this.Body.ApplyForce(Utils.Convert(myForce / 1.1f), this.Body.GetWorldCenter());
                        if (this.Position.Y > bound2)
                            // mySwitch.switchOn = true;
                            isMoving = true;
                    }

                }
            }
            else{

                if (isMoving == true)
                    {
                       // this.Body.ApplyForce(Utils.Convert(myForce), this.Body.GetWorldCenter());
                        Position = Position - new Vector2(0, 0.025f);
                        if (this.Position.Y < bound1)
                        {
                            isMoving = false;
                            //mySwitch.switchOn = false;//end of launch path
                        }

                    }
                    else
                    {
                        Position = Position + new Vector2(0, 0.05f);
                        //this.Body.ApplyForce(Utils.Convert(myForce / 1.1f), this.Body.GetWorldCenter());
                        if (this.Position.Y > bound2)
                            // mySwitch.switchOn = true;
                            isMoving = true;
                    }
            }

            base.Update(world, dt);
        }
        public override void Update(CASSWorld world, float dt)
        {
            //animation stuff
            myGameTime++;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);

            animateTimer += myGameTime;

            if (animateTimer > animateInterval)
            {
                xFrame++;

                if (xFrame > numFrames-1)
                {
                    xFrame = 0;
                }

                myGameTime = 0;
                animateTimer = 0;

            }

            if (!hasBody) { RemoveFromWorld(); hasBody = true; }

            base.Update(world, dt);
        }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //ronnie added for animation
            //Console.WriteLine("{0} {1} {2} {3}", myGameTime, xFrame,yFrame,animateTimer);
            if (animate == true)
            {
                myGameTime++;
                sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);
                if (!((xFrame == 3) && (yFrame == 1)))
                {
                    animateTimer += myGameTime;

                    if (animateTimer > animateInterval)
                    {
                        xFrame++;

                        if (xFrame > 4 && yFrame == 0)
                        {
                            xFrame = 0;
                            yFrame = 1;
                        }
                        else if (xFrame > 3 && yFrame == 1)
                        {
                            xFrame = 3;
                            yFrame = 1;
                        }

                        // -= (int)walkInterval;
                        myGameTime = 0;
                        animateTimer = 0;
                    }
                }
            }

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            bool skipdialog = false;

            keyState = Keyboard.GetState();

            // Allows the game to exit
            if (keyState.IsKeyDown(Keys.F4))
            {
                ExitGame();
            }

            if (keyState.IsKeyDown(Keys.Enter) && !prevKeyState.IsKeyDown(Keys.Enter))
            {
                skipdialog = true;
            }

            switch (progstate)
            {
                case ProgramState.Menu:
                    currentMenu.Update();
                    MenuCommand command = currentMenu.ReturnAndResetCommand(forcedCommand);
                    //lastFloorPlayed = Constants.floors.IndexOf(command);

                    switch (command)
                    {
                        case MenuCommand.LinkToMainMenu:
                            LinkToMain();
                            currentWorld = null;
                            audioManager.Stop();
                            break;

                        case MenuCommand.LinkToRooms:
                            LinkToRooms();
                            currentWorld = null;
                            audioManager.Stop();
                            break;

                        case MenuCommand.ExitProgram:
                            ExitGame();
                            break;

                        case MenuCommand.Load:
                            if (LoadWorld())
                            {
                                countdown = COUNTDOWN;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadGenesis:
                            if (LoadRelWorld("introduction1"))
                            {
                                lastFloorPlayed = 0;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadExodus:
                            if (LoadRelWorld("recreation1"))
                            {
                                lastFloorPlayed = 1;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadLeviticus:
                            if (LoadRelWorld("engineering1"))
                            {
                                lastFloorPlayed = 2;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadNumbers:
                            if (LoadRelWorld("core1"))
                            {
                                lastFloorPlayed = 3;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadDeuteronomy:
                            if (LoadRelWorld("credits1"))
                            {
                                lastFloorPlayed = 3;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadIntroduction:
                            if (LoadRelWorld("introduction" + (currentMenu.currentScreen.selected + 1) ))
                            {
                                lastFloorPlayed = 0;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;
                        case MenuCommand.LoadRecreation:
                            if (LoadRelWorld("recreation" + (currentMenu.currentScreen.selected + 1) ))
                            {
                                lastFloorPlayed = 1;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;
                        case MenuCommand.LoadEngineering:
                            if (LoadRelWorld("engineering" + (currentMenu.currentScreen.selected + 1) ))
                            {
                                lastFloorPlayed = 2;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;
                        case MenuCommand.LoadCore:
                            if (LoadRelWorld("core" + (currentMenu.currentScreen.selected + 1) ))
                            {
                                lastFloorPlayed = 3;
                                countdown = COUNTDOWN;
                                forcedCommand = MenuCommand.NONE;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LaunchEditor:
                            {
                                progstate = ProgramState.EditorOpen;
                                editor = new CrisisAtSwissStation.LevelEditor.Editor();
                                editor.Show();
                            }
                            break;

                        case MenuCommand.Resume:
                            progstate = ProgramState.Playing;
                            break;

                        case MenuCommand.New:
                           // menuAnimate = true;
                            if (NewWorld())
                            {
                                countdown = COUNTDOWN;
                                progstate = ProgramState.Playing;
                            }
                            break;

                        case MenuCommand.LoadCompleted:
                           // menuAnimate = true;
                            LoadCompleted();
                            break;

                        case MenuCommand.Continue:
                            countdown = COUNTDOWN;
                            forcedCommand = Constants.floors[savedgame.GetCurrentFloor(floorsScreen.Options.Count)];
                            break;
                    }

                    break;

                case ProgramState.Playing:
                    //menuAnimate = false;
                    //Updates the room.
                    KeyboardState ks = Keyboard.GetState();
                    if (ks.IsKeyDown(Keys.Escape))
                    {
                        EnterMenu();
                    }
                    else if (ks.IsKeyDown(Keys.R))
                    {
                        LoadWorld(cwname);
                    }
                    else if (ks.IsKeyDown(Keys.N) && ks.IsKeyDown(Keys.U))
                    {
                        //LoadNextWorld();
                        currentWorld.Succeeded = true;
                    }
                    else if (ks.IsKeyDown(Keys.RightControl) && ks.IsKeyDown(Keys.P) && ks.IsKeyDown(Keys.O))
                    {
                        LoadCompleted();
                    }

                    //world.Update();
                    currentWorld.Simulate((float)gameTime.ElapsedGameTime.TotalSeconds);
                    //SetDebugInfo("Level = " + world.player.Level);
                    break;

                case ProgramState.EditorOpen:

                    if (editor.IsDisposed)
                        progstate = ProgramState.Menu;
                    break;
            }

            //toggle mute if they press 'm'
            if (keyState.IsKeyDown(Keys.M) && prevKeyState.IsKeyUp(Keys.M))
                audioManager.Mute();

            if (currentWorld != null && (currentWorld.Succeeded || currentWorld.Failed))
            {
                countdown--;
                audioManager.DecreaseMusicVolume(.005f);
                //if (currentWorld.Failed)
                //{
                //    countdown--;
                //}

                //Play the level complete SFX
                if (countdown == 180 && currentWorld.Succeeded)
                {
                    audioManager.Stop();
                    audioManager.Play(CrisisAtSwissStation.AudioManager.SFXSelection.LevelComplete);

                }

                if (countdown <= 0 && currentWorld.Succeeded && !currentWorld.Failed)
                {
                    //reset = currentWorld.Failed;
                    if (!audioManager.isMuted())
                    {
                        audioManager.IncreaseMusicVolume(0.5f);
                    }
                    LoadNextWorld();
                }
                else if (countdown <= 0) // failed
                {
                        LoadWorld(cwname);
                        progstate = ProgramState.Playing;
                        countdown = COUNTDOWN;
                        if (!audioManager.isMuted())
                        {
                            audioManager.IncreaseMusicVolume(0.5f);
                        }
                }
            }

            // Just won or lost - initiate countdown
            if (currentWorld!=null && (currentWorld.Failed || currentWorld.Succeeded) && countdown <= 0)
                countdown = COUNTDOWN;

            base.Update(gameTime);
            prevKeyState = keyState;
        }
        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;
        }
        private void LoadNextWorld()
        {
            int levelnum;
            string[] pieces = cwname.Split('.');
            pieces = pieces[pieces.Length - 2].Split('\\');
            bool parsed = int.TryParse(pieces.Last().Substring(pieces.Last().Length - 1), out levelnum);
            //string origname;
            string lastpartofname;
            if (parsed)
            {
                //origname = pieces.Last().Substring(0, pieces.Last().Length - 1);
                lastpartofname = pieces.Last().Substring(0, pieces.Last().Length - 1);
            }
            else
            {
                //origname = pieces[0];
                lastpartofname = pieces.Last();
            }
            //string[] tempary = origname.Split('\\');
            //string lastpartofname = tempary[tempary.Length-2];

            //string newfilename = origname + (levelnum + 1) + ".world";
            string newfilename = GameEngine.GetCurrDir() + "\\Levels\\" + lastpartofname + (levelnum + 1) + ".world";
            //throw new System.ArgumentException(lastpartofname, parsed.ToString());

            // either way, say we beat this room and save the game
            // WARNING - this assumes there are FIVE rooms per floor, and that they're named like floorname1.world, floorname2.world...etc. - starting with 1
            try
            {
                savedgame.roomsBeatenBitmap[lastFloorPlayed, levelnum - 1] = true; savedgame.SaveGame();
            }
            catch (IndexOutOfRangeException e)
            {
            }

            EnableNextFloor(); // only actually does it if you've beaten all of the rooms on the floor right before the next one
            if (File.Exists(newfilename))
            {
                LoadWorld(newfilename);
                progstate = ProgramState.Playing;
            }
            else
            {
                //EnableNextFloor(); // only actually does it if you've beaten all of the rooms on the floor right before the next one
                LinkToFloors();
                progstate = ProgramState.Menu;
                currentWorld = null;
            }

            countdown = COUNTDOWN;
        }
        /**
         * Updates dude game logic - jumping cooldown
         */
        public override void Update(CASSWorld world, float dt)
        {
            // Apply cooldowns
            jumpCooldown = Math.Max(0, jumpCooldown - 1);

            MouseState mouse = Mouse.GetState();
            Vector2 start = myWorld.getScreenCoords(Position);
            Vector2 end = new Vector2(mouse.X,mouse.Y);
            //Console.WriteLine("{0} {1} {2} {3}", end.Y, start.Y, end.X, start.X);
            armAngle = (float)Math.Atan((end.Y - start.Y) / (end.X - start.X));
            //Console.WriteLine("{0}",armAngle);
            //animation stuff
            myGameTime++;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);
            //origin = new Vector2(sourceRect.Width / 2, sourceRect.Height / 2);

            base.Update(world, dt);
        }
        public override void Update(CASSWorld world, float dt)
        {
            //animation stuff
            myGameTime++;
            sourceRect = new Rectangle(xFrame * spriteWidth, yFrame * spriteHeight, spriteWidth, spriteHeight);

            animateTimer += myGameTime;

            if (animateTimer > animateInterval)
            {
                xFrame++;

                if (xFrame > 3 )
                {
                    xFrame = 0;
                }

                // -= (int)walkInterval;
                myGameTime = 0;
                animateTimer = 0;

            }

            // gotta delete the hole Body so we fall through the hole
            if (!destroyedBody)
            {
                Position = Position + new Vector2(0f, -0.258f);//0.35, 0.28
                tempBody = Body;
                //world.World.DestroyBody(Body);
                RemoveFromWorld();
                destroyedBody = true;
            }
            else if (Filled >= MAX_FILL && !replacedBody)
            {
                AddToWorld();
                Position = Position + new Vector2(0f, 0.258f);// +new Vector2(0.2f, -0.0145f);//0.35, 0.28
                replacedBody = true;
                if (Filled != MAX_FILL)
                {
                    float temp1 = Filled - MAX_FILL;
                    Filled = MAX_FILL;
                    ScrollingWorld.numDrawLeft += temp1;

                }
            }

            //base.Update(world, dt);
        }
        public override void Update(CASSWorld world, float dt)
        {
            //hoizontal objects not bound by switches atm

            if (mySwitch != null)
            {
                if (mySwitch.switchOn)
                {

                    if (isMoving == true)
                    {
                        Position = Position + new Vector2(.035f, 0);
                        //movPlatform1.Position = movPlatform1.Position - new Vector2(0, 0.05f);
                        if (this.Position.X > bound2)
                        {
                            isMoving = false;
                             mySwitch.switchOn = false;//right end of path, switch turns off automatically
                        }

                    }
                    else
                    {
                        //movPlatform1.Position = movPlatform1.Position + new Vector2(0, 0.05f);
                        Position = Position - new Vector2(.035f, 0);
                        if (this.Position.X < bound1)
                            // mySwitch.switchOn = true;
                            isMoving = true;
                    }

                }
            }
            else
            {
                if (isMoving == true)
                {
                    Position = Position + new Vector2(.035f, 0);
                    //movPlatform1.Position = movPlatform1.Position - new Vector2(0, 0.05f);
                    if (this.Position.X > bound2)
                    {
                        isMoving = false;
                        // mySwitch.switchOn = false;
                    }

                }
                else
                {
                    //movPlatform1.Position = movPlatform1.Position + new Vector2(0, 0.05f);
                    Position = Position - new Vector2(.035f, 0);
                    if (this.Position.X < bound1)
                        // mySwitch.switchOn = true;
                        isMoving = true;
                }
            }

            base.Update(world, dt);
        }
        public override void Update(CASSWorld world, float dt)
        {
            if ((Angle > MathHelper.ToRadians(85)) && (Angle < MathHelper.ToRadians(95)))
            {
                if(!adjusted)
                {
                endXPos = Position.X + .6f;
                endYPos = Position.Y - 2.5f;
                headMinVal = Position.Y;
                headMaxVal = Position.Y + .6f;
                adjusted = true;
                }

                if (pistonMove == true)
                {
                    Position = Position - new Vector2(0, trueInc);
                    if (Position.Y < headMinVal)
                        pistonMove = false;
                }
                else
                {
                    Position = Position + new Vector2(0, falseInc);
                    if (Position.Y > headMaxVal)
                        pistonMove = true;
                }

            }
            else if ((Angle > MathHelper.ToRadians(-95)) && (Angle < MathHelper.ToRadians(-85)))
            {
                if (!adjusted)
                {
                    endXPos = Position.X - .6f;
                    endYPos = Position.Y + 2.5f;
                    headMinVal = Position.Y;
                    headMaxVal = Position.Y - .6f;
                    adjusted = true;
                }

                if (pistonMove == true)
                {
                    Position = Position + new Vector2(0, trueInc);
                    if (Position.Y > headMinVal)
                        pistonMove = false;
                }
                else
                {
                    Position = Position - new Vector2(0, falseInc);
                    if (Position.Y < headMaxVal)
                        pistonMove = true;
                }

            }
            else if ((Angle > MathHelper.ToRadians(-5)) && (Angle < MathHelper.ToRadians(5)))
            {
                if (pistonMove == true)
                {
                    Position = Position - new Vector2(trueInc, 0);
                    if (Position.X < headMinVal)
                        pistonMove = false;
                }
                else
                {
                    Position = Position + new Vector2(falseInc, 0);
                    if (Position.X > headMaxVal)
                        pistonMove = true;
                }
            }
            else if ((Angle > MathHelper.ToRadians(175)) && (Angle < MathHelper.ToRadians(185)))
            {
                if (!adjusted)
                {
                    endXPos = Position.X + 2.3f;
                    endYPos = Position.Y + .6f;
                    headMinVal = Position.X;
                    headMaxVal = Position.X - .6f;
                    adjusted = true;
                }

                if (pistonMove == true)
                {
                    Position = Position + new Vector2(trueInc, 0);
                    if (Position.X > headMinVal)
                        pistonMove = false;
                }
                else
                {
                    Position = Position - new Vector2(falseInc, 0);
                    if (Position.X < headMaxVal)
                        pistonMove = true;
                }
            }

            base.Update(world, dt);
        }