Example #1
0
        public void StartLevel()
        {
            Console.WriteLine("Menu: StartLevel");

            game.Services.RemoveService(typeof(MenuSoundManager));
            game.Services.RemoveService(typeof(MenuInputController));

            IGameLogicInputService inputController = Game.Services.GetService(typeof(IGameLogicInputService)) as IGameLogicInputService;

            inputController.start();

            this.menuInputController.pause();

            InputManager inputManager = Game.Services.GetService(typeof(InputManager)) as InputManager;

            inputManager.start();

            if (!hudExists)
            {
                hudExists = true;
                Game.Components.Add(new HUDPuzzleBobble(this.game));
            }
            renderer.start();



            Game.Components.Remove(this);
            this.Dispose();
            PuzzleBobble.setup_random_level();
            Casanova.commit_variable_updates();
            gameLogic.start();
        }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            GameState.update_state(dt);
            GameState.update_script();
            Casanova.commit_variable_updates();

            base.Update(gameTime);
        }
Example #3
0
        public override void Update(GameTime gameTime)
        {
            //
            // UPDATE MENU ENTRIES BASED ON GAMESTATE
            //
            menuEntries[RESUME_GAME].enabled = GameState.state.elapsedTime.Value > 0 && !GameState.state.gameOver.Value;
            menuEntries[SAVE_GAME].enabled   = GameState.state.elapsedTime.Value > 0 && !GameState.state.gameOver.Value;
            // check that savegame exists
            menuEntries[LOAD_GAME].enabled = File.Exists("savegame");


            //
            // MENU INPUT
            //

            KeyboardState keyboard = Keyboard.GetState();
            GamePadState  gamepad  = GamePad.GetState(PlayerIndex.One);

            if ((gamepad.ThumbSticks.Left.Y > 0 && !(previousGamepad.ThumbSticks.Left.Y > 0)) || (keyboard.IsKeyDown(Keys.Up) && !previousKeyboard.IsKeyDown(Keys.Up)))
            {
                do
                {
                    selectedEntry = (selectedEntry - 1 + menuEntries.Length) % menuEntries.Length;
                } while (!menuEntries[selectedEntry].enabled);
            }

            if ((gamepad.ThumbSticks.Left.Y < 0 && !(previousGamepad.ThumbSticks.Left.Y < 0)) || (keyboard.IsKeyDown(Keys.Down) && !previousKeyboard.IsKeyDown(Keys.Down)))
            {
                do
                {
                    selectedEntry = (selectedEntry + 1 + menuEntries.Length) % menuEntries.Length;
                } while (!menuEntries[selectedEntry].enabled);
            }

            if ((gamepad.Buttons.A == ButtonState.Pressed && !(previousGamepad.Buttons.A == ButtonState.Pressed)) || (keyboard.IsKeyDown(Keys.Enter) && !previousKeyboard.IsKeyDown(Keys.Enter)))
            {
                //
                // MENU ACTIONS
                //

                switch (selectedEntry)
                {
                case NEW_GAME:
                    GameState.reset();
                    Casanova.commit_variable_updates();
                    this.ResumeGameComponents();
                    break;

                case RESUME_GAME:
                    this.ResumeGameComponents();
                    break;

                case LOAD_GAME:
                    Entities.GameState state;
                    stream          = File.Open("savegame", FileMode.Open);
                    binaryFormatter = new BinaryFormatter();
                    state           = (Entities.GameState)binaryFormatter.Deserialize(stream);
                    stream.Close();
                    GameState.set(state);
                    Casanova.commit_variable_updates();
                    this.ResumeGameComponents();
                    break;

                case SAVE_GAME:
                    stream          = File.Open("savegame", FileMode.Create);
                    binaryFormatter = new BinaryFormatter();
                    binaryFormatter.Serialize(stream, GameState.state);
                    stream.Close();
                    break;

                case HELP:
                    displayHelp = !displayHelp;
                    break;

                case EXIT_GAME:
                    Game.Exit();
                    break;
                }
            }

            previousKeyboard = keyboard;
            previousGamepad  = gamepad;

            base.Update(gameTime);
        }
