Advertisement
Guest User

Game1.cs

a guest
Sep 18th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.04 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. using GroundWalkTest;
  16.  
  17. using Cheddar;
  18.  
  19.  
  20. namespace CharacterControllerTest
  21. {
  22.     /// <summary>
  23.     /// This is the main type for your game
  24.     /// </summary>
  25.     public class Game1 : Microsoft.Xna.Framework.Game
  26.     {
  27.         GraphicsDeviceManager graphics;
  28.         SpriteBatch spriteBatch;
  29.  
  30.         Cheddar.Camera camera;
  31.         TexturedBox ground;
  32.         Space space;
  33.  
  34.         SimpleCharacterController character;
  35.        
  36.  
  37.         public Game1()
  38.         {
  39.             graphics = new GraphicsDeviceManager(this);
  40.             Content.RootDirectory = "Content";
  41.         }
  42.  
  43.         /// <summary>
  44.         /// Allows the game to perform any initialization it needs to before starting to run.
  45.         /// This is where it can query for any required services and load any non-graphic
  46.         /// related content.  Calling base.Initialize will enumerate through any components
  47.         /// and initialize them as well.
  48.         /// </summary>
  49.         protected override void Initialize()
  50.         {
  51.             // TODO: Add your initialization logic here
  52.  
  53.             base.Initialize();
  54.         }
  55.  
  56.         /// <summary>
  57.         /// LoadContent will be called once per game and is the place to load
  58.         /// all of your content.
  59.         /// </summary>
  60.         protected override void LoadContent()
  61.         {
  62.             // Create a new SpriteBatch, which can be used to draw textures.
  63.             spriteBatch = new SpriteBatch(GraphicsDevice);
  64.  
  65.             camera = new Cheddar.Camera(this, new Vector3(0f, 20f, 20f), Vector3.Down, Vector3.Up);
  66.             Components.Add(camera);
  67.  
  68.             character = new SimpleCharacterController(new Vector3(0f, 20f, 0f), 5f, 3f, 5f, 5f);
  69.            
  70.  
  71.  
  72.             Texture2D grass = Content.Load<Texture2D>("grass-texture-2");
  73.             ground = new TexturedBox(Vector3.Zero, 50f, 1f, 50f, grass, this.GraphicsDevice);
  74.  
  75.  
  76.             character.Activate();
  77.             space = new Space();
  78.             space.Add(ground);
  79.             space.Add(character);
  80.  
  81.            
  82.            
  83.  
  84.             space.ForceUpdater.Gravity = new Vector3(0, -9.8f, 0);
  85.  
  86.             character.Body.IsAffectedByGravity = true;
  87.            
  88.         }
  89.  
  90.         /// <summary>
  91.         /// UnloadContent will be called once per game and is the place to unload
  92.         /// all content.
  93.         /// </summary>
  94.         protected override void UnloadContent()
  95.         {
  96.             // TODO: Unload any non ContentManager content here
  97.         }
  98.  
  99.         /// <summary>
  100.         /// Allows the game to run logic such as updating the world,
  101.         /// checking for collisions, gathering input, and playing audio.
  102.         /// </summary>
  103.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  104.         protected override void Update(GameTime gameTime)
  105.         {
  106.             // Allows the game to exit
  107.             if (Keyboard.GetState().IsKeyDown(Keys.Escape))
  108.                 this.Exit();
  109.  
  110.             camera.Position = character.Body.BufferedStates.Entity.Position;
  111.             character.MovementDirection = Vector2.One;
  112.             space.Update();
  113.            
  114.            
  115.  
  116.             base.Update(gameTime);
  117.         }
  118.  
  119.         /// <summary>
  120.         /// This is called when the game should draw itself.
  121.         /// </summary>
  122.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  123.         protected override void Draw(GameTime gameTime)
  124.         {
  125.             GraphicsDevice.Clear(Color.CornflowerBlue);
  126.  
  127.             ground.Draw(camera.View, camera.Projection);
  128.  
  129.             base.Draw(gameTime);
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement