Ejemplo n.º 1
0
        public GameLogic(Game game)
            : base(game)
        {
            this.game = (Game1)game;
            Game.Services.AddService(typeof(IGameLogicService), this);
            bool useFile = false;

            this.running      = false;
            this.soundManager = new PuzzleBobbleSoundManager(this.game);
            GameLogicInputController inputController = new GameLogicInputController(this.game);

            game.Components.Add(inputController);
            this.hud = game.Services.GetService(typeof(IHUDService)) as IHUDService;
        }
Ejemplo n.º 2
0
        public override void Draw(GameTime gameTime)
        {
            if (!this.running)
            {
                return;
            }

            if ((PuzzleBobble.game_state.LevelStatus.ElapsedTime.Value > 0.0f) && (PuzzleBobble.game_state.LevelStatus.ElapsedTime.Value % PuzzleBobble.DefaultRoofStepTimeDelta) > PuzzleBobble.DefaultRoofStepTimeDelta - 5.0f)
            {
                if (!tickingPlaying)
                {
                    tickingPlaying = true;
                    PuzzleBobbleSoundManager.playSound(PuzzleBobbleSoundManager.SoundsEvent.ROOF_TICK);
                    //   this.clockTicking.Play(1.0f, 0.0f, 0.0f);
                }
                tremblingOffset = (float)(rnd.NextDouble() / 75.0f);
            }
            else
            {
                tickingPlaying  = false;
                tremblingOffset = 0.0f;
            }

            if (this.prevStep < PuzzleBobble.game_state.GridSteps.Value)
            {
                PuzzleBobbleSoundManager.playSound(PuzzleBobbleSoundManager.SoundsEvent.ROOF_DOWN);
                //this.doorSlam.Play(0.75f, 0.0f, 0.0f);
            }

            this.prevStep = PuzzleBobble.game_state.GridSteps.Value;

            int h = GraphicsDevice.Viewport.Bounds.Height;
            int w = GraphicsDevice.Viewport.Bounds.Width;

            this.DrawBackground(gameTime);

            int row    = PuzzleBobble.game_state.Grid.Value.GetLength(0);
            int column = PuzzleBobble.game_state.Grid.Value.GetLength(1);

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    // Microsoft.FSharp.Core.OptionModule.ToList<PuzzleBobble.Ball>( PuzzleBobble.game_state.Grid[row,column])
                    if (PuzzleBobble.game_state.Grid.Value[i, j] != null)
                    {
                        Vector3 pos   = PuzzleBobble.game_state.Grid.Value[i, j].Value.center.toXNAVector + new Vector3(0.0f, tremblingOffset, 0.0f);
                        float   scale = PuzzleBobble.game_state.Grid.Value[i, j].Value.radius;
                        Color   col   = PuzzleBobble.game_state.Grid.Value[i, j].Value.color;
                        this.DrawModel(this.ballMesh, new Vector3(scale, scale, scale), pos, Vector3.Zero, col);

                        //       Console.WriteLine("ball_docked " + i + " " + j + " pos " + pos);
                    }
                }
            }
            foreach (var climbingBall in PuzzleBobble.game_state.ClimbingBalls.Value)
            {
                Vector3 pos   = climbingBall.center.toXNAVector;
                float   scale = climbingBall.radius;
                Color   col   = climbingBall.color;
                this.DrawModel(this.ballMesh, new Vector3(scale, scale, scale), pos, Vector3.Zero, col);
            }
            foreach (var fallingBall in PuzzleBobble.game_state.FallingBalls.Value)
            {
                Vector3 pos   = fallingBall.center.toXNAVector;
                float   scale = fallingBall.radius;
                Color   col   = fallingBall.color;
                this.DrawModel(this.ballMesh, new Vector3(scale, scale, scale), pos, Vector3.Zero, col);
            }

            PuzzleBobble.Ball readyBall = PuzzleBobble.game_state.ReadyBall.Value;

            Vector3 p = readyBall.center.toXNAVector;
            float   s = readyBall.radius;
            Color   c = readyBall.color;

            this.DrawModel(this.ballMesh, new Vector3(s, s, s), p, Vector3.Zero, c);

            PuzzleBobble.Arrow arr = PuzzleBobble.game_state.Arrow;

            this.DrawArrow(arr.angle.Value);


            float XSIZE = BoxBoundingBox.Max.X - BoxBoundingBox.Min.X;
            float YSIZE = BoxBoundingBox.Max.Y - BoxBoundingBox.Min.Y;
            float ZSIZE = BoxBoundingBox.Max.Z - BoxBoundingBox.Min.Z;

            for (int i = -2; i < 3; i++)
            {
                this.DrawModel(Box, new Vector3(1.0f, 1.0f, 0.2f), new Vector3(-XSIZE / 2.0f - 0.2f, YSIZE + (YSIZE * i), 0.0f), Vector3.Zero, null);
                this.DrawModel(Box, new Vector3(1.0f, 1.0f, 0.2f), new Vector3(XSIZE / 2.0f + PuzzleBobble.BoxDimension.X + 0.2f, YSIZE + (YSIZE * i), 0.0f), Vector3.Zero, null);
            }
            float roofScaleX = PuzzleBobble.BoxDimension.X / (XSIZE + 0.2f);

            this.DrawModel(Box, new Vector3(roofScaleX, 1.0f, 0.2f), new Vector3(XSIZE * roofScaleX / 2.0f, PuzzleBobble.BoxDimension.Y - PuzzleBobble.game_state.GridSteps.Value * PuzzleBobble.BallDiameter, 0.0f) + new Vector3(0.2f, tremblingOffset, 0.0f), Vector3.Zero, null);
            this.DrawModel(Box, new Vector3(roofScaleX, 1.0f, 0.2f), new Vector3(XSIZE * roofScaleX / 2.0f, PuzzleBobble.BoxDimension.Y + YSIZE - PuzzleBobble.game_state.GridSteps.Value * PuzzleBobble.BallDiameter, 0.0f) + new Vector3(0.2f, tremblingOffset, 0.0f), Vector3.Zero, null);
            this.DrawModel(Box, new Vector3(roofScaleX, 1.0f, 0.2f), new Vector3(XSIZE * roofScaleX / 2.0f + 0.2f, 0.0f - YSIZE, 0.0f), Vector3.Zero, null);


            //pretty works
            //for (int i = 0; i < 8; i++)
            //{
            //    this.DrawModel(Box, 1.0f, new Vector3(-size + ce.X, +size - ce.Y + (size * 2 * i), -size), Vector3.Zero, null);
            //    this.DrawModel(Box, 1.0f, new Vector3(PuzzleBobble.BoxDimension.X + size - ce.X, +size - ce.Y + (size * 2 * i), -size), Vector3.Zero, null);
            //}

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

            if (PuzzleBobble.game_state.LevelStatus.Status.Value == PuzzleBobble.GameStatus.Ready)
            {
                this.hud.printMessage("Press Enter or\nRaise your left hand\nto start");
            }
            else if (PuzzleBobble.game_state.LevelStatus.Status.Value == PuzzleBobble.GameStatus.Win)
            {
                this.hud.printMessage("You\nWin!");
            }
            else if (PuzzleBobble.game_state.LevelStatus.Status.Value == PuzzleBobble.GameStatus.Lost)
            {
                this.hud.printMessage("You\nLost!");
            }
            base.Draw(gameTime);
        }