Example #4
0
        public override void Update(GameTime gameTime)
        {
            //if (InputManager.getState().GamePaused)
            //    this.pause();
            // Console.WriteLine("GameLogic: Update");
            if (this.running)
            {
                var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
                switch (PuzzleBobble.game_state.LevelStatus.Status.Value)
                {
                case PuzzleBobble.GameStatus.Lost:
                {
                    //PuzzleBobble.update_state(dt);
                    //PuzzleBobble.update_script();

                    //Casanova.commit_variable_updates();
                    //FIXME: remove thread sleep with an idle cycle
                    System.Threading.Thread.Sleep(5000);
                    this.pause();
                    this.OnBackToMenu();
                    break;
                }

                case PuzzleBobble.GameStatus.Win:
                {
                    //System.Threading.Thread.Sleep(5000);
                    PuzzleBobble.update_state(dt);
                    PuzzleBobble.update_script();

                    Casanova.commit_variable_updates();
                    System.Threading.Thread.Sleep(5000);
                    this.pause();
                    this.OnBackToMenu();
                    break;
                }

                default:
                {
                    if (this.hud == null)
                    {
                        this.hud = game.Services.GetService(typeof(IHUDService)) as IHUDService;
                    }

                    if (this.hud != null)
                    {
                        this.hud.clearMessage();
                    }
                    //n    Console.WriteLine("GameLogic: update");
                    PuzzleBobble.update_state(dt);
                    PuzzleBobble.update_script();

                    Casanova.commit_variable_updates();

                    break;
                }
                }

                //    if (PuzzleBobble.game_state.LevelStatus.GameStatus.Value != PuzzleBobble.GameStatus.Win &&
                //        PuzzleBobble.game_state.LevelStatus.GameStatus.Value != PuzzleBobble.GameStatus.Lost)
                //    {
                //        var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

                //        //n    Console.WriteLine("GameLogic: update");
                //        PuzzleBobble.update_state(dt);
                //        PuzzleBobble.update_script();

                //        Casanova.commit_variable_updates();

                //    }
                //    else {

                //        System.Threading.Thread.Sleep(5000);
                //        this.OnBackToMenu();
                //    }
            }
            base.Update(gameTime);
#if FOO
            if (rendering_data == null)
            {
                rendering_data = (RenderingData)Game.Services.GetService(typeof(RenderingData));
            }

            if (gameWorld == null)
            {
                gameWorld = (WorldData2D)Game.Services.GetService(typeof(WorldData2D));
            }
            if (Keyboard.GetState().IsKeyDown(Keys.B))
            //if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
            {
                while (Game.Components.Count > 0)
                {
                    ((GameComponent)Game.Components[0]).Dispose();
                }

                Game.Components.Clear();

                Game.Components.Add(new Menu(Game));
            }

            //rotate left arrow
            int delta = 2;
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                if (arrow.angle - delta > Arrow.minAngle)
                {
                    arrow.angle -= delta;
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                if (arrow.angle + delta < Arrow.maxAngle)
                {
                    arrow.angle += delta;
                }
                //Console.WriteLine("arrow.anngle " + arrow.angle);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                this.fireActiveBall();
            }

            //    ball.position = ball.position + ball.velocity * dt;
            //    ball.velocity = ball.velocity + Ball.G * dt;

            var k1 = ball.Derivative();
            var k2 = (0.5f * ball + 0.5f * dt * k1).Derivative();
            var k3 = (0.75f * ball + 0.75f * dt * k1).Derivative();

            Ball ballNew;
            ballNew = ball + (2.0f / 9.0f) * dt * k1 +
                      (1.0f / 3.0f) * dt * k2 +
                      (4.0f / 9.0f) * dt * k3;
            ball.position = ballNew.position;
            ball.velocity = ballNew.velocity;

            if (ball.position.Y > rendering_data.MaxY)
            {
                ball.position.Y = rendering_data.MaxY;

                ball.velocity.Y *= -0.8f;
            }

            this.moveActiveBall(dt);
#endif
        }