Wolvenspud

game1

Oct 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9. using Microsoft.Xna.Framework.Audio;
  10.  
  11.  
  12.  
  13. namespace GameTemplate
  14. {
  15.     /// <summary>
  16.     /// This is the main type for your game.
  17.     /// </summary>
  18.     public class Game1 : Game
  19.     {
  20.         GraphicsDeviceManager graphics;
  21.         SpriteBatch spriteBatch;
  22.  
  23.         public static SoundEffect soundEffect;
  24.         Camera2d cam = new Camera2d();
  25.  
  26.         private static float counter = 1f;
  27.         private static float jump = 100f;
  28.  
  29.         GameManager GM;
  30.  
  31.         public Game1()
  32.         {
  33.             graphics = new GraphicsDeviceManager(this);
  34.             Content.RootDirectory = "Content";
  35.         }
  36.  
  37.         /// <summary>
  38.         /// Allows the game to perform any initialization it needs to before starting to run.
  39.         /// This is where it can query for any required services and load any non-graphic
  40.         /// related content.  Calling base.Initialize will enumerate through any components
  41.         /// and initialize them as well.
  42.         /// </summary>
  43.         protected override void Initialize()
  44.         {
  45.             // TODO: Add your initialization logic here
  46.             cam.Pos = new Vector2(0, 0);
  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.             GM = new GameManager(spriteBatch, Content);
  61.  
  62.             soundEffect = Content.Load<SoundEffect>("Jump");
  63.  
  64.             GM.SewtCamera(cam);
  65.             // TODO: use this.Content to load your game content here
  66.         }
  67.  
  68.         /// <summary>
  69.         /// UnloadContent will be called once per game and is the place to unload
  70.         /// game-specific content.
  71.         /// </summary>
  72.         protected override void UnloadContent()
  73.         {
  74.             // TODO: Unload any non ContentManager content here
  75.         }
  76.  
  77.         /// <summary>
  78.         /// Allows the game to run logic such as updating the world,
  79.         /// checking for collisions, gathering input, and playing audio.
  80.         /// </summary>
  81.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  82.         protected override void Update(GameTime gameTime)
  83.         {
  84.            
  85.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  86.                 Exit();
  87.  
  88.             float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
  89.            
  90.             GM.Update(deltaTime);
  91.  
  92.             // TODO: Add your update logic here
  93.  
  94.             base.Update(gameTime);
  95.         }
  96.  
  97.         public static float UpdateinputY(float DT)
  98.         {
  99.             KeyboardState state = Keyboard.GetState();
  100.             counter += DT;
  101.             if (counter > 1f)
  102.             {
  103.                 if ((state.IsKeyDown(Keys.W) || state.IsKeyDown(Keys.Up)) && state.IsKeyDown(Keys.Space))
  104.                 {
  105.                     counter = 0f;
  106.                     soundEffect.Play();
  107.                     return -jump;
  108.                 }
  109.                 if ((state.IsKeyDown(Keys.S) || state.IsKeyDown(Keys.Down)) && state.IsKeyDown(Keys.Space))
  110.                 {
  111.                     counter = 0f;
  112.                     soundEffect.Play();
  113.                     return jump;
  114.                 }
  115.                 else
  116.                 {
  117.                     return 0f;
  118.                 }
  119.             }
  120.             else
  121.             {
  122.                 return 0f;
  123.             }
  124.         }
  125.  
  126.         public static float UpdateinputX(float DT)
  127.         {
  128.             KeyboardState state = Keyboard.GetState();
  129.             counter += DT;
  130.             if (counter > 1f)
  131.             {
  132.                 if ((state.IsKeyDown(Keys.D) || state.IsKeyDown(Keys.Right)) && state.IsKeyDown(Keys.Space))
  133.                 {
  134.                     counter = 0f;
  135.                     soundEffect.Play();
  136.                     return jump;
  137.                 }
  138.                 if ((state.IsKeyDown(Keys.A) || state.IsKeyDown(Keys.Left)) && state.IsKeyDown(Keys.Space))
  139.                 {
  140.                     counter = 0f;
  141.                     soundEffect.Play();
  142.                     return -jump;
  143.                 }
  144.                 else
  145.                 {
  146.                     return 0f;
  147.                 }
  148.             }
  149.             else
  150.             {
  151.                 return 0f;
  152.             }
  153.         }
  154.  
  155.         /// <summary>
  156.         /// This is called when the game should draw itself.
  157.         /// </summary>
  158.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  159.         ///
  160.  
  161.  
  162.         protected override void Draw(GameTime gameTime)
  163.         {
  164.             GraphicsDevice.Clear(Color.CornflowerBlue);
  165.            
  166.             spriteBatch.Begin(SpriteSortMode.BackToFront,
  167.                 BlendState.AlphaBlend,
  168.                 null,
  169.                 null,
  170.                 null,
  171.                 null,
  172.                 cam.Get_transformation(graphics));
  173.  
  174.  
  175.  
  176.             GM.Draw(spriteBatch);
  177.  
  178.  
  179.             spriteBatch.End();
  180.  
  181.             base.Draw(gameTime);
  182.         }
  183.     }
  184. }
Add Comment
Please, Sign In to add comment