Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Audio;
- namespace GameTemplate
- {
- /// <summary>
- /// This is the main type for your game.
- /// </summary>
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- public static SoundEffect soundEffect;
- Camera2d cam = new Camera2d();
- private static float counter = 1f;
- private static float jump = 100f;
- GameManager GM;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- cam.Pos = new Vector2(0, 0);
- base.Initialize();
- }
- /// <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);
- GM = new GameManager(spriteBatch, Content);
- soundEffect = Content.Load<SoundEffect>("Jump");
- GM.SewtCamera(cam);
- // TODO: use this.Content to load your game content here
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// game-specific content.
- /// </summary>
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- /// <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)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
- GM.Update(deltaTime);
- // TODO: Add your update logic here
- base.Update(gameTime);
- }
- public static float UpdateinputY(float DT)
- {
- KeyboardState state = Keyboard.GetState();
- counter += DT;
- if (counter > 1f)
- {
- if ((state.IsKeyDown(Keys.W) || state.IsKeyDown(Keys.Up)) && state.IsKeyDown(Keys.Space))
- {
- counter = 0f;
- soundEffect.Play();
- return -jump;
- }
- if ((state.IsKeyDown(Keys.S) || state.IsKeyDown(Keys.Down)) && state.IsKeyDown(Keys.Space))
- {
- counter = 0f;
- soundEffect.Play();
- return jump;
- }
- else
- {
- return 0f;
- }
- }
- else
- {
- return 0f;
- }
- }
- public static float UpdateinputX(float DT)
- {
- KeyboardState state = Keyboard.GetState();
- counter += DT;
- if (counter > 1f)
- {
- if ((state.IsKeyDown(Keys.D) || state.IsKeyDown(Keys.Right)) && state.IsKeyDown(Keys.Space))
- {
- counter = 0f;
- soundEffect.Play();
- return jump;
- }
- if ((state.IsKeyDown(Keys.A) || state.IsKeyDown(Keys.Left)) && state.IsKeyDown(Keys.Space))
- {
- counter = 0f;
- soundEffect.Play();
- return -jump;
- }
- else
- {
- return 0f;
- }
- }
- else
- {
- return 0f;
- }
- }
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- ///
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin(SpriteSortMode.BackToFront,
- BlendState.AlphaBlend,
- null,
- null,
- null,
- null,
- cam.Get_transformation(graphics));
- GM.Draw(spriteBatch);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Add Comment
Please, Sign In to add comment