脱線、ジジイは喜ぶクイックス
■残像をつくっていたら、ついムラムラしてきて作ってしまいました、ただ、近くにいた21歳プログラマーに「クリックすって知ってる?」と聞いたら知らないという返事が返って。ちょっとションボリです。
■ソース
namespace WindowsGame { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; ContentManager content; const int VERTICES_SIZE = 2; VertexPositionColor[] vertices = new VertexPositionColor[VERTICES_SIZE]; VertexDeclaration vdecl; BasicEffect basicEffect; const int BOX_SIZE = 4; VertexPositionColor[] verticesBox = new VertexPositionColor[BOX_SIZE]; const int lineCount = 10; Vector2[] pos = new Vector2[ lineCount * 2 ]; Vector2[] direction= new Vector2[ lineCount * 2]; public Game1() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void Initialize() { vdecl = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionColor.VertexElements); basicEffect = new BasicEffect(graphics.GraphicsDevice, null); basicEffect.VertexColorEnabled = true; basicEffect.World = Matrix.Identity; basicEffect.View = Matrix.Identity; //原点( 0, 0 )を画面右上に設定 basicEffect.Projection = Matrix.CreateOrthographicOffCenter( 0.0f, // 左座標 this.Window.ClientBounds.Width, // 右座標 Window幅 this.Window.ClientBounds.Height, // 下座標 Window高さ 0.0f, // 上座標 0.0f, // ニアクリップの距離 1.0f); // ファークリップの距離 Random ran = new Random(); float ang; for (int i = 0; i < lineCount * 2; i++) { pos[ i ] = new Vector2((float)ran.Next(700), (float)ran.Next(500)); ang= (float)ran.Next(360) * 3.14159f / 180.0f; direction[ i ] = new Vector2((float)Math.Sin(ang) * 8.0f, (float)Math.Cos(ang) * 8.0f); } base.Initialize(); } protected override void Update(GameTime gameTime) { for (int i = 0; i < lineCount * 2; i++) { pos[i] += direction[i]; if ((pos[i].X < 0) || (pos[i].X > 800 - 32)) direction[i].X = -direction[i].X; if ((pos[i].Y < 0) || (pos[i].Y > 600 - 32)) direction[i].Y = -direction[i].Y; } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { basicEffect.VertexColorEnabled = true; //--------------------------------------------------------------------- graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha; Box(0, 0, 800, 600, new Color(0, 0, 0, 4)); //--------------------------------------------------------------------- graphics.GraphicsDevice.RenderState.AlphaBlendEnable = false; Color lineColor = new Color(128, 255, 80, 255); for (int i = 0; i < lineCount; i++) Line(pos[i * 2], pos[i * 2 + 1], lineColor); base.Draw(gameTime); } public void Line( Vector2 pos1, Vector2 pos2, Color lineColor) { vertices[0].Position.X = pos1.X; vertices[0].Position.Y = pos1.Y; vertices[0].Position.Z = 0; vertices[0].Color = lineColor; vertices[1].Position.X = pos2.X; vertices[1].Position.Y = pos2.Y; vertices[1].Position.Z = 0; vertices[1].Color = lineColor; basicEffect.Begin(); graphics.GraphicsDevice.VertexDeclaration = vdecl; basicEffect.CurrentTechnique.Passes[0].Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.LineList, vertices, 0, 1); basicEffect.CurrentTechnique.Passes[0].End(); basicEffect.End(); } public void Box(float x1, float y1, float x2, float y2, Color boxColor) { verticesBox[0].Position.X = x1; verticesBox[0].Position.Y = y1; verticesBox[0].Position.Z = 0; verticesBox[0].Color = boxColor; verticesBox[1].Position.X = x2; verticesBox[1].Position.Y = y1; verticesBox[1].Position.Z = 0; verticesBox[1].Color = boxColor; verticesBox[2].Position.X = x1; verticesBox[2].Position.Y = y2; verticesBox[2].Position.Z = 0; verticesBox[2].Color = boxColor; verticesBox[3].Position.X = x2; verticesBox[3].Position.Y = y2; verticesBox[3].Position.Z = 0; verticesBox[3].Color = boxColor; basicEffect.Begin(); graphics.GraphicsDevice.VertexDeclaration = vdecl; basicEffect.CurrentTechnique.Passes[0].Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.TriangleStrip, verticesBox, 0, 2); basicEffect.CurrentTechnique.Passes[0].End(); basicEffect.End(); } } }