Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace BadGame
- {
- public struct PlayerData
- {
- public Vector2 Position;
- public int Health;
- }
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- GraphicsDevice device;
- SpriteBatch spriteBatch;
- SpriteFont font;
- Texture2D backgroundTexture;
- Texture2D levelTexture;
- Texture2D foregroundTexture;
- Texture2D playerTexture;
- int screenHeight;
- int screenWidth;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- graphics.PreferredBackBufferWidth = 800;
- graphics.PreferredBackBufferHeight = 400;
- graphics.IsFullScreen = false;
- graphics.ApplyChanges();
- Window.Title = "Terrible Game";
- base.Initialize();
- }
- public static PlayerData Save1 = new PlayerData();
- public static void BuildPlayerData()
- {
- Save1.Position = new Vector2(0, 312);
- Save1.Health = 100;
- }
- protected override void LoadContent()
- {
- device = graphics.GraphicsDevice;
- spriteBatch = new SpriteBatch(GraphicsDevice);
- backgroundTexture = Content.Load<Texture2D>("background");
- levelTexture = Content.Load<Texture2D>("level");
- playerTexture = Content.Load<Texture2D>("player");
- foregroundTexture = Content.Load<Texture2D>("foreground");
- font = Content.Load<SpriteFont>("gameFont");
- screenWidth = device.PresentationParameters.BackBufferWidth;
- screenHeight = device.PresentationParameters.BackBufferHeight;
- BuildPlayerData();
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- KeyboardState keyboard = Keyboard.GetState();
- Vector2 input = Vector2.Zero;
- if (keyboard.IsKeyDown(Keys.W)) input.Y -= 1;
- if (keyboard.IsKeyDown(Keys.A)) input.X -= 1;
- if (keyboard.IsKeyDown(Keys.S)) input.Y += 1;
- if (keyboard.IsKeyDown(Keys.D)) input.X += 1;
- if (input != Vector2.Zero)
- {
- input.Normalize();
- Save1.Position += input * 2;
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- spriteBatch.Begin();
- DrawLevel();
- DrawPlayer();
- DrawText();
- spriteBatch.End();
- base.Draw(gameTime);
- }
- private void DrawText()
- {
- spriteBatch.DrawString(font, String.Format("Position: {0}", Save1.Position), new Vector2(0, 0), Color.White);
- }
- private void DrawLevel()
- {
- Rectangle screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
- spriteBatch.Draw(backgroundTexture, screenRectangle, Color.White);
- spriteBatch.Draw(levelTexture, screenRectangle, Color.White);
- spriteBatch.Draw(foregroundTexture, screenRectangle, Color.White);
- }
- private void DrawPlayer()
- {
- spriteBatch.Draw(playerTexture, Save1.Position, Color.White);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement