source: 2011/23/sijoseha/SpaceWorld/SpaceWorld/SpaceWorld/Game1.cs @ 2044

Revision 2044, 4.7 KB checked in by sijoseha, 8 years ago (diff)

asfd

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using Microsoft.Xna.Framework;
5using Microsoft.Xna.Framework.Audio;
6using Microsoft.Xna.Framework.Content;
7using Microsoft.Xna.Framework.GamerServices;
8using Microsoft.Xna.Framework.Graphics;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Media;
11
12namespace SpaceWorld
13{
14    /// <summary>
15    /// This is the main type for your game
16    /// </summary>
17    public class Game1 : Microsoft.Xna.Framework.Game
18    {
19        GraphicsDeviceManager graphics;
20        GraphicsDevice device;
21        SpriteBatch spriteBatch;
22
23        List<WorldPoint> points;
24        //WorldPoint point, point2, point3, point4;
25        BasicEffect effect;
26
27        Matrix viewMatrix, projectionMatrix;
28
29        public Game1()
30        {
31            graphics = new GraphicsDeviceManager(this);
32            Content.RootDirectory = "Content";
33        }
34
35        /// <summary>
36        /// Allows the game to perform any initialization it needs to before starting to run.
37        /// This is where it can query for any required services and load any non-graphic
38        /// related content.  Calling base.Initialize will enumerate through any components
39        /// and initialize them as well.
40        /// </summary>
41        protected override void Initialize()
42        {
43            // TODO: Add your initialization logic here
44            IsMouseVisible = true;
45            base.Initialize();
46        }
47
48        /// <summary>
49        /// LoadContent will be called once per game and is the place to load
50        /// all of your content.
51        /// </summary>
52        protected override void LoadContent()
53        {
54            // Create a new SpriteBatch, which can be used to draw textures.
55            device = graphics.GraphicsDevice;
56            spriteBatch = new SpriteBatch(GraphicsDevice);
57
58            effect = new BasicEffect(device);
59
60            points = new List<WorldPoint>();
61
62            Random r = new Random();
63            /*for (int i = 0; i < 10; i++)
64            {
65                WorldPoint point = new WorldPoint(new Vector2((float)r.NextDouble() * 400 - 200, (float)r.NextDouble() * 200 - 100));
66                points.Add(point);
67            }*/
68
69            WorldPoint point = new WorldPoint(new Vector2(-10, 0));
70            points.Add(point);
71            point = new WorldPoint(new Vector2(10, 0));
72            points.Add(point);
73
74            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 300.0f);
75            //projectionMatrix = Matrix.CreateOrthographic(device.Viewport.Width, device.Viewport.Height, 0.1f, 100);
76            viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 20), Vector3.Zero, Vector3.Up);
77            // TODO: use this.Content to load your game content here
78        }
79
80        /// <summary>
81        /// UnloadContent will be called once per game and is the place to unload
82        /// all content.
83        /// </summary>
84        protected override void UnloadContent()
85        {
86            // TODO: Unload any non ContentManager content here
87        }
88
89        /// <summary>
90        /// Allows the game to run logic such as updating the world,
91        /// checking for collisions, gathering input, and playing audio.
92        /// </summary>
93        /// <param name="gameTime">Provides a snapshot of timing values.</param>
94        protected override void Update(GameTime gameTime)
95        {
96            // Allows the game to exit
97            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
98                this.Exit();
99
100            // TODO: Add your update logic here
101
102            base.Update(gameTime);
103        }
104
105        /// <summary>
106        /// This is called when the game should draw itself.
107        /// </summary>
108        /// <param name="gameTime">Provides a snapshot of timing values.</param>
109        protected override void Draw(GameTime gameTime)
110        {
111            GraphicsDevice.Clear(Color.Black);
112            RasterizerState rs = new RasterizerState();
113            rs.FillMode = FillMode.WireFrame;
114           
115            //device.RasterizerState = rs;
116            effect.Projection = projectionMatrix;
117            effect.VertexColorEnabled = true;
118            effect.View = viewMatrix;
119            effect.World = Matrix.Identity;
120            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
121            {
122                pass.Apply();
123                foreach (WorldPoint point in points)
124                {
125                    point.Draw(device);
126                }
127            }
128
129           
130
131            base.Draw(gameTime);
132        }
133    }
134}
Note: See TracBrowser for help on using the repository browser.