/// <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 this.Window.AllowUserResizing = true; this.Window.ClientSizeChanged += new EventHandler <EventArgs>(Window_ClientSizeChanged); void Window_ClientSizeChanged(object sender, EventArgs e) { graphics.PreferredBackBufferWidth = Window.ClientBounds.Width; graphics.PreferredBackBufferHeight = Window.ClientBounds.Height; graphics.ApplyChanges(); } originalcubepos = new Vector3(0, 0, -5); floor = new Model3D(new Vector3(0, -1, 0), 0, 256, 0, 192); cube = new Player(originalcubepos, 1, 2, 2, 2); cube.initialize(GraphicsDevice); cube.health = 4; level = 0; levelseconds = 0; leveltimer = 0; levelenemies = new List <List <Enemy> >(); List <Enemy> e0 = new List <Enemy>(); e0.Add(new Enemy(new Vector3(15, 0, 30), 2, 2, 2, 2)); e0.Add(new Enemy(new Vector3(-15, 0, 30), 2, 2, 2, 2)); levelenemies.Add(e0); List <Enemy> e1 = new List <Enemy>(); e1.Add(new Enemy(new Vector3(40, 0, 40), 2, 2, 2, 2)); e1.Add(new Enemy(new Vector3(-40, 0, 40), 2, 2, 2, 2)); e1.Add(new Enemy(new Vector3(-40, 0, -40), 2, 2, 2, 2)); e1.Add(new Enemy(new Vector3(40, 0, -40), 2, 2, 2, 2)); levelenemies.Add(e1); List <Enemy> e2 = new List <Enemy>();; float x1 = (float)((enemyrange + 5) * Math.Sin(2 * Math.PI / 5)); float x2 = (float)((enemyrange + 5) * Math.Sin(4 * Math.PI / 5)); float z1 = (float)((enemyrange + 5) * Math.Cos(2 * Math.PI / 5)); float z2 = (float)((enemyrange + 5) * Math.Cos(Math.PI / 5)); e2.Add(new Enemy(new Vector3(0, 0, enemyrange + 5), 2, 2, 2, 2)); e2.Add(new Enemy(new Vector3(x1, 0, z1), 2, 2, 2, 2)); e2.Add(new Enemy(new Vector3(-x1, 0, z1), 2, 2, 2, 2)); e2.Add(new Enemy(new Vector3(x2, 0, -z2), 2, 2, 2, 2)); e2.Add(new Enemy(new Vector3(-x2, 0, -z2), 2, 2, 2, 2)); levelenemies.Add(e2); //m.initialize(GraphicsDevice); for (int i = 0; i < levelenemies.Count; i++) { List <Enemy> e = levelenemies.ElementAt <List <Enemy> >(i); for (int j = 0; j < e.Count; j++) { Enemy enemy = e.ElementAt <Enemy>(j); enemy.initialize(GraphicsDevice); } } floor.initialize(GraphicsDevice); state = 0; basic = new BasicEffect(GraphicsDevice); basic.Alpha = 1.0f; //basic.TextureEnabled = true; basic.VertexColorEnabled = true; basic.LightingEnabled = false; bill = new BasicEffect(GraphicsDevice) { TextureEnabled = true, VertexColorEnabled = true, }; walls = new List <Model3D>(); for (int i = 0; i < 50; i++) { walls.Add(new Model3D(new Vector3((2 * i) - 50, 0, 50), 0, 2, 2, 2)); walls.Add(new Model3D(new Vector3((2 * i) - 50, 0, -50), 0, 2, 2, 2)); walls.Add(new Model3D(new Vector3(-50, 0, (2 * i) - 50), 0, 2, 2, 2)); walls.Add(new Model3D(new Vector3(50, 0, (2 * i) - 50), 0, 2, 2, 2)); } h = new Rectangle[4]; h[0] = new Rectangle(0, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8); h[1] = new Rectangle(GraphicsDevice.Viewport.Width / 8, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8); h[2] = new Rectangle(GraphicsDevice.Viewport.Width / 4, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8); h[3] = new Rectangle(3 * GraphicsDevice.Viewport.Width / 8, 0, GraphicsDevice.Viewport.Width / 8, GraphicsDevice.Viewport.Height / 8); /*for (int i = 0; i < walls.Count; i++) * { * Model3D w = walls.ElementAt<Model3D>(i); * walls.Add(new Model3D(w.position+new Vector3(0,2,0),0, 2,2,2)); * walls.Add(new Model3D(w.position + new Vector3(0, 4, 0), 0, 2, 2, 2)); * }*/ for (int i = 0; i < walls.Count; i++) { Model3D w = walls.ElementAt <Model3D>(i); w.initialize(GraphicsDevice); } soundeffects = new List <SoundEffect>(); base.Initialize(); //Create the triangle /*triangleVertices = new VertexPositionColor[3]; * triangleVertices[0] = new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red); * triangleVertices[1] = new VertexPositionColor(new Vector3(-1, 10, 10), Color.Blue); * triangleVertices[2] = new VertexPositionColor(new Vector3(-1, 0, 20), Color.Green); * // triangleVertices[3] = new VertexPositionColor(new Vector3(100, 0, 0), Color.Goldenrod); * * vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 4, BufferUsage.WriteOnly); * * vertexBuffer.SetData<VertexPositionColor>(triangleVertices); */ }
/// <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) { if (state == 4) { spritebatch.Begin(); spritebatch.DrawString(data, "" + levelseconds, new Vector2(GraphicsDevice.Viewport.Width / 2, 3 * GraphicsDevice.Viewport.Height / 4), Color.Black); spritebatch.End(); } if (state != 1 || paused == true) { // //GraphicsDevice.Clear(Color.Aqua); spritebatch.Begin(); spritebatch.Draw(screen, frame, Color.White); spritebatch.End(); } else { //GraphicsDevice.BlendState = BlendState.Opaque; /*spritebatch.Begin(); * for (int i = 0; i < cube.health; i++) * { * spritebatch.Draw(heart, h[i], Color.White); * } * spritebatch.End();*/ GraphicsDevice.DepthStencilState = DepthStencilState.Default; //GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; GraphicsDevice.Clear(Color.SlateBlue); basic.Projection = cube.camera.projection; basic.View = cube.camera.view; basic.World = cube.camera.world; GraphicsDevice.SetVertexBuffer(vertexBuffer); //turn off back face culling RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; GraphicsDevice.RasterizerState = rasterizerState; foreach (EffectPass pass in basic.CurrentTechnique.Passes) { pass.Apply(); //GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 3); } cube.draw(GraphicsDevice); List <Enemy> e = levelenemies.ElementAt <List <Enemy> >(level); for (int j = 0; j < e.Count; j++) { Enemy enemy = e.ElementAt <Enemy>(j); enemy.draw(GraphicsDevice, cube.camera); } floor.draw(GraphicsDevice, cube.camera); for (int i = 0; i < walls.Count; i++) { Model3D w = walls.ElementAt <Model3D>(i); w.draw(GraphicsDevice, cube.camera); } spritebatch.Begin(0, null, null, null, RasterizerState.CullNone, bill); spritebatch.DrawString(data, "Score", Vector2.Zero, Color.Black, 0, Vector2.Zero, 0.5f, 0, 0); spritebatch.End(); //drawing code base.Draw(gameTime); } }