| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- //---------------------------------------------------------------------------------
- // Ported to the Atomic Game Engine
- // Originally written for XNA by Michael Hoffman
- // Find the full tutorial at: http://gamedev.tutsplus.com/series/vector-shooter-xna/
- //----------------------------------------------------------------------------------
- using System;
- using AtomicEngine;
- namespace AtomicBlaster
- {
- static class Extensions
- {
- public static float ToAngle(this Vector2 vector)
- {
- return (float)Math.Atan2(vector.Y, vector.X);
- }
- public static Vector2 ScaleTo(this Vector2 vector, float length)
- {
- return vector * (length / vector.Length);
- }
- /*
- public static Point ToPoint(this Vector2 vector)
- {
- return new Point((int)vector.X, (int)vector.Y);
- }
- */
- public static float NextFloat(this Random rand, float minValue, float maxValue)
- {
- return (float)rand.NextDouble() * (maxValue - minValue) + minValue;
- }
- public static Vector2 NextVector2(this Random rand, float minLength, float maxLength)
- {
- double theta = rand.NextDouble() * 2 * Math.PI;
- float length = rand.NextFloat(minLength, maxLength);
- return new Vector2(length * (float)Math.Cos(theta), length * (float)Math.Sin(theta));
- }
- }
- }
|