Esempio n. 1
0
 public BehaviorEngine(Character character)
 {
     Actions = new List<ActionBehavior>();
     Character = character;
     if (rand == null)
         rand = new Random((int) (DateTime.Now.Millisecond*character.Position.X*character.Position.Y));
 }
Esempio n. 2
0
 public static Vector2 Seek(Character character, Character target, float minRange)
 {
     if (minRange + target.CollisionRadius <= (character.Position - target.Position).Length())
     {
         float angle = MapHelper.GetAngleBetweenPoints(character, target);
         angle = angle < 0 ? angle + 360 : angle;
         return MapHelper.GetVectorFromDirection(MapHelper.GetDirectionFromAngle(angle));
         //return MapHelper.GetVectorFromAngle(angle);
     }
     return Vector2.Zero;
 }
Esempio n. 3
0
        public static Vector2 Separation(Character model, List<Character> neighbours)
        {
            Vector2 steeringForce = Vector2.Zero;

            for (int i = 0; i < neighbours.Count; i++)
            {
                if (neighbours[i] != model && neighbours[i].IsAlive)
                {
                    if (model.CollidesWithObject(neighbours[i]))
                    {
                        steeringForce += Flee(model, neighbours[i]);

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

            return steeringForce;
        }
Esempio n. 4
0
 public void Update(GameTime gameTime, Character character, List<GameObject> gameObjects)
 {
 }
Esempio n. 5
0
        public void NewGame()
        {
            Player = new Character(new SpriteAnimation(GameGraphics.MonsterSpriteIdle, 200, 11))
            {
                Position = MapHelper.GetPixelsFromTileCenter(new Vector2(3, 3)),
                MaxHp = 100,
                Hp = 100
            };

            Points = 0;

            Player.AttackSprite = new SpriteAnimation(GameGraphics.MonsterSpriteAttack, 200, 4);

            #region GenerateMap
            var firstMap = new Map
            {
                Height = 50,
                Width = 50,
                Tileset = new Tileset()
                {
                    Columns = 4,
                    TextureMap = GameGraphics.SpaceTextures3,
                    TileSize = 64
                },
                Layers = new List<MapLayer>()
                {
                    new MapLayer(50, 50)
                }
            };

            var textureMap = new int[50, 50];

            var rand = new Random(DateTime.Now.Millisecond);
            for (int y = 0; y < 50; y++)
            {
                for (int x = 0; x < 50; x++)
                {
                    textureMap[x, y] = rand.Next(0, 16);
                }
            }

            CurrentMap = firstMap;

            firstMap.Layers[0].Map = textureMap;
            #endregion
        }
Esempio n. 6
0
        private void KillEnemy(Character enemy, bool byPlayer)
        {
            //var xpFont = Fonts.ArialBlack12;
            if (Player.Target == enemy)
            {
                Player.Target = null;
            }

            enemy.IsAlive = false;

            #region Creep ship

            if (enemy.UniqueObjectId == 1 || enemy.UniqueObjectId == 4)
            {
                if (byPlayer)
                { 
                    GameGraphics.SoundExplosion.Play();
                }

                Game.CurrentMap.Animations.Add(new Animation()
                {
                    Position = enemy.Position,
                    Collision = false,
                    Sprite = new SpriteAnimation(GameGraphics.Explosion1, 200, 4)
                    {
                        IsToggle = true
                    }
                });
            }

            #endregion

            #region BigShip1

            if (enemy.UniqueObjectId == 2)
            {
                if (byPlayer)
                {
                    GameGraphics.SoundExplosionBig.Play();
                }

                Game.CurrentMap.Animations.Add(new Animation()
                {
                    Position = enemy.Position,
                    Collision = false,
                    Sprite = new SpriteAnimation(GameGraphics.Explosion1, 200, 4)
                    {
                        IsToggle = true
                    }
                });
                Game.CurrentMap.Animations.Add(new Animation()
                {
                    Position = enemy.Position + new Vector2(30, 30),
                    Collision = false,
                    Sprite = new SpriteAnimation(GameGraphics.Explosion1, 200, 4)
                    {
                        IsToggle = true
                    }
                });
                Game.CurrentMap.Animations.Add(new Animation()
                {
                    Position = enemy.Position + new Vector2(30, -30),
                    Collision = false,
                    Sprite = new SpriteAnimation(GameGraphics.Explosion1, 200, 4)
                    {
                        IsToggle = true
                    }
                });
                Game.CurrentMap.Animations.Add(new Animation()
                {
                    Position = enemy.Position + new Vector2(-30, -30),
                    Collision = false,
                    Sprite = new SpriteAnimation(GameGraphics.Explosion1, 200, 4)
                    {
                        IsToggle = true
                    }
                });
                Game.CurrentMap.Animations.Add(new Animation()
                {
                    Position = enemy.Position + new Vector2(-30, 30),
                    Collision = false,
                    Sprite = new SpriteAnimation(GameGraphics.Explosion1, 200, 4)
                    {
                        IsToggle = true
                    }
                });

                SpawnHealthKits(2, enemy.Position);
            }

            #endregion
            
            #region Buff Kit
            if (enemy.UniqueObjectId == 3)
            {
                if (byPlayer)
                {
                    GameGraphics.SoundHeal.Play();
                }
            }
            #endregion

            AliveNpcs.FindAll(x => x.Target == enemy).ForEach(x => x.Target = null);

            Player.Target = null;
            enemy.IsAlive = false;
            //enemy.CharSprite.AnimateAction(AnimationType.Death);
        }
Esempio n. 7
0
        public static bool EnforcePenetrationConstraint(Character model, IEnumerable<GameObject> objects)
        {
            bool CollisedWithNeighbour = false;

            // Checar colisão com todos os Inimigos
            foreach (GameObject obj in objects)
            {
                // If is enemy and is dead
                if (obj is Character && !(obj as Character).IsAlive)
                    continue;

                // If this object has no collision
                if (!obj.Collision)
                    continue;

                if (model != obj && model.CollidesWithObject(obj))
                {
                    CollisedWithNeighbour = true;
                    Vector2 d = obj.Position - model.Position;

                    if (d != Vector2.Zero)
                        d.Normalize();

                    model.Position = obj.Position - (d*(model.CollisionRadius + obj.CollisionRadius));
                }
            }
            return CollisedWithNeighbour;
        }
Esempio n. 8
0
        public static Vector2 KeepDistance(Enemy creature, Character character, int distance)
        {
            Vector2 steeringForce = Vector2.Zero;
            if ((creature.Position - character.Position).Length() < distance)
            {
                steeringForce += Flee(creature, character);

                if (steeringForce != Vector2.Zero)
                    steeringForce.Normalize();
            }
            return steeringForce;
        }
Esempio n. 9
0
        public static bool HasFutureCollision(Character character, Vector2 characterMovement, List<GameObject> gameObjects)
        {
            foreach (GameObject item in gameObjects)
            {
                if (item is Enemy && !(item as Enemy).IsAlive)
                    continue;

                if (item.UniqueObjectId != character.UniqueObjectId)
                    if (character.WillCollideWithObject(item, characterMovement))
                        return true;
            }

            return false;
        }
Esempio n. 10
0
        public void Face(Character character)
        {
            float angle = MapHelper.GetAngleBetweenPoints(Position, character.Position);
            if (angle < 0)
                angle += 360;

            Direction dir = MapHelper.GetDirectionFromAngle(angle);
            Turn(dir);
        }