2 using System.Collections.Generic;
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 using Microsoft.Xna.Framework.Net;
12 using Microsoft.Xna.Framework.Storage;
15 namespace CharacterTestBed
18 /// This is the main type for your game
20 public class Game1 : Microsoft.Xna.Framework.Game
22 GraphicsDeviceManager graphics;
23 SpriteBatch spriteBatch;
26 KeyboardState previousKeyboardState;
27 KeyboardState currentKeyboardState;
30 graphics = new GraphicsDeviceManager(this);
31 Content.RootDirectory = "Content";
35 /// Allows the game to perform any initialization it needs to before starting to run.
36 /// This is where it can query for any required services and load any non-graphic
37 /// related content. Calling base.Initialize will enumerate through any components
38 /// and initialize them as well.
40 protected override void Initialize()
42 // TODO: Add your initialization logic here
48 /// LoadContent will be called once per game and is the place to load
49 /// all of your content.
51 protected override void LoadContent()
53 // Create a new SpriteBatch, which can be used to draw textures.
54 spriteBatch = new SpriteBatch(GraphicsDevice);
56 p = new Player(new Map(), Content.Load<Texture2D>("pinball"), 4, 100, 20, 10);
57 // TODO: use this.Content to load your game content here
61 /// UnloadContent will be called once per game and is the place to unload
64 protected override void UnloadContent()
66 // TODO: Unload any non ContentManager content here
70 /// Allows the game to run logic such as updating the world,
71 /// checking for collisions, gathering input, and playing audio.
73 /// <param name="gameTime">Provides a snapshot of timing values.</param>
74 protected override void Update(GameTime gameTime)
76 // Allows the game to exit
77 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
79 currentKeyboardState = Keyboard.GetState();
80 // TODO: Add your update logic here
81 p.updatePlayerScreenPosition(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
83 List<Keys> movementKeys = new List<Keys>();
84 if (currentKeyboardState.IsKeyDown(Keys.Up))
86 movementKeys.Add(Keys.Up);
88 if (currentKeyboardState.IsKeyDown(Keys.Down))
90 movementKeys.Add(Keys.Down);
92 if (currentKeyboardState.IsKeyDown(Keys.Left))
94 movementKeys.Add(Keys.Left);
96 if (currentKeyboardState.IsKeyDown(Keys.Right))
98 movementKeys.Add(Keys.Right);
101 p.movePlayer(movementKeys);
103 previousKeyboardState = Keyboard.GetState();
104 base.Update(gameTime);
108 /// This is called when the game should draw itself.
110 /// <param name="gameTime">Provides a snapshot of timing values.</param>
111 protected override void Draw(GameTime gameTime)
113 GraphicsDevice.Clear(Color.CornflowerBlue);
114 spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
118 // TODO: Add your drawing code here