2
0

Transform.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Artemis;
  6. using Microsoft.Xna.Framework;
  7. namespace StarWarrior.Components
  8. {
  9. class Transform : Component
  10. {
  11. private Vector3 coords;
  12. public Transform()
  13. {
  14. }
  15. public Transform(Vector3 coords) {
  16. this.coords = coords;
  17. }
  18. public void SetCoords(Vector3 coords) {
  19. this.coords = coords;
  20. }
  21. public void AddX(float x) {
  22. this.coords.X += x;
  23. }
  24. public void AddY(float y) {
  25. this.coords.Y += y;
  26. }
  27. public float GetX() {
  28. return this.coords.X;
  29. }
  30. public void SetX(float x) {
  31. this.coords.X = x;
  32. }
  33. public float GetY() {
  34. return this.coords.Y;
  35. }
  36. public void SetY(float y) {
  37. this.coords.Y = y;
  38. }
  39. public void SetLocation(float x, float y) {
  40. this.coords.X = x;
  41. this.coords.Y = y;
  42. }
  43. public float GetRotation() {
  44. return this.coords.Z;
  45. }
  46. public void SetRotation(float rotation) {
  47. this.coords.Z = rotation;
  48. }
  49. public void AddRotation(float angle) {
  50. this.coords.Z = (this.coords.Z + angle) % 360;
  51. }
  52. public float GetRotationAsRadians() {
  53. return (float)Math.PI * this.coords.Z / 180.0f;
  54. }
  55. public float GetDistanceTo(Transform t) {
  56. return Artemis.Utils.Distance(t.GetX(), t.GetY(), GetX(), GetY());
  57. }
  58. }
  59. }