Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteFont  = Content.Load <SpriteFont>("Arial");

            ballModel        = Content.Load <Model>("Models\\balltest");
            groundModel      = Content.Load <Model>("Models\\ground");
            boxModel         = Content.Load <Model>("Models\\cube");
            arrowModel       = Content.Load <Model>("Models\\arrow");
            exitModel        = Content.Load <Model>("Models\\exit");
            ballTextureBeach = Content.Load <Texture2D>("Textures\\ball");
            ballTextureMetal = Content.Load <Texture2D>("Models\\tile");
            terrainModel     = Content.Load <Model>("Models\\terrain");
            rockTexture      = Content.Load <Texture2D>("Models\\rocks");
            heightMap        = terrainModel.Tag as HeightMap;
            if (heightMap == null)
            {
                string message = "The terrain model did not have a HeightMapInfo";
                throw new InvalidOperationException(message);
            }
            Sound.playSoundLoop("Sound\\background", Content);
            effect = Content.Load <Effect>("Lighting/Effects");
            sky    = Content.load <Sky>("Textures\\sky");
        }
Пример #2
0
 override public void Initialize()
 {
     content          = ScreenManager.getManager();
     device           = ScreenManager.getDevice();
     XboxcurrentState = GamePad.GetState(PlayerIndex.One);
     XboxoldState     = GamePad.GetState(PlayerIndex.One);
     currentState     = Keyboard.GetState();
     oldState         = Keyboard.GetState();
     Sound.playSoundLoop("Sound\\menu", content);
 }
Пример #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        override public void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(device);
            spriteFont  = content.Load <SpriteFont>("Arial");

            camera = new ChaseCamera(heightMap);
            // Set the camera offsets
            camera.DesiredPositionOffset = new Vector3(0.0f, 100.0f, 200.0f);
            camera.LookAtOffset          = new Vector3(0f, 15.0f, 30.0f);

            ball       = new Ball(this, device, "Models\\balltest");
            ball.scale = Vector3.One * 15f;

            camera.NearPlaneDistance = 10.0f;
            camera.FarPlaneDistance  = 100000.0f;
            camera.AspectRatio       = (float)device.Viewport.Width /
                                       device.Viewport.Height;
            camera.ChasePosition  = ball.position;
            camera.ChaseDirection = ball.Direction;
            camera.Up             = ball.Up;
            camera.Reset();

            ballModel  = content.Load <Model>("Models\\balltest");
            pitModel   = content.Load <Model>("Models\\ground");
            boxModel   = content.Load <Model>("Models\\cube");
            arrowModel = content.Load <Model>("Models\\arrow");
            exitModel  = content.Load <Model>("Models\\exit2");
            //exitModelText = content.Load<Model>("Models\\exitSign");
            ballTextureBeach  = content.Load <Texture2D>("Textures\\beach");
            ballTextureMetal  = content.Load <Texture2D>("Textures\\metal");
            ballTextureAir    = content.Load <Texture2D>("Textures\\air");
            coinTexture       = content.Load <Texture2D>("Textures\\coin");
            teleporterTexture = content.Load <Texture2D>("Textures\\teleporter");
            terrainModel      = content.Load <Model>(terrain);
            rockTexture       = content.Load <Texture2D>(terrainTexture);
            pitTextureLava    = content.Load <Texture2D>("Textures\\lava");
            pitTextureIce     = content.Load <Texture2D>("Textures\\3");
            scoreboardTexture = content.Load <Texture2D>("Textures\\highscores");
            heightMap         = terrainModel.Tag as HeightMapInfo;
            if (heightMap == null)
            {
                string message = "The terrain model did not have a HeightMapInfo";
                throw new InvalidOperationException(message);
            }
            Sound.playSoundLoop(background, content);
            effect = content.Load <Effect>("Lighting/Effects");
            sky    = content.Load <Sky>("Textures\\sky");

            /*Initialize properties for each ball*/
            beachBallProperties   = new BallProperties(ballTextureBeach, 1.0f, 0.5f, 900f, 1f, new Vector3(0.97f, 1f, 0.97f), new Vector3(1f, 1f, 1f), "Sound\\jump", "Sound\\jump", "Sound\\changeBall");
            metalBallProperties   = new BallProperties(ballTextureMetal, 3.0f, 0.15f, 750f, 3f, new Vector3(0.95f, 1f, 0.95f), new Vector3(1f, 1f, 1f), "Sound\\jump", "Sound\\jump", "Sound\\changeBall");
            airBallProperties     = new BallProperties(ballTextureAir, 1f, 0.05f, 1200f, 0.8f, new Vector3(0.99f, 0.99f, 0.99f), new Vector3(0.99f, 0.99f, 0.99f), "Sound\\jump", "Sound\\jump", "Sound\\changeBall");
            currentBallProperties = beachBallProperties;

            List <Texture2D> textures = new List <Texture2D>();

            textures.Add(Content.Load <Texture2D>("Textures\\circle"));
            textures.Add(Content.Load <Texture2D>("Textures\\star"));
            textures.Add(Content.Load <Texture2D>("Textures\\diamond"));
            particleEngine = new ParticleEngine(textures, new Vector2(100, 40));

            //ExitPosition = new Vector3(1405.1f, .90952f, -2367.78f);
            ExitPosition   = new Vector3(2000, 0f, 2000);
            ExitPosition.Y = getHeight(ExitPosition) + 50f;
            ExitBox        = new BoundingBox(ExitPosition - new Vector3(50, 50, 50), ExitPosition + new Vector3(50, 50, 50));
            for (int x = 0; x < 50; x++)
            {
                Vector3 Pos = new Vector3(RandomNumber(-2000, 2000), 0, RandomNumber(-2000, 2000));
                //Vector3 Pos = new Vector3(0, 0, 0);
                Vector3 Normal;
                float   Height;
                heightMap.GetHeightAndNormal(Pos, out Height, out Normal);
                Pos.Y = Height + 20;
                //System.Diagnostics.Debug.WriteLine(Pos);
                coinList.Add(new Coin(Pos, content));
            }
            for (int x = 0; x < 20; x++)
            {
                Vector3 Pos    = new Vector3(RandomNumber(-2500, 3000), 0, RandomNumber(-2500, 3000));
                Vector3 Normal = new Vector3();
                float   Height = 10;
                heightMap.GetHeightAndNormal(Pos, out Height, out Normal);
                Pos.Y = Height + 50;
                //System.Diagnostics.Debug.WriteLine(Pos);
                teleporterList.Add(new teleporter(Pos, content));
            }
        }
