ラインテスト
以前、
http://d.hatena.ne.jp/sanoh/20070530 を作ったのですがこれをZuneに移植しようと思いました。
namespace LineQ { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; private Texture2D linePoint; private Rectangle lineDrawArea = new Rectangle(); private Rectangle lineSrcArea = new Rectangle(); private Vector2 lineCenter = new Vector2(0, 0); private SpriteEffects lineSpEffect = new SpriteEffects(); //-------------------------------------------------- const int lineCount = 10; Vector2[] pos = new Vector2[lineCount * 2]; Vector2[] direction = new Vector2[lineCount * 2]; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 240; graphics.PreferredBackBufferHeight = 320; // Frame rate is 30 fps by default for Zune. TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); } protected override void Initialize() { Random ran = new Random(); float ang; for (int i = 0; i < lineCount * 2; i++) { pos[i] = new Vector2((float)ran.Next(240 - 10), (float)ran.Next(320 - 10)); 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 LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); linePoint = Content.Load<Texture2D>("Point"); lineSrcArea.X = 0; lineSrcArea.Y = 0; lineSrcArea.Width = 1; lineSrcArea.Height = 1; lineDrawArea.Height = 1; } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); for (int i = 0; i < lineCount * 2; i++) { pos[i] += direction[i]; if ((pos[i].X < 0) || (pos[i].X > 240)) direction[i].X = -direction[i].X; if ((pos[i].Y < 0) || (pos[i].Y > 320)) direction[i].Y = -direction[i].Y; } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear( Color.Black ); spriteBatch.Begin(); Color lineColor = new Color(128, 255, 80, 255); for (int i = 0; i < lineCount; i++) drawLine((int)pos[i * 2].X, (int)pos[i * 2].Y, (int)pos[i * 2 + 1].X, (int)pos[i * 2 + 1].Y, lineColor); spriteBatch.End(); base.Draw(gameTime); } //------------------------------------------------------------------------------- //ラインを引く //------------------------------------------------------------------------------- private void drawLine(int x1, int y1, int x2, int y2, Color lineColor) { double rr, ra; int x, y; x = x2 - x1; y = y2 - y1; rr = Math.Sqrt(x * x + y * y); ra = (x > 0) ? Math.Asin(y / rr) : Math.PI - Math.Asin(y / rr); lineDrawArea.X = x1; lineDrawArea.Y = y1; lineDrawArea.Width = (int)rr; spriteBatch.Draw(linePoint, lineDrawArea, lineSrcArea, lineColor, (float)ra, lineCenter, lineSpEffect, 0); } } }
ただ、問題は残像を残そうと画面をクリアしないようにしたかったのですが、Zuneだとその部分がうまくいかず、まだ検討中、ダブルバッファなので1つ前の画像参照はしないでテクスチャにレンダリングした方がいいのかも。。。。
ほんとは、こんな画面にしたいのだけど・・・・ちょっとPCと動作が異なるみたい