]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CharacterTestBed/Game1.cs
git-svn-id: https://bd85.net/svn/cs3505_group@168 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CharacterTestBed / Game1.cs
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 using Microsoft.Xna.Framework.Net;
12 using Microsoft.Xna.Framework.Storage;
13 using CarFire;
14
15 namespace CharacterTestBed
16 {
17 /// <summary>
18 /// This is the main type for your game
19 /// </summary>
20 public class Game1 : Microsoft.Xna.Framework.Game
21 {
22 GraphicsDeviceManager graphics;
23 SpriteBatch spriteBatch;
24 Player p;
25
26 KeyboardState previousKeyboardState;
27 KeyboardState currentKeyboardState;
28 public Game1()
29 {
30 graphics = new GraphicsDeviceManager(this);
31 Content.RootDirectory = "Content";
32 }
33
34 /// <summary>
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.
39 /// </summary>
40 protected override void Initialize()
41 {
42 // TODO: Add your initialization logic here
43
44 base.Initialize();
45 }
46
47 /// <summary>
48 /// LoadContent will be called once per game and is the place to load
49 /// all of your content.
50 /// </summary>
51 protected override void LoadContent()
52 {
53 // Create a new SpriteBatch, which can be used to draw textures.
54 spriteBatch = new SpriteBatch(GraphicsDevice);
55
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
58 }
59
60 /// <summary>
61 /// UnloadContent will be called once per game and is the place to unload
62 /// all content.
63 /// </summary>
64 protected override void UnloadContent()
65 {
66 // TODO: Unload any non ContentManager content here
67 }
68
69 /// <summary>
70 /// Allows the game to run logic such as updating the world,
71 /// checking for collisions, gathering input, and playing audio.
72 /// </summary>
73 /// <param name="gameTime">Provides a snapshot of timing values.</param>
74 protected override void Update(GameTime gameTime)
75 {
76 // Allows the game to exit
77 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
78 this.Exit();
79 currentKeyboardState = Keyboard.GetState();
80 // TODO: Add your update logic here
81 p.updatePlayerScreenPosition(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
82
83 List<Keys> movementKeys = new List<Keys>();
84 if (currentKeyboardState.IsKeyDown(Keys.Up))
85 {
86 movementKeys.Add(Keys.Up);
87 }
88 if (currentKeyboardState.IsKeyDown(Keys.Down))
89 {
90 movementKeys.Add(Keys.Down);
91 }
92 if (currentKeyboardState.IsKeyDown(Keys.Left))
93 {
94 movementKeys.Add(Keys.Left);
95 }
96 if (currentKeyboardState.IsKeyDown(Keys.Right))
97 {
98 movementKeys.Add(Keys.Right);
99 }
100
101 p.movePlayer(movementKeys);
102
103 previousKeyboardState = Keyboard.GetState();
104 base.Update(gameTime);
105 }
106
107 /// <summary>
108 /// This is called when the game should draw itself.
109 /// </summary>
110 /// <param name="gameTime">Provides a snapshot of timing values.</param>
111 protected override void Draw(GameTime gameTime)
112 {
113 GraphicsDevice.Clear(Color.CornflowerBlue);
114 spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
115
116 p.Draw(spriteBatch);
117
118 // TODO: Add your drawing code here
119 spriteBatch.End();
120 base.Draw(gameTime);
121 }
122 }
123 }
This page took 0.037902 seconds and 4 git commands to generate.