Пример #4
0
        /// <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)
        {
            timeInMillis += gameTime.ElapsedGameTime.Milliseconds;

            lastKeyboardState = currentKeyboardState;
            lastGamePadState  = currentGamePadState;
            lastMousState     = currentMouseState;

            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            currentMouseState    = Mouse.GetState();

            // Exit when the Escape key or Back button is pressed
            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
                currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                if (ball.onGround && !ball.jumpDelayTimer.IsRunning)
                {
                    ball.ApplyForce(new Vector3(0, 300, 0));
                    Sound.playSoundOnce("Sound\\jump", Content);
                }
            }

            if (currentKeyboardState.IsKeyDown(Keys.I))
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y += 2, 20, 150);
                camera.DesiredPositionOffset = offset;
                Sound.playSoundOnce("Sound\\rotateCam", Content);
            }
            else if (currentKeyboardState.IsKeyDown(Keys.K))
            {
                Vector3 offset = camera.DesiredPositionOffset;
                offset.Y = MathHelper.Clamp(offset.Y -= 2, 20, 150);
                camera.DesiredPositionOffset = offset;
                Sound.playSoundOnce("Sound\\rotateCam", Content);
            }

            if (currentKeyboardState.IsKeyDown(Keys.Q) && !lastKeyboardState.IsKeyDown(Keys.Q))
            {
                if (ballTexture.Equals(ballTextureBeach))
                {
                    ballTexture = ballTextureMetal;
                }
                else if (ballTexture.Equals(ballTextureMetal))
                {
                    ballTexture = ballTextureBeach;
                }
                Sound.playSoundOnce("Sound\\changeBall", Content);
            }
            else if (currentKeyboardState.IsKeyDown(Keys.E) && !lastKeyboardState.IsKeyDown(Keys.E))
            {
                if (ballTexture.Equals(ballTextureBeach))
                {
                    ballTexture = ballTextureMetal;
                }
                else if (ballTexture.Equals(ballTextureMetal))
                {
                    ballTexture = ballTextureBeach;
                }
                Sound.playSoundOnce("Sound\\changeBall", Content);
            }
            if (currentKeyboardState.IsKeyDown(Keys.N))
            {
                Sound.pauseSound("Sound\\background", Content);
                Sound.playSoundLoop("Sound\\background2", Content);
            }
            if (currentKeyboardState.IsKeyDown(Keys.M))
            {
                Sound.pauseSound("Sound\\background2", Content);
                Sound.playSoundLoop("Sound\\background", Content);
            }

            bool touchTopLeft = currentMouseState.LeftButton == ButtonState.Pressed &&
                                lastMousState.LeftButton != ButtonState.Pressed &&
                                currentMouseState.X < GraphicsDevice.Viewport.Width / 10 &&
                                currentMouseState.Y < GraphicsDevice.Viewport.Height / 10;

            if (currentKeyboardState.IsKeyDown(Keys.R) ||
                currentGamePadState.Buttons.RightStick == ButtonState.Pressed)
            {
                ball.Reset();
                camera.Reset();
            }

            //if (currentKeyboardState.IsKeyDown(Keys.Z))
            //{
            //    IPEndPoint ip = new IPEndPoint(IPAddress.Parse("128.143.69.241"), 9050);
            //    Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //    try
            //    {
            //        server.Connect(ip);
            //    }
            //    catch (SocketException e)
            //    {
            //        Console.WriteLine("Unable to connect to server.");
            //        return;
            //    }
            //    server.Send(Encoding.ASCII.GetBytes("HIGHSCORE-INSERT-1-5000"));
            //    byte[] data = new byte[1024];
            //    int receivedDataLength = server.Receive(data);
            //    string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
            //    Console.WriteLine("DATA FROM SERVER: " + stringData);
            //}

            ball.Update(gameTime);
            camera.ChasePosition  = ball.Position;
            camera.ChaseDirection = ball.Direction;
            camera.Up             = ball.Up;
            camera.Reset();
            base.Update(gameTime);
        }