]> Dogcows Code - chaz/carfire/blob - Project06/lobbyTest/lobbyTest/Game1.cs
Background for lobby, currently has background with spotlight that moves around.
[chaz/carfire] / Project06 / lobbyTest / lobbyTest / 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
14 namespace lobbyTest
15 {
16 /// <summary>
17 /// This is the main type for your game
18 /// </summary>
19 public class Game1 : Microsoft.Xna.Framework.Game
20 {
21 GraphicsDeviceManager graphics;
22 SpriteBatch spriteBatch;
23
24 Texture2D background;
25 Texture2D spotLight;
26 Texture2D cs;
27
28 Vector2 backgroundPos;
29 Vector2 spotLightPos;
30 Vector2 spotLightCenter;
31 Vector2 csPos;
32
33 Vector2 zero;
34 Vector2 spotLightVelocity;
35
36 int MaxX;
37 int MinX;
38 int MaxY;
39 int MinY;
40
41 public Game1()
42 {
43 graphics = new GraphicsDeviceManager(this);
44 Content.RootDirectory = "Content";
45 }
46
47 /// <summary>
48 /// Allows the game to perform any initialization it needs to before starting to run.
49 /// This is where it can query for any required services and load any non-graphic
50 /// related content. Calling base.Initialize will enumerate through any components
51 /// and initialize them as well.
52 /// </summary>
53 protected override void Initialize()
54 {
55 // TODO: Add your initialization logic here
56 graphics.PreferredBackBufferWidth = 800;
57 graphics.PreferredBackBufferWidth = 600;
58 base.Initialize();
59 }
60
61 /// <summary>
62 /// LoadContent will be called once per game and is the place to load
63 /// all of your content.
64 /// </summary>
65 protected override void LoadContent()
66 {
67 // Create a new SpriteBatch, which can be used to draw textures.
68 spriteBatch = new SpriteBatch(GraphicsDevice);
69 background = Content.Load<Texture2D>("background");
70 spotLight = Content.Load<Texture2D>("spotlight");
71 cs = Content.Load<Texture2D>("cs");
72 backgroundPos = new Vector2(0f, 0f);
73 spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);
74 spotLightCenter = new Vector2(800f, 800f);
75 spotLightVelocity = new Vector2(-100, 33);
76 csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);
77
78 zero = new Vector2(0, 0);
79
80 MaxX = graphics.GraphicsDevice.Viewport.Width;
81 MinX = 0;
82 MaxY = graphics.GraphicsDevice.Viewport.Height;
83 MinY = 100;
84 // TODO: use this.Content to load your game content here
85 }
86
87 /// <summary>
88 /// UnloadContent will be called once per game and is the place to unload
89 /// all content.
90 /// </summary>
91 protected override void UnloadContent()
92 {
93 // TODO: Unload any non ContentManager content here
94 }
95
96 /// <summary>
97 /// Allows the game to run logic such as updating the world,
98 /// checking for collisions, gathering input, and playing audio.
99 /// </summary>
100 /// <param name="gameTime">Provides a snapshot of timing values.</param>
101 protected override void Update(GameTime gameTime)
102 {
103 // Allows the game to exit
104 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
105 this.Exit();
106
107 // TODO: Add your update logic here
108 UpdateSpotLight(gameTime);
109 base.Update(gameTime);
110 }
111
112 /// <summary>
113 /// This is called when the game should draw itself.
114 /// </summary>
115 /// <param name="gameTime">Provides a snapshot of timing values.</param>
116 protected override void Draw(GameTime gameTime)
117 {
118 GraphicsDevice.Clear(Color.CornflowerBlue);
119 spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
120 // TODO: Add your drawing code here
121 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
122 spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);
123 spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);
124
125 spriteBatch.End();
126 base.Draw(gameTime);
127 }
128
129 private void UpdateSpotLight(GameTime gameTime)
130 {
131 spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,
132 spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);
133
134 if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall
135 {
136 spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);
137 }
138 else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall
139 {
140 spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);
141 }
142 }
143 }
144 }
This page took 0.034703 seconds and 4 git commands to generate.