Exemplo n.º 1
0
        //Load enemy based on JSON using a configuration
        protected void Load(Enemy enemy, EnemyConfig enemyConfiguration, Vector2 origin)
        {
            //Set enemy starting position
            //Enemy is randomly spawned
            if (enemyConfiguration.randomSpawn == 1)
            {
                enemy.Position = enemy.GetRandomSpawnPosition(enemyConfiguration.spawnInterval);
            }
            else
            {
                enemy.Position = new Vector2((float)origin.X, (float)origin.Y);
            }

            //Load enemy attributes
            enemy.MaxHealth       = enemyConfiguration.health;
            enemy.FireRate        = enemyConfiguration.fireRate;
            enemy.Velocity        = enemyConfiguration.velocity;
            enemy.Health          = enemyConfiguration.health;
            enemy.MovementPattern = enemyConfiguration.movementPattern;

            //Set movement
            if (enemy.MovementPattern != MovementPattern.None)
            {
                this.factory = MovementFactory.MakeFactory(enemy.MovementPattern);
                Movement movement = this.factory.Create(enemy.Position, new Vector2((float)enemyConfiguration.direction.X, (float)enemyConfiguration.direction.Y), (float)enemy.Velocity);
                enemy.Movement = movement;
            }
        }
Exemplo n.º 2
0
        //Takes a movement type, origin, direction, and speed to make the corresponding movement
        public static Movement CreateMovement(MovementPattern pattern, Vector2 origin, Vector2 direction, float velocity)
        {
            AbstractMovementFactory factory = MakeFactory(pattern);

            if (factory != null)
            {
                return(factory.Create(origin, direction, velocity));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        //Makes the corresponding movement factory and returns it
        public static AbstractMovementFactory MakeFactory(MovementPattern pattern)
        {
            AbstractMovementFactory factory = null;

            switch (pattern)
            {
            case MovementPattern.Straight:
                factory = new StraightPattern();
                break;

            case MovementPattern.Oscillate:
                factory = new OscillatePattern();
                break;
            }

            return(factory);
        }