Ejemplo n.º 1
0
 public MeleeAttack(Character.Character attacker, GameObject target, int delay, SpriteAnimation targetAnimation)
 {
     Delay = delay;
     Attacker = attacker;
     Target = target;
     TargetAnimation = targetAnimation;
     Timer = 0;
 }
Ejemplo n.º 2
0
 public static Vector2 Flee(GameObject model, GameObject target)
 {
     // Se o modelo estiver a mais de 200 pixels de seu alvo, ele não foge mais
     if ((model.Position - target.Position).Length() < 200)
     {
         float angle = MapHelper.GetAngleBetweenPoints(model, target);
         angle = angle < 0 ? angle + 360 : angle;
         return (-1*MapHelper.GetVectorFromDirection(MapHelper.GetDirectionFromAngle(angle)));
     }
     return Vector2.Zero;
 }
Ejemplo n.º 3
0
        public static Vector2 KeepDistance(GameObject model, List<GameObject> neighbours, float distance)
        {
            Vector2 steeringForce = Vector2.Zero;

            for (int i = 0; i < neighbours.Count; i++)
            {
                if (neighbours[i] is Enemy && !(neighbours[i] as Enemy).IsAlive)
                    continue;

                if (neighbours[i] != model)
                {
                    if ((model.Position - neighbours[i].Position).Length() < distance)
                    {
                        steeringForce += Flee(model, neighbours[i]);

                        if (steeringForce != Vector2.Zero)
                            steeringForce.Normalize();
                    }
                }
            }

            return steeringForce;
        }
Ejemplo n.º 4
0
        public bool WillCollideWithObject(GameObject obj, Vector2 movement)
        {
            Vector2 distance = obj.Position - FuturePosition(movement);
            if (obj.CollisionRadius > 0)
                return (distance.Length() < obj.CollisionRadius + CollisionRadius);

            return false;
        }
Ejemplo n.º 5
0
 public bool IsInAttackRange(GameObject target)
 {
     Vector2 distance = target.Position - Position;
     // Faço os calculos apenas se o personagem estiver proximo o suficiente
     return (distance.Length() <= target.CollisionRadius + CurrentWeapon.AttackRange);
 }
Ejemplo n.º 6
0
        public bool CollidesWithObject(GameObject c)
        {
            Vector2 distance = c.Position - Position;
            if (c.CollisionRadius > 0)
                return (distance.Length() < c.CollisionRadius + CollisionRadius);

            return false;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Checks wheter the character is within hearing radius
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        public bool CanHear(GameObject gameObject)
        {
            // TODO: Add noise level to the hearing detection
            var distance = (int) (Position - gameObject.Position).Length();
            distance = distance < 0 ? distance*-1 : distance;

            return distance < HearingRange;
        }
Ejemplo n.º 8
0
        public bool CanAttackCharacter(GameObject target)
        {
            float angle = MapHelper.GetAngleBetweenPoints(Position, target.Position);
            if (angle < 0)
                angle += 360;

            float myangle = MapHelper.GetAngleFromVector(MapHelper.GetVectorFromDirection(Facing));
            float resultingAngle = myangle - angle;

            return resultingAngle <= CurrentWeapon.AttackAngle/2;
        }
Ejemplo n.º 9
0
 public static float GetAngleBetweenPoints(GameObject observer, GameObject target)
 {
     Vector2 diff = target.Position - observer.Position;
     float angle = MathHelper.ToDegrees((float) Math.Atan2(diff.Y, diff.X));
     return angle;
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Retorna o vetor direção para a qual o modelo deve ser movimentado, em direção ao seu alvo
 /// </summary>
 /// <param name="position">Posição do modelo</param>
 /// <param name="target">Posição do alvo</param>
 /// <returns>Vetor direção</returns>
 public static Vector2 Seek(GameObject model, Vector2 target)
 {
     if ((model.CollisionRadius) < (model.Position - target).Length())
     {
         Vector2 diff = (target - model.Position);
         float angle = MathHelper.ToDegrees((float) Math.Atan2(diff.Y, diff.X));
         angle = angle < 0 ? angle + 360 : angle;
         return MapHelper.GetVectorFromDirection(MapHelper.GetDirectionFromAngle(angle));
     }
     return Vector2.Zero;
 }
Ejemplo n.º 11
0
        private void SelectObject()
        {
            Vector2 v = new Vector2(MouseTile.X, MouseTile.Y);

            bool found = false;
            lblSelectedObject.Text = "Selecionado: None";
            selectedObject = null;

            foreach (MapObject o in CurrentMap.MapObjects)
            {
                if (MapHelper.GetTileFromPixels(o.Position) == v)
                {
                    found = true;
                    selectedObject = o;
                    lblSelectedObject.Text = "Selecionado: MapObject " + o.Name;
                    break;
                }
            }

            if (!found)
                foreach (Enemy en in CurrentMap.MapEnemies)
                {
                    if (MapHelper.GetTileFromPixels(en.Position) == v)
                    {
                        selectedObject = en;
                        lblSelectedObject.Text = "Selecionado: Enemy " + en.Name;
                        break;
                    }
                }
            if (!found)
                foreach (Npc npc in CurrentMap.MapNpcs)
                {
                    if (MapHelper.GetTileFromPixels(npc.Position) == v)
                    {
                        selectedObject = npc;
                        lblSelectedObject.Text = "Selecionado: NPC " + npc.Name;
                        break;
                    }
                }
            if (!found)
                foreach (Event ev in CurrentMap.MapEvents)
                {
                    if (ev.Position == v)
                    {
                        selectedObject = ev;
                        lblSelectedObject.Text = "Selecionado: Event " + ev.Label;
                        SelectEvent(ev);
                        break;
                    }
                }
        }
Ejemplo n.º 12
0
        private void mapControl_MouseUp(object sender, MouseEventArgs e)
        {
            // Ao liberar o botão esquerdo do mouse caso o PaintArea esteja selecionado
            // e as variaveis de paint area estejam preenchidas
            // preencho as celulas contidas na area selecionada com a textura atual

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (CurrentLayerType == LayerType.MapLayer)
                {
                    if (CurrentEditorCommand == EditorCommand.PaintArea && mapControl.PaintedAreaSelected)
                    {
                        PaintArea();
                    }
                }

                if (CurrentEditorCommand == EditorCommand.Select)
                    selectedObject = null;
            }

            mapControl.PaintedAreaCurrentPosition = new Vector2(-1, -1);
            mapControl.PaintedAreaStart = new Vector2(-1, -1);
        }