示例#1
0
 // These are "factory" methods, they are used when you want to use parameters of the same type and amount
 // for class constructors
 // They are used by calling ClassName.FromMethod(PARAMETERS)
 // for example: Velocity myVelocity = Velocity.FromCoordinates(2, -2); which creates a velocity going towards 2, -2
 // or Velocity myVelocity = Velocity.FromDirection(270, 30); which creates a velocity going straight down at a speed of 30
 public static Velocity FromDirection(float directionDegrees, float speed)
 {
     Velocity v = new Velocity();
     v.direction = new Vector2((float)Math.Cos(directionDegrees * DEG_TO_RAD) * speed, (float)Math.Sin(directionDegrees * DEG_TO_RAD) * speed);
     v.speed = speed;
     return v;
 }
示例#2
0
 public static Velocity FromCoordinates(float x, float y)
 {
     Velocity v = new Velocity();
     v.direction = new Vector2(x, y);
     v.speed = v.direction.Length();
     return v;
 }
示例#3
0
 // Load sprite from existing texture
 public BasicSprite(Texture2D tex, bool collide)
 {
     spriteTex = tex;
     spritePos = new Vector2(0, 0);
     spriteSize = spriteTex.Bounds.Size;
     velocity = Velocity.Zero;
     collidable = collide;
     if (!collidable)
         borderColor = Color.Blue;
 }
示例#4
0
        // Load sprite from file, requires you pass in a game instance for content loading
        // when subclassing BasicSprite you must create the same Constructors in the subclass with :base(parameters)
        // the parameters should match the ones here
        public BasicSprite(Game game, string file, bool collide)
        {
            try {
                spriteTex = game.Content.Load<Texture2D>(file); // load the texture

                spritePos = new Vector2(0, 0); // initial position
                spriteSize = spriteTex.Bounds.Size; // get the size from the texture size
                velocity = Velocity.Zero;
                collidable = collide;
                if (!collidable)
                    borderColor = Color.Blue;

            } catch (ContentLoadException)
            {
                Console.WriteLine(file + " not loaded. Probably can't be found.\n");
            }
        }
示例#5
0
 public void updatePositionFromVelocity(Velocity v)
 {
     spritePos = getUpdatePositionFromVelocity(v);
 }
示例#6
0
 public Vector2 getUpdatePositionFromVelocity(Velocity v)
 {
     return spritePos + v.getDirection();
 }