Exemplo n.º 1
0
 public Transform(TransformBase transform) : this()
 {
     position = new Vector2(transform.position.X, transform.position.Y);
     size     = new Vector2(transform.size.X, transform.size.Y);
     rotation = transform.rotation;
     parent   = transform.parent;
 }
Exemplo n.º 2
0
        public static async void CreateProjectileAsync(Projectile projectile)
        {
            if (!IsConnected())
            {
                return;
            }

            try
            {
                TransformBase tr    = projectile.transform;
                var           stats = new ProjectileStats()
                {
                    damage      = projectile.damage,
                    speed       = projectile.speed,
                    bounceAngle = projectile.bounceAngle,
                    bounceCount = projectile.bounceCount,
                };

                await connection.InvokeAsync("CreateProjectile", tr.position.X, tr.position.Y, tr.rotation, stats);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error sending projectile update: " + e.Message);
            }
        }
Exemplo n.º 3
0
        public void Spawn()
        {
            switch (tankType)
            {
            case TankType.HeavyTank:
                builder = new HeavyTankBuilder();
                break;

            case TankType.LightTank:
                builder = new LightTankBuilder();
                break;

            default:
                builder = new HeavyTankBuilder();
                break;
            }
            TankDirector director = new TankDirector(builder);

            TransformBase tr = spawnPoint.transform;

            director.Construct(tr.position.X, tr.position.Y);

            controllable = builder.GetResult();
            controllable.transform.rotation = spawnPoint.transform.rotation;
        }
Exemplo n.º 4
0
        void UpdatePosition(float deltaTime)
        {
            Vector2       vertical = new Vector2();
            float         speed    = controllable.speed;
            TransformBase tr       = controllable.transform;

            // Test strategy pattern
            if (elapsedTime < 3f)
            {
                action = new MoveForward();
                action.DoAction(tr, ref vertical, speed, deltaTime);
            }
            else if (elapsedTime >= 3f && elapsedTime < 4.8f)
            {
                action = new TurnRight();
                action.DoAction(tr, ref vertical, speed, deltaTime);
            }
            else if (elapsedTime >= 4.8f && elapsedTime < 6.6f)
            {
                action = new TurnLeft();
                action.DoAction(tr, ref vertical, speed, deltaTime);
            }
            else if (elapsedTime >= 6.6f && elapsedTime < 9.6f)
            {
                action = new MoveBackwards();
                action.DoAction(tr, ref vertical, speed, deltaTime);
            }
            else if (elapsedTime >= 9.6f)
            {
                elapsedTime = 0;
            }

            tr.position           += Utils.Rotate(vertical, tr.rotation);
            controllable.transform = tr;
        }
Exemplo n.º 5
0
        public void RenderShape(Graphics g, Brush brush, TransformBase transform, Shape shape, Vector2 offset = default)
        {
            if (shape == Shape.None)
            {
                return;
            }

            Vector2 position = transform.WorldPosition;
            float   rotation = transform.WorldRotation;

            if (rotation != 0)
            {
                Rotator.Rotate(g, position + offset, rotation);
            }

            switch (shape)
            {
            case Shape.Rectangle:
                Rectangle.Draw(g, brush, position + offset, transform.size);
                break;

            case Shape.Ellipse:
                Ellipse.Draw(g, brush, position + offset, transform.size);
                break;

            case Shape.Mesh:
            default:
                throw new NotImplementedException("Shape not implemented");
            }

            if (rotation != 0)
            {
                g.ResetTransform();
            }
        }
Exemplo n.º 6
0
        public override void Render(Graphics g)
        {
            base.Render(g);

            TransformBase tr = controllable.transform;
            float         x  = tr.position.X;
            float         y  = tr.position.Y - Control.DefaultFont.Height - 18;

            g.DrawString(name, Control.DefaultFont, Brushes.Black, x, y, nameFormat);
        }
Exemplo n.º 7
0
        private static void ResolveCollision(GameObject item1, GameObject item2, Collision collision, bool equaly = false)
        {
            TransformBase tr1 = item1.transform;
            TransformBase tr2 = item2.transform;

            Vector2 correction = collision.normal * collision.penetration;

            if (equaly)
            {
                correction   /= 2f;
                tr2.position += correction;
            }
            tr1.position -= correction;
        }
Exemplo n.º 8
0
        public static async void SendPositionUpdateAsync(Tank tank)
        {
            if (!IsConnected())
            {
                return;
            }

            try
            {
                TransformBase tr       = tank.transform;
                float         turetRot = tank.Turret.transform.rotation;
                await connection.SendAsync("SendPositionUpdate", tr.position.X, tr.position.Y, tr.rotation, turetRot);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error sending position update: " + e.Message);
            }
        }
Exemplo n.º 9
0
        private static bool CirclevsCircleOverlap(GameObject item1, GameObject item2, ref Collision collision)
        {
            TransformBase circle1 = item1.transform;
            TransformBase circle2 = item2.transform;

            float   radius = (Math.Max(circle1.size.X, circle1.size.Y) + Math.Max(circle2.size.X, circle2.size.Y)) / 2;
            Vector2 normal = circle2.position - circle1.position;

            if (radius * radius <= normal.LengthSquared())
            {
                return(false);
            }

            float normalLen = normal.Length();
            float pen       = radius - normalLen;

            collision.penetration = new Vector2(pen);
            collision.normal      = normal / normalLen;

            return(true);
        }
Exemplo n.º 10
0
        private static bool AABBvsCircleOverlap(GameObject item1, GameObject item2, ref Collision collision)
        {
            float eps = 1e-3f;

            BoxAABB       rect   = item1.AABB;
            TransformBase rectTr = item1.transform;
            TransformBase circle = item2.transform;

            if (rectTr.position == circle.position)
            {
                return(false);
            }

            float   radius  = Math.Max(circle.size.X, circle.size.Y) / 2f;
            Vector2 closest = Vector2.Clamp(circle.position, rect.min, rect.max);

            if (closest == circle.position)
            {
                closest = circle.position.MoveTowards(rectTr.position, eps);
            }

            Vector2 normal = circle.position - closest;

            if (radius * radius <= normal.LengthSquared())
            {
                return(false);
            }

            float normalLen = normal.Length();
            float pen       = radius - normalLen;

            collision.penetration = new Vector2(pen);
            collision.normal      = normal / normalLen;

            return(true);
        }
Exemplo n.º 11
0
 public override void AddChild(TransformBase child)
 {
     children.Add(child);
 }
Exemplo n.º 12
0
 public void DoAction(TransformBase tr, ref Vector2 vertical, float speed, float deltaTime)
 {
     tr.rotation -= speed * deltaTime;
 }
Exemplo n.º 13
0
 public void DoAction(TransformBase tr, ref Vector2 vertical, float speed, float deltaTime)
 {
     vertical.Y = -speed * deltaTime;
 }
Exemplo n.º 14
0
 public void RenderShape(Graphics g, Pen pen, TransformBase transform, Shape shape, Vector2 offset = default)
 {
     Renderer.RendererInstance.RenderShape(g, pen, transform, shape, offset);
 }