Beispiel #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();
        }
Beispiel #2
0
 public void OnLoadGame()
 {
     using (var stream = File.Open("game_status.sav", FileMode.Open))
     {
         var binary_formatter = new BinaryFormatter();
         try
         {
             PuzzleBobble.GameState state = binary_formatter.Deserialize(stream) as PuzzleBobble.GameState;
             PuzzleBobble.load_game_state(state);
             //  Casanova.commit_variable_updates();
             //  Console.WriteLine("State Loaded at gametime " + state.LevelStatus.ElapsedTime.Value.ToString());
         }
         catch (ArgumentNullException e) {
             Console.WriteLine(e.Message);
         }
         stream.Close();
     }
 }
Beispiel #3
0
        public override void Initialize()
        {
            //      Console.WriteLine("GameLogic: Initialize");

            this.gameLogicInputController = Game.Services.GetService(typeof(IGameLogicInputService)) as IGameLogicInputService;
            //if (cameraInput != null)
            //{
            if (this.gameLogicInputController == null)
            {
                this.gameLogicInputController = new GameLogicInputController(this.game);
                Game.Components.Add((GameLogicInputController)this.gameLogicInputController);
            }
            gameLogicInputController.changedCamera += this.OnCameraMoved;//(Camera.CameraTransformations t, float dt) => this.OnCameraMoved(t, dt);
            gameLogicInputController.gamePaused    += this.OnGamePaused;

            //}
            Game.Exiting += new EventHandler <EventArgs>(Game_Exiting);
            PuzzleBobble.setup_random_level();
            //  Casanova.commit_variable_updates();
            //_level();
            base.Initialize();
        }
Beispiel #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
        }