Advertisement
Guest User

Game1.cs

a guest
Sep 17th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. using BEPUphysics;
  13. using BEPUphysicsDemos;
  14. using BEPUphysicsDemos.AlternateMovement.SimpleCharacter;
  15.  
  16.  
  17. namespace CharacterControllerTest
  18. {
  19.     /// <summary>
  20.     /// This is the main type for your game
  21.     /// </summary>
  22.     public class Game1 : Microsoft.Xna.Framework.Game
  23.     {
  24.         GraphicsDeviceManager graphics;
  25.         SpriteBatch spriteBatch;
  26.  
  27.         Camera camera;
  28.         TexturedBox ground;
  29.         Space space;
  30.        
  31.  
  32.         public Game1()
  33.         {
  34.             graphics = new GraphicsDeviceManager(this);
  35.             Content.RootDirectory = "Content";
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Allows the game to perform any initialization it needs to before starting to run.
  40.         /// This is where it can query for any required services and load any non-graphic
  41.         /// related content.  Calling base.Initialize will enumerate through any components
  42.         /// and initialize them as well.
  43.         /// </summary>
  44.         protected override void Initialize()
  45.         {
  46.             // TODO: Add your initialization logic here
  47.  
  48.             base.Initialize();
  49.         }
  50.  
  51.         /// <summary>
  52.         /// LoadContent will be called once per game and is the place to load
  53.         /// all of your content.
  54.         /// </summary>
  55.         protected override void LoadContent()
  56.         {
  57.             // Create a new SpriteBatch, which can be used to draw textures.
  58.             spriteBatch = new SpriteBatch(GraphicsDevice);
  59.  
  60.             camera = new Camera(new Vector3(0f, 20f, 0f), 2f, 1f, 1f,
  61.                 Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), GraphicsDevice.DisplayMode.AspectRatio,
  62.                 0.1f, 10000f));
  63.            
  64.  
  65.  
  66.             Texture2D grass = Content.Load<Texture2D>("grass-texture-2");
  67.             ground = new TexturedBox(Vector3.Zero, 50f, 1f, 50f, grass, this.GraphicsDevice);
  68.  
  69.            
  70.  
  71.             space = new Space();
  72.             space.Add(ground);
  73.            
  74.  
  75.             space.ForceUpdater.Gravity = new Vector3(0, -9.8f, 0);
  76.            
  77.         }
  78.  
  79.         /// <summary>
  80.         /// UnloadContent will be called once per game and is the place to unload
  81.         /// all content.
  82.         /// </summary>
  83.         protected override void UnloadContent()
  84.         {
  85.             // TODO: Unload any non ContentManager content here
  86.         }
  87.  
  88.         /// <summary>
  89.         /// Allows the game to run logic such as updating the world,
  90.         /// checking for collisions, gathering input, and playing audio.
  91.         /// </summary>
  92.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  93.         protected override void Update(GameTime gameTime)
  94.         {
  95.             // Allows the game to exit
  96.             if (Keyboard.GetState().IsKeyDown(Keys.Escape))
  97.                 this.Exit();
  98.  
  99.             float dt = (float)gameTime.ElapsedGameTime.Seconds;
  100.             KeyboardState KeyboardInput = Keyboard.GetState();
  101.             MouseState MouseInput = Mouse.GetState();
  102.             GamePadState GamePadInput = GamePad.GetState(PlayerIndex.One);
  103.  
  104.             camera.Update(dt, KeyboardInput, MouseInput, GamePadInput);
  105.  
  106.             space.Update();
  107.            
  108.            
  109.  
  110.             base.Update(gameTime);
  111.         }
  112.  
  113.         /// <summary>
  114.         /// This is called when the game should draw itself.
  115.         /// </summary>
  116.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  117.         protected override void Draw(GameTime gameTime)
  118.         {
  119.             GraphicsDevice.Clear(Color.CornflowerBlue);
  120.  
  121.             ground.Draw(camera.ViewMatrix, camera.ProjectionMatrix);
  122.  
  123.             base.Draw(gameTime);
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement