public void DrawBorder(VertexBatch vertexBatch) { Vector2 size = Size; if (vertexBatch.primitiveType == PrimitiveType.TriangleList) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 2, 1, 2, 3); } if (vertexBatch.primitiveType == PrimitiveType.TriangleStrip) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 2, 3); } if (vertexBatch.primitiveType == PrimitiveType.LineList) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 1, 3, 3, 2, 2, 0); } if (vertexBatch.primitiveType == PrimitiveType.LineStrip) { vertexBatch.Draw(new Vertex[] { new Vertex(postion), new Vertex(postion + size.X_Vector()), new Vertex(postion + size.Y_Vector()), new Vertex(postion + size) }, 0, 1, 3, 2, 0); } }
protected override void Draw(GameTime gameTime) { Common.UpdateFPS(gameTime); GraphicsDevice.Clear(Color.Black); u.width = 100; u.height = 100; u.postion = new Vector2(100, 100); u.Update(); Window.Title = u.mouseStatus.ToString(); var z = Common.MouseState.position.Y / Common.Resolution.Y * 1.15f; vertexBatch.Begin(swordFx.Texture, PrimitiveType.TriangleList); var v = new Triangle(vertices).Rotate(timer, TriangleVertexType.A).RotationList(TriangleVertexType.A, 3.1415f). TransformPosition(Matrix.CreateScale(1f, z, 1f), Common.MouseState.position); v = v.Transform(delegate(int index, Vertex vertex) { return(vertex.ChangeColor(vertex.Color * (index * 1.4f / v.vertex.Length))); }); vertexBatch.Draw(v); vertexBatch.End(); vertexBatch.Begin(PrimitiveType.LineStrip); u.DrawBorder(vertexBatch); vertexBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); text.Draw(spriteBatch, new Vector2(100, 100), null, Color.White, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0); for (int i = 0; i < bullets.Count; i++) { if (bullets[i] == null) { break; } bullets[i].Draw(spriteBatch); } for (int k = 0; k < 1; k++) { for (int i = 0; i < 15; i++) { if (mousePos[i] != Vector2.Zero) { float m = (mousePos[i] - mousePos.TryGetValue(i + 1)).Length() * 0.3f; /*try * { * Vector2[] v = Helper.LagrangeInterpolation(mousePos.CutOut(i - 1, i + 1), (int)(m)); * for (int j = 0; j < v.Length; j++) * { * a.Draw(spriteBatch, v[j] + k * new Vector2(10, 10), null, Color.White * (1.5f - (float)(Math.Sqrt(i) / Math.Sqrt(14))), 0.7853f, new Vector2(20, 20), 1.3f * (1 - (float)(Math.Sqrt(i) / Math.Sqrt(14))), SpriteEffects.None, 0f); * } * } * catch * { * * }*/ for (int j = 0; j < m; j++) { a.Draw(spriteBatch, mousePos[i].LinearInterpolationTo(mousePos.TryGetValue(i + 1), j, m) + k * new Vector2(10, 10), null, Color.White * (1.1f - (float)(Math.Sqrt(i) / Math.Sqrt(14))), 0.7853f, new Vector2(20, 20), 0.9f * (1 - (float)(Math.Sqrt(i) / Math.Sqrt(14))), SpriteEffects.None, 0f); } } } MeteorBullet.flarefx.Draw(spriteBatch, mousePos[0], null, Color.White * 0.9f, 0.7853f, new Vector2(20, 20), 1.4f, SpriteEffects.None, 0f); spriteBatch.End(); base.Draw(gameTime); } }
protected override void Draw(GameTime gameTime) { Common.UpdateFPS(gameTime); GraphicsDevice.Clear(Color.Black); u.width = 100; u.height = 100; u.postion = (Common.Resolution - u.Size) / 2; u.Update(); //Window.Title = u.mouseStatus.ToString() + mousePos[0].ToString(); /* * var p = Common.MouseState.position; * vertices = new Vertex[] * { * new Vertex(new Vector2(0 + p.X , 0f + p.Y), Color.White, new Vector2(0.5f, 0f)), * new Vertex(new Vector2(5f + p.X, 200f + p.Y), Color.White, new Vector2(0.5f, 1f)), * new Vertex(new Vector2(-5f + p.X, 200f + p.Y), Color.White, new Vector2(0.5f, 1f)) * }; * var z = Common.MouseState.position.Y / Common.Resolution.Y * 1.15f; * vertexBatch.Begin(swordFx.Texture, PrimitiveType.TriangleList); * //准备绘制,用到一个材质,顶点的类型是TriangleList * var v = new VertexTriangle(vertices).Rotate(timer, TriangleVertexType.A).RotationList(TriangleVertexType.A, 3.1415f). * TransformPosition(Matrix.CreateScale(1f, z, 1f), Common.MouseState.position); * //声明新的三角形,将三角形绕点A(第一个点)旋转timer rad,从这个三角形生成RotationList,RotationList包含有序的经过旋转的三角形,索引增加三角形旋转的度数也增加,这里最多转3.1415 rad(也就是半圈) * //对Vertex进行变换,每个顶点x不变,y乘以z,这里z是小于1的 * v = v.Transform(delegate (int index, Vertex vertex) * { * return vertex.ChangeColor(vertex.Color * (index * 1f / v.vertex.Length)); * }); * //对Vertex进行变换,索引数值小的透明度低 * vertexBatch.Draw(v); * //进行绘制 * vertexBatch.End(); * //真正地将它绘制到屏幕上,释放资源 * vertexBatch.Begin(PrimitiveType.LineStrip); * //u.DrawBorder(vertexBatch); * vertexBatch.End(); */ spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); //Draw Texts //dtt.DrawString(spriteBatch, "开始游戏\n啥也开始不了", (Common.Resolution - dtt.MeasureString("开始游戏\n啥也开始不了", 1)) / 2, Color.White, default, 1); //Draw Bullets EntityManager.Draw(bullets, spriteBatch); if (mousePos[0] != mousePos[1]) { float t = (mousePos[0] - mousePos[1]).Angle() + 0.7853f; Color c = Color.White.LinearTo(MeteorBullet.drawColor, 1, 2); MeteorBullet.flarefx.Draw(spriteBatch, mousePos[0], c, CenterType.MiddleCenter, 2f, t); MeteorBullet.flarefxAlt.Draw(spriteBatch, mousePos[0], c * 0.5f, CenterType.MiddleCenter, 5f, t); MeteorBullet.flarefxAlt.Draw(spriteBatch, (mousePos[0] + mousePos[1]) / 2, c * 0.5f, CenterType.MiddleCenter, 5f, t); MeteorBullet.flarefxAlt.Draw(spriteBatch, mousePos[1], c * 0.5f, CenterType.MiddleCenter, 5f, t); MeteorBullet.flarefxAlt.Draw(spriteBatch, mousePos[2], c * 0.5f, CenterType.MiddleCenter, 5f, t); MeteorBullet.flarefxAlt.Draw(spriteBatch, mousePos[4], c * 0.5f, CenterType.MiddleCenter, 5f, t); } else { MeteorBullet.flarefx.Draw(spriteBatch, mousePos[0], Color.White, CenterType.MiddleCenter, 1.5f, 0.7853f); } spriteBatch.End(); //Draw Mouse var v = Helper.CatmullRom(mousePos, 3); if (Keyboard.GetState().IsKeyDown(Keys.Z)) { throw new Exception(v.ToStringAlt()); } vertexBatch.Begin(tex, BlendState.Additive, PrimitiveType.TriangleStrip); vertexBatch.Draw(VertexTriangle.Strip(v, 20, delegate(int index, Vertex vertex) { return(vertex.ChangeCoord(index * 0.25f / v.Length + (float)(Math.Sin(timer * 2) + 1) / 4, index % 2 == 0 ? 0f : 1f).ChangeColor(MeteorBullet.drawColor.LinearTo(MeteorBullet.drawColor2, index, v.Length * 0.8f) * (-index * 0.5f / v.Length + 1) * (-index * 0.5f / v.Length + 1) * 1.2f)); } )); vertexBatch.End(); vertexBatch.Begin(tex2, BlendState.Additive, PrimitiveType.TriangleStrip); vertexBatch.Draw(VertexTriangle.Strip(v, 30, delegate(int index, Vertex vertex) { return(vertex.ChangeCoord((float)(Math.Sin(timer) + Math.Sin(index * 8f / v.Length) + 2) / 4, index % 2 == 0 ? 0.3f : 0.7f).ChangeColor(MeteorBullet.drawColor.LinearTo(MeteorBullet.drawColor2, index, v.Length * 0.8f) * (-index * 0.5f / v.Length + 1) * (-index * 0.5f / v.Length + 1) * 1.4f)); } )); vertexBatch.End(); base.Draw(gameTime); }